Arduino PID Reverse not working

Hi!

I have a problem with my Arduino PID setup, im using a fan to cool my tempsensor. When i choose REVERSE as direction, the output is zero all the time.

PID myPID(&Input, &Output, &Setpoint, -5, -5, -1, REVERSE);

The K's are all negative. When i use DIRECT (with positive values) the output changes.

Thanks!

ricerik:
Hi!

I have a problem with my Arduino PID setup, im using a fan to cool my tempsensor. When i choose REVERSE as direction, the output is zero all the time.

PID myPID(&Input, &Output, &Setpoint, -5, -5, -1, REVERSE);

The K's are all negative. When i use DIRECT (with positive values) the output changes.

Thanks!

Reverse simply flips the sign of the output variable. If you're using a PWM that goes from 0-255, as on the Arduino, that does you no good, unless you LOOK at the output, and modify the value as needed to drive your particular motor driver. One some, this means setting/clearing a DIR bit based on the sign of the PWM command, and always outputting a positive PWM value. On others, it means outputting two different PWM values, one of which is active when going forward, the other when going reverse.

In any case that conversion is your responsibility. The PID can't help you with it.

Regards,
Ray L.

You did not post your whole program but when you say

The K's are all negative.

Aren't they supposed to be doubles and zero or greater ?
PID Constructor

UKHeliBob:
You did not post your whole program but when you sayAren't they supposed to be doubles and zero or greater ?
PID Constructor

Setting negative coefficients in PID (assuming this is PID_v1) is pointless. If negative coefficients are passed to PID, it does an abs() on all of them before saving its internal, time-scaled representations. What REVERSE actually does is flip the signs on its internal representations of the coefficients to make them all negative, thus flipping the sign of its output.

Regards,
Ray L.

The fan runs now, with REVERSE-mode and the output is positive, i have no idea why it works now