I've set up a PIC16F1825 to do PWM on CCP3/4 for motor control as follows:
I need to use a relatively high frequency value for the motors. My question is this: would it hurt the LEDs or otherwise be a bad idea to use the same frequency for LED PWM? I want to set up CCP1 with the same timer, prescaler & resolution as the motors so that I can include the LEDs in this loop to 'ramp up' the motors:Code:' *************************************************************** ' Set up registers for PWM on CCP3, CCP4 ' *************************************************************** CCP3CON = %00001100 ; Use CCP3 in PWM mode (Motor 1) CCP4CON = %00001100 ; Use CCP4 in PWM mode (Motor 2) CCPTMRS = %00000000 ; Use Timer2 T2CON = %00000101 ; Timer2 on with 1:4 prescaler PR2 = 62 ; For 16Mhz OSC the desired output freq of 15,873Hz is ; achieved with this PR2 value (8-bit resolution ; with 1:4 prescaler) ; PWM freq must be ~ 16-20kHz to reduce noise
I know of the SPWM_INT.bas include file from Darrel (which allows you to use 200Hz, high enough so no flicker is seen) but I don't know if I need to use that here instead of sharing Timer2 with the same high frequency as with the motors.Code:' Spin up motors to saved value of _MotorRPM ' (Below a value of 'MinDuty', the motors don't move at all) FOR i = (MinDuty - PreSpinVal) to MotorRPM DutyVar3 = i IF PortEngDir = 0 THEN DutyVar4 = i ' Port engine (CCP4), fwd (CCW) ELSE DutyVar4 = (MaxDuty - I) ' Port engine (CCP4), rev (CW) ENDIF CCP3CON.4 = DutyVar3.0 CCP3CON.5 = DutyVar3.1 CCPR3L = DutyVar3 >> 2 CCP4CON.4 = DutyVar4.0 CCP4CON.5 = DutyVar4.1 CCPR4L = DutyVar4 >> 2 pause SpinUpPause #IFDEF USE_LCD_FOR_DEBUG HSEROUT [LCD_INST, LCD_CLR] pause 5 HSEROUT ["RPM=", DEC i, " ", 13, 10] ' Send text followed by carriage return and linefeed #ENDIF NEXT i




Bookmarks