A last question : I've doubts about the duty cycle. What's the exact range of the duty cycle?
If I define a duty cycle between 0-10, the simulator oscilloscope gives me weird things (the inverted signal "jumps")...
If I define a duty cycle above 1023, same thing...
The code used :
Code:' At 20MHz, to figure a PWM frequency of 19.455kHz ' TPWM = time period of PWM frequency ' PTPER = 12-bit period register PTPERL and PTPERH ' PTMRPS = PWM time base prescaler ' ' (PTPER+1)*PTMRPS 257 ' TPWM = ---------------- = ------------ = 0.0000514 ' Fosc/4 5000000 ' ' Frequency = 1/TPWM = 1/0.0000514 = 19.455kHz ' ' PWM resolution (bits resolution for duty cycle) ' ' log(20MHz/19.455kHz) 3.01 ' Resolution = ------------------ = ----------- = 10 bits ' .301 .301 'PIC initialization DEFINE LOADER_USED 1 DEFINE OSC 40 'Port registers configuration PORTB = 0 ' Clear ports TRISB = %11000000 ' PWM 0,1,2,3,4,5 outputs TRISC = 2 ' RC1 = FLTA input (ground RC1 to halt PWM), pull-up resistor on RC1 'PCPWM registers configuration DTCON = %00001010 ' Deadtime (500ns) PTCON0 = %00000100 ' 1:1 postscale, Fosc/4 1:1 prescale, free running mode PTCON1 = %10000000 ' PWM time base is ON, counts up, 19.45kHz/4 PTPERL = 0 ' PWM low-side PTPERH = 1 ' PWM high-side 'PWM registers configuration PWMCON0 = %01000000 'PWM 0,1,2,3,4,5 set in pair mode PWMCON1 = %00000001 'PWM timer sync configuration FLTCONFIG = %00000011 'Fault configuration 'U, V and W duty variables uduty VAR WORD vduty VAR WORD wduty VAR WORD 'Phases duty uduty = 1 vduty = 1000 wduty = 1000 pwmlp: ' PWM update loop 'PWM U phase PDC0L = uduty.LOWbyte PDC0H = Uduty.HIGHByte 'PWM V phase PDC1L = vduty.LOWbyte PDC1H = vduty.HIGHByte 'PWM W phase PDC2L = wduty.LOWbyte PDC2H = wduty.HIGHByte goto pwmlp




Bookmarks