I don't have the 18F4431 or Microchip motor control board, but this works
on the 18F2431. It outputs PWM on RB0,RB1,RB2,RB3,RB4 and RB5 with a
varying duty cycle. Ramps up, then down.
It should be at least enough to get you started.
This is just a slight modification to what you posted before. To work with theCode:DEFINE OSC 20 Duty VAR WORD PORTB = $FF TRISB = 0 PTCON0=$00 'page 8,step 1 PTPERL=$A0 ' $01A0 = 12kHz PTPERH=$01 PWMCON0=%01011110 'would be %01011111 for the 18F4431 PWMCON1=%00000001 'step 4 DTCON=$00 ;OVDCOND=$00 'step 6 ; May want to un-comment these based on your PIC & board. ;OVDCONS=$00 ;FLTCONFIG=%10110011 ;POVD=00000000 ;SEVTCMP=$0000 ;step 8 SEVTCMPL=$00 SEVTCMPH=$00 PDC0L=$00 PDC0H=$00 PDC1L=$00 PDC1H=$00 PDC2L=$00 PDC2H=$00 ;PDC3L=$FF ; un-comment for 18F4431 ;PDC3H=$00 PTCON1=%10000000 Main: FOR Duty = 50 TO $500 STEP 4 ASM bsf PWMCON1,UDIS ;Disable the PWM buffer update MOVFF _Duty,PDC0L MOVFF _Duty+1,PDC0H MOVFF _Duty,PDC1L MOVFF _Duty+1,PDC1H MOVFF _Duty,PDC2L MOVFF _Duty+1,PDC2H ;MOVFF _Duty,PDC3L ;un-comment for 18F4431 ;MOVFF _Duty+1,PDC3H bcf PWMCON1,UDIS ;Enable the PWM buffer update ENDASM PAUSE 50 NEXT Duty FOR Duty = $500 TO 50 STEP-4 ASM bsf PWMCON1,UDIS ;Disable the PWM buffer update MOVFF _Duty,PDC0L MOVFF _Duty+1,PDC0H MOVFF _Duty,PDC1L MOVFF _Duty+1,PDC1H MOVFF _Duty,PDC2L MOVFF _Duty+1,PDC2H ;MOVFF _Duty,PDC3L ;un-comment for 18F4431 ;MOVFF _Duty+1,PDC3H bcf PWMCON1,UDIS ;Enable the PWM buffer update ENDASM PAUSE 50 NEXT Duty GOTO Main END
18F2431. I haven't done much beyond this with the PCPWM module. Not yet
at least..;o}
HTH




Bookmarks