'---------------Title-------------- ' File......16F877A_hpwm2.pbp ' Started....1/17/08 ' Microcontroller used: Microchip Technology 16F877A ' microchip.com ' PicBasic Pro Code: micro-Engineering Labs, Inc. ' melabs.com '--------Program Desciption-------- ' Uses HPWM command to change the motor speeds. '-------------Schematic------------ ' See schematic at: ' http://www.cornerstonerobotics.org/schematics/pic16f877a_hpwm2.pdf '----------Related Lesson---------- ' hpwm1.pbp (the 16F88 program) is used in ' the lesson MOTOR CONTROL WITH PWM at: ' http://www.cornerstonerobotics.org/curriculum/lessons_year2/erii21_motor_control_pwm.pdf '--------------Comments------------ ' The HPWM Channel 1 (CCP1) for the PIC16F877A is RC2. ' The HPWM Channel 2 (CCP2) for the PIC16F877A is RC1. '-------------Variables------------ p0 var byte ' Byte to store Dutycycle variable '-----------Initialization--------- TRISB = %00000000 ' Sets all pins of PORTB as outputs ADCON1 = %00000110 ' Changes PORTE and PORTA analog bits to ' digital operation since not using ADC ' (Analog to Digital Converter) '------------Main Code------------- start: p0 = 90 ' Sets Dutycycle variable to 90 gosub motorhpwm ' Jumps to subroutine motorhpwm p0 = 255 ' Sets Dutycycle variable to 255 gosub motorhpwm ' Jumps to subroutine motorhpwm p0 = 0 ' Sets Dutycycle variable to 0 gosub motorhpwm ' Jumps to subroutine motorhpwm goto start ' Jump to loop label and start all over end motorhpwm: ' Subroutine motorhpwm hpwm 2,p0,245 ' Motor is driver by Channel 1, (RB0) on ' the PIC16F88. The Dutycycle is set at ' the value of p0. ' The frequency is set for 245 Hz. pause 2000 ' Pauses 2000 mS or 2 sec. return ' Returns to next program statement after ' the GOSUB command.