A customer tells me he has a motor driver that needs two separate PWM inputs... one telling the motor to go forward, and another telling it to go backwards. I've never heard of such a thing! Has anyone else seen that?
If so, the BOB PIC firmware should be able to support it as follows (Note: this code is NOT tested):
The P1C signal from the PIC on pin RC3 comes out to the A axis Direction line on the BOB PCB, so that can provide the second PWM output.
In
github.com/JamesNewton/BOBPID/blob/master/main.c
Update SetPWM to add the following to the start.
Code:
if (MOTOR_DIRECTION) { // could also use if (PIDOutput > 0) {
PSTRCONbits.STRC = 1; //drive the output to A DIR, RC3, P1C
PSTRCONbits.STRD = 0; //NOT to P1D, RC2
}
else {
PSTRCONbits.STRD = 1; //steer the output to P1D, RC2
PSTRCONbits.STRC = 0; //NOT to A DIR, RC3, P1C
}
In the main setup code, you will need to tris (tristate) RC3 as an output. Right after:
Code:
TRISCbits.TRISC2 = 0; // Set pin C2 1=input / 0=output motor PWM
Add:
Code:
TRISCbits.TRISC3 = 0; // Set pin C3 1=input / 0=output motor PWM2
If anyone needs that, I can add it fairly easily.