'--------------------------------------------------------------------------------------------------------------------- 'Chopper Dual Speed Controller '--------------------------------------------------------------------------------------------------------------------- 'PROGRAM DESCRIPTION 'This program uses a PIC16F877 as a dual PWM speed controller for the two Speed 400 motors used in the arcade chopper project. '--------------------------------------------------------------------------------------------------------------------- Include "modedefs,bas" '--------------------------------------------------------------------------------------------------------------------- 'SET VARIABLES Define ADC_bits 8 'Anolog configuration Define ADC_clock 3 Define ADC_sampleus 50 TRISA=%111111 ADCON1=%00000100 'set port A analogs and right justify result TRISB=1 'default everything to inputs TRISC=1 TRISD=1 TRISE=1 '--------------------------------------------------------------------------------------------------------------------- 'PIN DESIGNATIONS 'Left Throttle var porta.0 'Anolog input left throttle control 'Right Throttle var porta.1 'Anolog input from right throttle control 'CCP2 var porta.2 'Pin 16 HPWM 'CCP1 var portd.2 'Pin 17 HPWM 'Variables Lvolts var word Rvolts var word Rangeadj var word '-------------------------------------------------------------------------------------------------------------------- Loop: Adcin 2, Rangeadj 'read voltage from range pot Adcin 0,Lvolts 'read left throttle pot volts Lvolts = (Lvolts*330/100)*(Rangeadj*100/255)/100 Lvolts = Lvolts Min 255 'ensure no invalid numbers Adcin 1,Rvolts 'read right throttle pot volts RVolts = (Rvolts*330/100)*(Rangeadj*100/255)/100 Rvolts = Rvolts Min 255 'ensure no invalid numbers HPWM 1,Lvolts,10000 'generate PWM signal to channel one, motor1 HPWM 2,Rvolts,10000 'generate PWM signal to channel two, motor2 goto loop