#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; 適当に初期値と終了値をセットしてください。プログラムの中では このなかでnch分が捜査の対象になります。 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; } ADCにセットする値の変化の絶対値の最大を調べます。 これが最後のループのステップ数になります。 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); 各チャネル用にACCと言う変数を使うところが 味噌です。 初期値は「ステップ数/2」です。 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) { DACの値を1増やします。 dacvalue[ich]=dacvalue[ich]+dir[ich]; ACCをMDのあまりにします。 acc[ich]=acc[ich]-md; } printf("%6d",dacvalue[ich]); } 次のステップまで一定時間休みます。   // sleep_system(delay_time); printf("\n"); } }