|
|
View previous topic :: View next topic |
Author |
Message |
jaguar
Joined: 10 Sep 2008 Posts: 3 Location: Oaxaca, Mexico
|
PWM by software |
Posted: Wed Sep 10, 2008 3:59 pm |
|
|
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
|
|
Posted: Wed Sep 10, 2008 4:14 pm |
|
|
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
|
|
Posted: Wed Sep 10, 2008 4:15 pm |
|
|
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
|
PWM by software |
Posted: Thu Sep 11, 2008 3:18 pm |
|
|
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
|
|
Posted: Thu Sep 11, 2008 3:26 pm |
|
|
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
|
|
|
|
|
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
|