Thanks did not know that ccp and pwm0-5 are not the same pins that helped now how about setuo for timer 2.
Thanks did not know that ccp and pwm0-5 are not the same pins that helped now how about setuo for timer 2.
If you're using HPWM you don't need to mess with Timer2. It's automatically handled
for you.
If you plan to setup hardware PWM manually, these calcs should help.
Search here for HPWM and you'll find a boat-load more examples.Code:PR2=(Fosc/(4*PS*Freq))-1 TMR2 Prescaler = 1 PR2 = (8MHz/(4*1*12,000)) = (8MHz/48,000)-1 PR2 = 165.666 TMR2 Prescaler = 4 PR2 = (8MHz/(4*4*12,000)) = (8MHz/192,000)-1 PR2 = 40.666 TMR2 Prescaler = 16 PR2 = (8MHz/(4*16*12,000))-1 = (8MHz/768,000))-1 PR2 = 9.416 CCPR1L:CCP1CON<5:4>=(PR2+1)*4*Duty% (165+1)*4*0.5 = 332 (40+1)*4*0.5 = 82 (9+1)*4*0.5 = 20 To load the duty cycle registers just place the value calculated in a word, and do something like this; Duty = 332 ' Roughly 50% duty cycle CCP1CON.4 = Duty.0 ' Setup 10-bit duty cycle as CCP1CON.5 = Duty.1 ' a 10-bit word CCPR1L = Duty >> 2
Hi Bruce,
you mentioned above that the equation used to calculate the PWM resolution is
log(20MHz/19.455kHz) 3.01
Resolution = ------------------ = ----------- = 10 bits
.301 .301
In the 18F2431 datasheet it says that Fosc must be divided by four, i.e.
log(5MHz/19.455kHz) 2.41
Resolution = ------------------ = ----------- = 8 bits
.301 .301
and in other microchip document (link below) it provides the same equation you used.
http://ww1.microchip.com/downloads/e...doc/31014a.pdf
I am confused here! Can you please tell me what you think of that?
Kind regards,
Look at equation 17-4 PWM RESOLUTION. Then look at Table 17-2 just below it.
Try plugging in some numbers on your calculator using both methods, and see what you get according to the resolutions shown in Table 17-2 for different values of Fosc, at various frequencies.
You are right. So for 10 bits, thats 2 LSBs of PDCxH and 8 bits of PDCxL. Thanks.
PDCxH gets the 2 MSBs. PDCxL the lower 8-bits.So for 10 bits, thats 2 LSBs of PDCxH and 8 bits of PDCxL
hello bruce
i have a doubt abt carrier generation in 18f4431.sine wave ne how il generate through luk up table bt m nt bin able to generate carrier frequency of 20khz to compare it with ma sine wave.i'm attaching image for ur reference.can u plz help me in dis .![]()
Last edited by park21; - 15th April 2014 at 10:59.
Hi,
Finding this old thread may have answered some questions, I wanted to know, so thanks for it, especially Bruce.
Cheers, Camerart.
Bookmarks