diff --git a/ADbasic_program_buffered.bas b/ADbasic_program_buffered.bas index 6a9f3425c2bf3c654188e1683a410068e4c8a2cd..d8fb6e4708ee7bdc4dbd3ee72ce8852a3d57f2c0 100644 --- a/ADbasic_program_buffered.bas +++ b/ADbasic_program_buffered.bas @@ -53,7 +53,7 @@ DIM DATA_29[MAX_PID_EVENTS] AS LONG 'PID max values DIM DATA_7[AINNO] AS LONG 'Start times for channel recording DIM DATA_8[AINNO] AS LONG 'End times for channel recording DIM DATA_9[AINNO] AS LONG 'Gain modes for AIN channels -DIM DATA_199[30000016] AS LONG 'Recorded Data - add padding at the end to ensure no overflow happens +DIM DATA_199[A_IN_BUFFER+16] AS LONG 'Recorded Data - add padding at the end to ensure no overflow happens 'Declare arrays for digital data from experiment control software DIM DATA_10[MAX_TICO_EVENTS] AS LONG 'DIO1 TiCo times @@ -91,8 +91,9 @@ DIM eventIdx AS LONG DIM pidIdx AS LONG DIM aInIdx AS LONG DIM nextPidTime AS LONG -DIM nextAInTime AS LONG +DIM nextAOutTime AS LONG DIM timer AS LONG 'timing the event duration +DIM total_workload AS LONG 'calcutaing the workload during the shot DIM i AS LONG 'for loop index 'Declare arrays for storing AIN and setting AOUT channels @@ -116,8 +117,9 @@ init: eventIdx = 0 pidIdx = 0 aInIdx = 0 + total_workload = 0 nextPidTime = DATA_4[1] - nextAInTime = DATA_1[1] + nextAOutTime = DATA_1[1] '===========================================================INITIALIZE TICOS============================================================ 'Set DIO channels as outputs @@ -158,19 +160,10 @@ init: NEXT i '===========================================================INITIALIZE AOUTS============================================================ - 'Initialize set values of all output channels to 0V - pid_min[0] = -N - pid_max[0] = 65535 + 'Initialize set values of all output channels FOR i=1 TO AOUTNO - set_target[i]=ZERO - set_output[i]=ZERO - act_values[i]=ZERO - set_pid[i]=0 - pid_P[i]=0 - pid_I[i]=0 - pid_D[i]=0 - pid_min[i]=-N - pid_max[i]=65535 + set_target[i]=DATA_3[i] 'The initial output values are always given for all channels + set_pid[i]=0 'At beginning all PIDs off NEXT i 'Write analog out values @@ -310,38 +303,42 @@ EVENT: ENDIF ' Update target values - IF(nextAInTime <= processIdx) THEN + IF(nextAOutTime <= processIdx) THEN DO inc eventIdx set_target[DATA_2[eventIdx]]=DATA_3[eventIDX] UNTIL(DATA_1[eventIdx+1] > processIdx) - nextAInTime = DATA_1[eventIdx+1] + nextAOutTime = DATA_1[eventIdx+1] ENDIF ' Update pid target IF(nextPidTime <= processIdx) Then DO inc pidIdx - set_pid[DATA_5[pidIdx]] = DATA_6[pidIdx] - pid_sum[DATA_5[pidIdx]] = 0 'act_values[DATA_6[pidIdx]]-N - pid_prev_dError[DATA_5[pidIdx]] = 0 - pid_P[DATA_6[pidIdx]] = DATA_25[pidIdx] - pid_I[DATA_6[pidIdx]] = DATA_26[pidIdx] - pid_D[DATA_6[pidIdx]] = DATA_27[pidIdx] - pid_min[DATA_6[pidIdx]] = DATA_28[pidIdx] - pid_max[DATA_6[pidIdx]] = DATA_29[pidIdx] + i = DATA_5[pidIdx] + set_pid[i] = DATA_6[pidIdx] + pid_sum[i] = 0 'act_values[DATA_6[pidIdx]]-N + pid_prev_dError[i] = 0 + i = DATA_6[pidIdx] + pid_P[i] = DATA_25[pidIdx] + pid_I[i] = DATA_26[pidIdx] + pid_D[i] = DATA_27[pidIdx] + pid_min[i] = DATA_28[pidIdx] + pid_max[i] = DATA_29[pidIdx] UNTIL(DATA_4[pidIdx+1] > processIdx) nextPidTime = DATA_4[pidIdx+1] ENDIF '### Debug Timer - par_13=READ_TIMER_SYNC() - timer + timer=READ_TIMER_SYNC() - timer ' TO BE REMOVED IN REAL USAGE !! IF (processIdx<MAX_EVENTS) THEN - DATA_31[processIdx] = par_13 + DATA_31[processIdx] = timer ENDIF + total_workload = total_workload + timer + par_15=processIdx FINISH: @@ -373,4 +370,5 @@ FINISH: P2_Start_DAC(AOUT1) P2_Start_DAC(AOUT2) + PAR_13 = total_workload PAR_1 = 0