Code:duty var word ansel0=%00000000 'all digital 'ansel1=%00000000 trisa=%11111111 'set all port a pins to input cap1,cap2,cap3 trisb=%00000000 'set all port b pins as output portb=%00000000 'set port b to all zero trisc = 2 ' rc1=flta input(ground pin 16 to stop) pin 16 high to run 'capture mode intcon =0 'interrupts off tmr5h = 0 'clean high byte of tm5 counter tmr5l = 0 'clean low byte t5con = %00000001 ' prescale 1:1, int clock, tmr5 =on cap1con=%01000101 ' enable caputure,pulse width measurement mode, 'every rising o falling edge cap2con=%01000101 cap3con=%01000101 where is the capture data go from here ' ovdcond=%00010010 'turn on / off pwm pins 'ovdcons=%00000000 'pcpwm init dtcon = %00000101 'set deadtime to -500ns ptcon0 =%00000000 ' 1:1 postscaale,fosc/4 1:1 prescale, free run mode ptperl =0 ptperh=1 pwmcon0= %01010000 'pwm[5:0] output enabled 0100pwm4,5 independent, 'pwm0,1,2,3 complementary pwmcon1=1 'update enable,overrides sync w/time ptcon1=%10000000 'pwm time base is on, counts up fltconfig = %00000011 ' enable fault a, cycle-by-cycle mode duty =100 ' 50% =800 PDC2L = duty.lowbyte 'main a fixed 50% duty cycle on pwm4,5 PDC2H = duty.highbyte 'independent pwm outputs. main: for duty = 900 to 100 step-1 ' 10% to 90% PDC0L = duty.lowbyte 'register controls pwm1/0 PDC0H = duty.highbyte PDC1L = duty.lowbyte 'register controls pwm3/2 PDC1H = duty.highbyte PDC3L = duty.lowbyte 'register controls pwm6/7 PDC3H = duty.highbyte pause 50 next duty pause 500' 1/2 second delay between ramp up / down for duty = 100 to 900 ' 90% to 10% PDC0L = duty.lowbyte PDC0H = duty.highbyte PDC1L = duty.lowbyte PDC1H = duty.highbyte PDC3L = duty.lowbyte PDC3H = duty.highbyte pause 5 next duty pause 500' 1/2 second delay between ramp up / down goto main end
Bookmarks