max_imum2000 said:
hello, i have been trying hard to figure out how can i use the PWM power module on pics like 18F4431 , mainly 18Fxx31 series.
they have up to 8 pwm module pairs
It only has 4 complementary output pairs plus 2 single ended PWM channels from the CCP modules.
the data sheet state for Period calculations we use the formula
(PTPER+1)
TPWM = -------------
Fosc (PS/4)
i use 8mhz crystal
so here is what i places
Fosc = 8Mhz
PS = 1:1
TPWM = 20Khz = 0.02Mhz (since i want to run a small motor over h-bridge) so i placed it as 50us
Make sure your configuration fuses are setup for OSC = HSPLL to get the maximum speed possible from the 8Mhz crystal (Fosc=32Mhz). All PIC18F4431's are rated 40Mhz @ 4.2-5V supply.
However, since you used an Fosc=8Mhz (no PLL), let us use that to check your calculations.
the PRPER regsiter then is equal to 99 or 1100011
to my understanding i load the PTPERL with 1100011 and PTPERH with 0
The value of the PTPER is correct for a 20Khz PWM frequency, 1:1 prescale and free running mode (PTCON0=0).
ok now i need to setup the dutycyle , since i want it to be 50% , the value for duty cycle must be TPWM/2= 25 or 11001 again this is went to PDC0L and zero goes to PDC0H.
MAX_PWM is 100*4 = 400 (it's less than 9-bits resolution BTW). Therefore, for 50% duty, PWM value is 200. The value of 200 goes to PDC0L and 0 to PDC0H.
then i fire the pwm module
i watch the signel over my cheap usb scope and i find a strage ramp like waves. not the know square wave,
i hook the motor and it only makes a hummmm sound but not turning
i tried to :
increase and decrease the duty cycle, didnt work also
what am i doing wrong ?? can anyone help with these PICs family please ?
thanks
I suspect there is something wrong your software and/or circuit. There are H-bridge circuits that can be configured to run maximum in one direction when the duty is 100%, zero speed at 50% duty, and maximum speed in the opposite direction when the duty is 0%.
Notice the PWM outputs are complementary. If the duty in one output is 0%, it's 100% on the complementary pair. Similarly, 50% on one means 50% on the other.
Your cheap USB scope is also suspect. The output of the PIC's PWM outputs are pure digital (high or low). It should not produce a ramp output.
If you can hear the chopping frequency, there is something modulating the 20Khz PWM frequency. It alone is inaudible to normal humans. Maybe your program is continuously writing to the PDC or PTPER registers somehow?