|
|
View previous topic :: View next topic |
Author |
Message |
aderogba
Joined: 03 Jun 2005 Posts: 8
|
PWM Frequency |
Posted: Thu Aug 04, 2005 7:23 am |
|
|
Please can someone help me with this code? From my calculations for period and duty cycle, I expect results to be frequency of 15khz and 50% duty cycle.
Code: |
#include <18F6722.h>
#use delay(clock=8000000)
#fuses INTRC_IO,NOLVP,NOWDT,PUT
void main(void)
{
setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 132, 1);
set_pwm2_duty(267);
while(true);
}
|
|
|
|
Ttelmah Guest
|
|
Posted: Thu Aug 04, 2005 9:42 am |
|
|
Yes.
So what are you seeing?...
I'd suggest adding the 'setup_oscillator(OSC_8MHZ)' line to the code. Some versions of the compiler correctly handle doing this automatically, but others don't, and if this was wrong, the output frequency would also be wrong.
Frequency shoul be fractionally over 15Khz, and the duty cycle, just a little over 50%. The 50% value would be 266 ((132+1)*2). I'd also be 'explicit' here, and make sure this value is a 'Long' (add an 'L' to the definition), since while it shoul work fine with 267, if the value was under 255, the compiler will switch to multiplying the value by 4, as it'll then be seen as an 8bit vaue, rather than a 16bit value.
Best Wishes |
|
|
aderogba
Joined: 03 Jun 2005 Posts: 8
|
|
Posted: Mon Aug 08, 2005 4:15 pm |
|
|
Thanks! Your suggestions work. |
|
|
|
|
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
|