Hi,
The approach with the direction bit is for sign and magnitude PWM while, by the sound of it, you're looking for locked anti phase. In locked antiphase the PWM dutycycle is 50% when no torque should be delivered by the motor (the average current thru the motor is 0A). The dutycycle is then increased or decreased from 50% depending on which direction and how much torque the motor should deliver.

So, if you ARE doing locked antiphase PWM simply set the PWM duty cycle to 50% on startup and then, if pid_out.15 is set (output is negative) you subtract the ABS value of pid_out from the value coresponding to 50% and if pid-out.15 is "0" you add the ABS value of pid_out to value coresponding to 50%.

If you are doing sign and magnitude then your hardware will have an input for direction and you need to set that according to pid_out.15 and then set the dutycycle to the ABS value of pid_out.

I sugest you set the pid_Out_Clamp variable to a suitable value to prevent over or underflow in the duty-cycle register.

/Henrik.