Listing 6. The Control Code

r=(AMP)*sin((FREQ)*2*M_PI*t);
/* reference signal- sine wave*/
Read_30ATchans(fd1,in_ptr);
/* read the card input channels */
e=r-(in_ptr[0]); /* compute error signal */
s+=e; /* cumulative error */
out_ptr[0]=(1.0)*(kp*e+ki*s+kd*(e-eold));
/* compute control signal */
Write_30ATchans(fd1,out_ptr);
/* output control signal */
t+=dt;
/* increment time */
eold=e;
/* Assign old value of error */