Hello,
I am new to pic microcontrollers and I need some help. I tried looking online but I could only find PWM speed control.
I am using a PIC18F26K22. I am using the eccp to control the enhanced PWM on RB2 and RC2. I connected my motor to those pins and I need to figure out how to program the uC to run the motor in reverse.
Here is my code so far:
I am new to pic microcontrollers and I need some help. I tried looking online but I could only find PWM speed control.
I am using a PIC18F26K22. I am using the eccp to control the enhanced PWM on RB2 and RC2. I connected my motor to those pins and I need to figure out how to program the uC to run the motor in reverse.
Here is my code so far:
C:
void CleanStep() {
DisUSR = ultrasonic(1); //get distance from ultrasonic sensor 1
DisUSL = ultrasonic(2); //get distance from ultrasonic sensor 2
uint16_t dutycycle = 638; //62.5%
while (1) {
while (DisUSR > 1) { //keep going Right till the distance from obstacle is 1cm
PORTBbits.RB2 = 0; //is it right to set the pins to LOW before running the PWM?
PORTCbits.RC2 = 0;
dutycycle = 638;
EPWM1_LoadDutyValue(dutycycle); //Set the speed at 62.5%
DisUSR = ultrasonic(1);
}
dutycycle = 0;
EPWM1_LoadDutyValue(dutycycle); //set speed to 0
PORTBbits.RB2 = 0; //also is it right to set the pins to LOW after running the PWM?
PORTCbits.RC2 = 0;
while (DisUSL > 1) { //keep going Left till the distance from obstacle is 1cm
PORTBbits.RB2 = 0;
PORTCbits.RC2 = 0;
dutycycle = 638;
EPWM1_LoadDutyValue(dutycycle);
DisUSR = ultrasonic(1);
}
dutycycle = 0;
PORTBbits.RB2 = 0;
PORTCbits.RC2 = 0;
}
}
Last edited by a moderator: