App note 221. Last line on page 7.

They use the process value for the derivative term. Sure, why not. But they show (everywhere shows in fact) that the derivative is calculated by y[n]-y[n-1].

But if you look at their code pid.c, they do the error correct, but the derivative incorrect... they do it backwards: y[n-1] - y[n]

int16_t pid_Controller(int16_t setPoint, int16_t processValue, struct PID_DATA *pid_st) { int16_t error, p_term, d_term; int32_t i_term, ret, temp; error = setPoint - processValue; ... // Calculate Dterm d_term = pid_st->D_Factor * (pid_st->lastProcessValue - processValue); pid_st->lastProcessValue = processValue; ret = (p_term + i_term + d_term) / SCALING_FACTOR; return((int16_t)ret); }

Am I incorrect or am I missing something?

Cheers,

Tom