#include #include main() { //Simulation of synchronous DA control double period=3600, delay_time; #define NCH 12 int from[NCH], to[NCH], acc[NCH],dacvalue[NCH],dif[NCH],dir[NCH]; int ich,chm; int md,is,nch=5; from[ 0]= 1000; to[ 0]= 1000; from[ 1]= 1000; to[ 1]= 1200; from[ 2]= 1000; to[ 2]= 900; from[ 3]= 1000; to[ 3]= 999; from[ 4]= 1000; to[ 4]= 1001; from[ 5]= 1000; to[ 5]= 1000; from[ 6]= 3000; to[ 6]= 5000; from[ 7]= 1000; to[ 7]= 1000; from[ 8]= 2000; to[ 8]= 1001; from[ 9]= 1000; to[ 9]= 1200; from[10]= 1000; to[10]= 0; from[11]= 1500; to[11]= 1000; chm=0; for(ich=0;ich abs(to[chm]-from[chm])) chm=ich; } md=abs(to[chm]-from[chm]); if(md==0) { printf("No need to change DAC\n"); exit(0); } printf("Change %d DACs from to in %.1f seconds\n",nch,period); delay_time=period/abs(md); for(ich=0;ich0)? 1:-1; } printf("DAC will be controled in %.1f msec step total %d steps\n", delay_time*1000, md); for(is=0;is=md) { acc[ich]=acc[ich]-md; dacvalue[ich]=dacvalue[ich]+dir[ich]; } printf("%6d",dacvalue[ich]); } // sleep_system(delay_time); <-- System function to delay this process for delay_time seconds. printf("\n"); } }