View previous topic :: View next topic |
Author |
Message |
davt
Joined: 07 Oct 2003 Posts: 66 Location: England
|
PWM |
Posted: Mon Jan 12, 2004 9:47 am |
|
|
Hi all!
Having not used the Pic PWM module before is it possible to produce a frequency of 40 khz whose duty cycle is variable in 255 steps.
I fear I may not get the resolution I require maybe 128 is more realistic!
Iwould be running the clock at 20mhz.
Thanks.
Dave |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: PWM |
Posted: Mon Jan 12, 2004 10:24 am |
|
|
davt wrote: | Hi all!
Having not used the Pic PWM module before is it possible to produce a frequency of 40 khz whose duty cycle is variable in 255 steps.
I fear I may not get the resolution I require maybe 128 is more realistic!
Iwould be running the clock at 20mhz.
Thanks.
Dave |
20mhz. is 5M IPS (instructions cycles per second)
You can setup timer2 to overflow every 250 instructions cycles.
setup_timer_2 ( T2_DIV_BY_1, 250, 1);
5M / 250 = 20K frequency
The PWM putput will toggle at overflow.
pwm1_duty is the count of timer2 that toggles the PWM output.
set_pwm1_duty (125)
will give 50% duty cycle.
Last edited by Neutone on Mon Jan 12, 2004 12:45 pm; edited 1 time in total |
|
|
Ttelmah Guest
|
Re: PWM |
Posted: Mon Jan 12, 2004 10:29 am |
|
|
davt wrote: | Hi all!
Having not used the Pic PWM module before is it possible to produce a frequency of 40 khz whose duty cycle is variable in 255 steps.
I fear I may not get the resolution I require maybe 128 is more realistic!
Iwould be running the clock at 20mhz.
Thanks.
Dave |
Go to the Microchip website, and get AN539, and AN564. They describe the options and limits for the PWM very well.
You can get 8bit at 40KHz OK (the limit is about 8.9 bits for this frequency), in hi-resolution mode.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 12, 2004 10:55 am |
|
|
Quote: | is it possible to produce a frequency of 40 khz whose duty cycle is variable in 255 steps. I fear I may not get the resolution I require |
Piclist has a chart, and also a forumula that lets you calculate
the number of bits of resolution for a given frequency.
http://www.piclist.com/techref/microchip/pwmrescalc.htm |
|
|
|