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 support@ccsinfo.com

PWM by software

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jaguar



Joined: 10 Sep 2008
Posts: 3
Location: Oaxaca, Mexico

View user's profile Send private message MSN Messenger

PWM by software
PostPosted: Wed Sep 10, 2008 3:59 pm     Reply with quote

Hi!

I need to generate three independent PWM signals (by software) with a frequency of 100 Hz or 150 Hz. Each signal with different duty cycle which can be modified using several values saved in PIC's memory.

Any idea about the programming?

I want to use the PIC12F683, thanks for your attention
_________________
Best wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 4:14 pm     Reply with quote

Tell us the maximum PIC oscillator frequency that you will permit in your
design (4 MHz, 20 MHz, etc.), and tell us the resolution of the PWM that
you require (either in number of bits, or number of steps).
Guest








PostPosted: Wed Sep 10, 2008 4:15 pm     Reply with quote

Configure a timer to operate at some multiple of your desired frequency.

The more duty cycle resolution you want, the higher the multiple.

Then in the timer isr, use a incrementing variable to control duty cycle

So say you wanted to do 100Hz with 100 different possible duty cycles

Configure the timer to interrupt every 0.0001 seconds, and increment a variable, say x, for example in the isr. When x reaches a certain value (determined by duty cycle), set the output to low. When reaches 100, reset the variable to 0, and set the output high. For a duty cycle of 50%, set the output change to happen at x=50. For a duty cycle of 10, set the output change to happen at x=10.
jaguar



Joined: 10 Sep 2008
Posts: 3
Location: Oaxaca, Mexico

View user's profile Send private message MSN Messenger

PWM by software
PostPosted: Thu Sep 11, 2008 3:18 pm     Reply with quote

PCM programmer wrote:
Tell us the maximum PIC oscillator frequency that you will permit in your
design (4 MHz, 20 MHz, etc.), and tell us the resolution of the PWM that
you require (either in number of bits, or number of steps).


The maximum PIC oscillator frequency is 4MHZ using the internal oscillator, and the resolution required is of 8 bits.

Thanks for your response
_________________
Best wishes
jaguar



Joined: 10 Sep 2008
Posts: 3
Location: Oaxaca, Mexico

View user's profile Send private message MSN Messenger

PostPosted: Thu Sep 11, 2008 3:26 pm     Reply with quote

Anonymous wrote:
Configure a timer to operate at some multiple of your desired frequency.

The more duty cycle resolution you want, the higher the multiple.

Then in the timer isr, use a incrementing variable to control duty cycle

So say you wanted to do 100Hz with 100 different possible duty cycles

Configure the timer to interrupt every 0.0001 seconds, and increment a variable, say x, for example in the isr. When x reaches a certain value (determined by duty cycle), set the output to low. When reaches 100, reset the variable to 0, and set the output high. For a duty cycle of 50%, set the output change to happen at x=50. For a duty cycle of 10, set the output change to happen at x=10.


Well, I'm a beginner, so could you explain me step by step how write down the code?

thanks
_________________
Best wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 11, 2008 3:56 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=35160&start=3
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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