|
PWM TEST PROGRAM PWM (Pulse Width Modulation) Test Program for the Mainboard (PIC16F876) The main part of the code at "Start" performs the following function: Motor Left Forward The program loops forever and has
the following effect:
The Code: list p=16f876 #include "P16F876.inc" ;Define ports so we can use them by name #define ML1 PORTB,5 ;OUTPUT #define ML2 PORTB,4 ;OUTPUT #define MR1 PORTB,3 ;OUTPUT #define MR2 PORTB,2 ;OUTPUT cblock 20h VLDelay, LDelay, MDelay, SDelay ;variables for delay routines endc org 0 goto init ;jump over interrupt vectors org 10 init bsf STATUS, RP0 bcf STATUS, RP1 ;select bank 1 movlw b'11000011' movwf TRISB ;RB2,RB3,RB4,RB5 set as outputs bcf STATUS, RP0 ;select bank 0 Start bsf ML1 bcf ML2 ;Motor Left Forward bsf MR1 bcf MR2 ;Motor Right Forward movlw .100 ;100*10uS=1mS call ShortDelay ;wait for 1 milli Second bcf ML1 bcf ML2 ;Motor Left off bcf MR1 bcf MR2 ;Motor Right off movlw .100 ;100*10uS=1mS call ShortDelay ;wait for 1 milli second goto Start ;loop forever ;***** Short Delay 10 uS to 3 mSec, value in w on entry, 1 tick = 12 uS ShortDelay movwf SDelay WaitSDF nop nop nop nop nop nop nop decfsz SDelay,F goto WaitSDF Return ;************************** ;*** Config word *** ;************************** __CONFIG h'3FFF' & _LVP_OFF & _BODEN_OFF & _XT_OSC & _PWRTE_ON & _WDT_OFF end The Results:
Note the frequency is approx 500Hz as per the design.
|