Post the code you're actually using for that test and someone will most likely see what's going on.
Post the code you're actually using for that test and someone will most likely see what's going on.
THIS IS THE CODE:
TRISC.2 = 0 ' PORTC.2 IS OUTPUT
PR2 = 200 ' Set PWM Period
CCP1CON = %00001100 ' Select PWM Mode
T2CON = %00000101 ' Timer2 = ON + 1:4 prescale ( about 10 KHz )
FOR DUTY=1 TO 1023
GOSUB READ_DATA ' READS ADC INPUT
GOSUB SERIAL_OUT ' SEND DATA TO SERIAL PORT FOR DISPLAY
ccp1con.bit4=duty.bit0
ccp1con.bit5=duty.bit1
CCPR1L = duty>>2
NEXT DUTY
THANKS
AMBROGIO
Hi,
The reason is because you have PR2 set to 200.
Remember how the PWM generator works: Basically, the PWM cycle starts over when TMR2 equals PR2 and because TMR2 is concatenated with two more bits at the "low end" the available number of discrete dutycycles is PR2*4 or, in this case, 800.
/Henrik.
Henrik,
thanks for the interest.
I have read the data sheet again but it is still not clear to me: could you please spend few more words for me ?
( Will I have 10 bit resolution if PR2 is set to 256 since 256*4 =1023 : is this assumption correct ? ).
Thanks for your time
bst rgds,
Ambrogio
Hello,
Well, PR2 is 8 bits so you can only really set it to 255 but otherwise yes you're correct.
This will of course also change the frequency - there's always a tradeoff between frequency and resolution. If you need to "hit" 10kHz exactly then you'll have to live with ~9.5 bits of resolution or change your oscillator frequency to one that better matches your needs. Faster isn't always better.
/Henrik.
Thanks Henrik: it is clear to me now.
Best regards,
Ambrogio
IW2FVO
North Italy
Bookmarks