>> pid_calc: >> last_error = error > This first step should go at the end, otherwise the DELTA_ERROR below > will always be 0. >> error = target_rpm - measured_rpm >> sum_error = sum_error + error >> delta_error = error - last_error >> >> proportional_term = error * proportional_gain >> integral_term = sum_error * integral_gain >> derivative_term = delta_error * derivative_gain >> >> control_signal = proportional_term + integral_term + derivative_term I should have been clear on scope: either last_error or error will have to be global or static; I assumed error would be global. In that case, I think the way I wrote it would work. If that statement is at the end, it requires that last_error survive until the next call. -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body