CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PWM/DAC...etc General advice required.
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PWM and filtering
PostPosted: Sat Feb 18, 2012 5:33 pm     Reply with quote

At last I do think you might be getting it.

There is another way of looking at the PWM square waves. Suppose you've got a 20% duty ratio 0 to 5V peak signal. It looks like:-
Code:
 5|    ---                  ---                  ---                  ---   
  |   |   |                |   |                |   |                |
 4|   |   |                |   |                |   |                |
  |   |   |                |   |                |   |                |
 3|   |   |                |   |                |   |                |
  |   |   |                |   |                |   |                |
 2|   |   |                |   |                |   |                |
  |   |   |                |   |                |   |                |
 1|   |   |                |   |                |   |                |
  |   |   |                |   |                |   |                |
 0|---     ----------------     ----------------     ----------------


But you could consider it to have two components, a 1V dc component and an offset ac one.

dc component
Code:
 5|
  |
 4|
  |
 3|
  |
 2|
  |
 1|------------------------------------------------------------------------
  |
 0|

ac component
Code:
 5|
  |
 4|    ---                  ---                  ---                  ---   
  |   |   |                |   |                |   |                |
 3|   |   |                |   |                |   |                |
  |   |   |                |   |                |   |                |
 2|   |   |                |   |                |   |                |
  |   |   |                |   |                |   |                |
 1|   |   |                |   |                |   |                |
  |   |   |                |   |                |   |                |
 0|   |   |                |   |                |   |                |
  |   |   |                |   |                |   |                |
-1|---     ----------------     ----------------     ----------------

The ac component has an average value of zero.

So if you start from the 0-5V PWM square wave and remove the ac component with an RC filter you are left with the dc.

By starting from a 0-5V PWM you can produce any desired dc voltage from 0 to 5V by changing the duty ratio.

Then progress to a PWM square wave, where the duty ratio follows a sine function, follow that with low pass filtering you get something which looks a sine wave (or any other you choose).

I hope this helps shed some light on where I'm coming from.



A quick summary (as I see it):-

(1) You start with a raised sinusoidal waveform.
(2) Sample the waveform at 100ms intervals, with loss of information in the process (i.e. between the samples).
(3) Transmit the samples ultimately to a PIC as 10 bit data.

At this stage you have two requirements:-

Recover the missing information & convert to analogue.

Your initial approach was to:-

(a) Convert to analogue.
(b) Hope to recover the missing information by filtering.

I suggested:-

(A) Recover the missing information by interolating between sample points.
(B) Convert to analogue, either with a DAC or PWM and filtering.

If you go down the PWM route and have a 20MHz processor clock you can:-

( i ) Create a PWM signal @ 20khz i.e. 50us period.
(ii ) Modulate PWM with your restored information.
(iii) Remove 20kHz carrier with an RC filter.

A 50ms filter time constant will reduce the 20kHz ripple to less than 0.1%.

Job done.

Mike
kcj



Joined: 05 Oct 2011
Posts: 33

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 10:34 am     Reply with quote

Hi Mike & everybody,

Thanks for all your suggestions, I increased the sampling time of the xbee to its maximum 50ms and discovered an extra PIN was configured as a an analogue sample pin, so it was sending an extra 2 bytes, which i had not accounted for in the code.

After i changed this and used a low pass filter, C=1uf R= 4.4K, the PWM was smoothed and changed extremely quickly with force.There was also an extra delay in the code which slowed the code down as well.

All is working as it should be, hopefully it will on presentation day. Thanks for your help, i learned a lot about different filters available and alternative thinking.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group