So my current solution to this is to just always use analogWrite() on the pins I use PWM on (just analogWrite(PIN, 0) or (PIN, 1023) for LOW/HIGH) - took me a while to figure out that this was the problem, though.
Basically i've got a DC motor hooked to an H-bridge (L293DD), and to swap directions I'd been using:
But it was only working in one direction (whichever one went first) - and it only worked once. Once I switch directions, everything would stop and no more motor movement would occur.
If I instead use:
Everything works as expected. So, while I've solved the problem, I'm not entirely certain of the CAUSE of the problem (all pins are pinMode(pin, OUTPUT)). Why does doing a digitalWrite break analog/PWM output on the same pin? Or is it the opposite, and doing an analogWrite on a pin stops digitalWrite from having access to the same pin?
Basically i've got a DC motor hooked to an H-bridge (L293DD), and to swap directions I'd been using:
Code:
//up
digitalWrite(FDR1_MOTOR_EN, HIGH);
digitalWrite(FDR1_MOTOR_A, LOW);
analogWrite(FDR1_MOTOR_B, speed);
//down
digitalWrite(FDR1_MOTOR_EN, HIGH);
digitalWrite(FDR1_MOTOR_B, LOW);
analogWrite(FDR1_MOTOR_A, speed);
But it was only working in one direction (whichever one went first) - and it only worked once. Once I switch directions, everything would stop and no more motor movement would occur.
If I instead use:
Code:
//up
digitalWrite(FDR1_MOTOR_EN, HIGH);
analogWrite(FDR1_MOTOR_A, 0);
analogWrite(FDR1_MOTOR_B, speed);
//down
digitalWrite(FDR1_MOTOR_EN, HIGH);
analogWrite(FDR1_MOTOR_B, 0);
analogWrite(FDR1_MOTOR_A, speed);
Everything works as expected. So, while I've solved the problem, I'm not entirely certain of the CAUSE of the problem (all pins are pinMode(pin, OUTPUT)). Why does doing a digitalWrite break analog/PWM output on the same pin? Or is it the opposite, and doing an analogWrite on a pin stops digitalWrite from having access to the same pin?