*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit 73acea84 authored by Schabbauer, Johannes's avatar Schabbauer, Johannes
Browse files

Fixed workload issue with two addition time variables, set DIO output at t=0,...

Fixed workload issue with two addition time variables, set DIO output at t=0, use for loop for AOut channels (PIDs) --> Loop might be removed again!
parent 7bd1c444
No related branches found
No related tags found
No related merge requests found
......@@ -56,6 +56,8 @@ DIM DATA_11[MAX_TICO_EVENTS] AS LONG 'DIO1 digital output values
DIM DATA_20[MAX_TICO_EVENTS] AS LONG 'DIO2 TiCo times
DIM DATA_21[MAX_TICO_EVENTS] AS LONG 'DIO2 digital output values
DIM DATA_31[MAX_EVENTS] AS LONG ' Workload Array for testing
'Declare arrays to store TICO memory pointers
DIM PTR_TICO1[150] AS LONG
DIM PTR_TICO2[150] AS LONG
......@@ -80,6 +82,8 @@ DIM processIdx AS LONG
DIM eventIdx AS LONG
DIM pidIdx AS LONG
DIM aInIdx AS LONG
DIM nextPidTime AS LONG
DIM nextAInTime AS LONG
DIM timer AS LONG 'timing the event duration
DIM i AS LONG 'for loop index
......@@ -104,6 +108,8 @@ init:
eventIdx = 0
pidIdx = 0
aInIdx = 0
nextPidTime = DATA_4[1]
nextAInTime = DATA_1[1]
'===========================================================INITIALIZE TICOS============================================================
'Set DIO channels as outputs
......@@ -144,6 +150,10 @@ init:
pid_P[2] = 1
pid_I[2] = 1
pid_D[2] = 1
'A_IN 9 - AOM: PID Testing -
pid_P[1] = 0.01
pid_I[1] = 0.01
pid_D[1] = 0
'Initialize Integrator and Difference
FOR i=1 TO AOUTNO
......@@ -152,7 +162,7 @@ init:
NEXT i
' Set paramters of manual PID control from GUI
IF Par_21 <> 0 THEN
IF (Par_21 <> 0) THEN
pid_P[Par_21] = FPar_21
pid_I[Par_21] = FPar_22
pid_D[Par_21] = FPar_23
......@@ -213,7 +223,11 @@ init:
'Start Conversion for first event
P2_Sync_All(001100b)
'Wait for 200 * 10ns to make sure that first ADC values are ready
CPU_Sleep(200)
CPU_Sleep(200) ' TODO: Do we still need to wait if we set DIOs after Sync All?
' Set first output values at DIOs
P2_DIGOUT_LONG(DIO1,DATA_11[1])
P2_DIGOUT_LONG(DIO2,DATA_21[1])
'========================================================================================================================================
'= EVENT LOOP =
......@@ -237,81 +251,84 @@ EVENT:
P2_Sync_All(001100b)
'=======================================================CALCULATE NEW SET VALUES =======================================================
FOR i=1 TO 16
pidn = set_pid[i]
if (pidn = 0) then
'No PID active
set_output[i]=set_target[i]
pid_sum[i] = act_values[pidn]-N
pid_prev_dError[i] = 0
else
'Get deviation from target voltage
pid_error = set_target[i]- act_values[pidn]
'Get proportional part
pid_lin=pid_P[pidn]*pid_error
'Get integral part
pid_sum[i] = pid_sum[i] + pid_I[pidn]*pid_error
'Get differential part
pid_dError = pid_D[pidn]* pid_error
pid_diff = pid_dError - pid_prev_dError[i]
pid_prev_dError[i] = pid_dError
'Check for integral overflow
if (pid_sum[i] > N) then pid_sum[i] = N
if (pid_sum[i] < -N) then pid_sum[i] = -N
set_output[i]=(pid_lin+pid_sum[i]+pid_diff) + N
endif
' Check that output is within safe limits
if (set_output[i] < -N) then set_output[i] = - N
if (set_output[i] > 65535) then set_output[i] = 65535
NEXT i
'### CH1 - insert describtion here -
'set_output[1]=set_target[1]
pidn = set_pid[1]
if (pidn = 0) then
'No PID active
set_output[1]=set_target[1]
pid_sum[1] = act_values[pidn]-N
pid_prev_dError[1] = 0
else
'Get deviation from target voltage
pid_error = set_target[1]- act_values[pidn]
'Get proportional part
pid_lin=pid_P[pidn]*pid_error
'Get integral part
pid_sum[1] = pid_sum[1] + pid_I[pidn]*pid_error
'Get differential part
pid_dError = pid_D[pidn]* pid_error
pid_diff = pid_dError - pid_prev_dError[1]
pid_prev_dError[1] = pid_dError
'Check for integral overflow
if (pid_sum[1] > N) then pid_sum[1] = N
if (pid_sum[1] < -N) then pid_sum[1] = -N
set_output[1]=(pid_lin+pid_sum[1]+pid_diff) + N
endif
' Check that output is within safe limits
if (set_output[1] < -N) then set_output[1] = - N
if (set_output[1] > 65535) then set_output[1] = 65535
'### CH2 - insert describtion here -
set_output[2]=set_target[2]
'set_output[2]=set_target[2]
'### CH3 - insert describtion here -
set_output[3]=set_target[3]
'set_output[3]=set_target[3]
'### CH4 - insert describtion here -
set_output[4]=set_target[4]
'set_output[4]=set_target[4]
'### CH5 - insert describtion here -
set_output[5]=set_target[5]
'set_output[5]=set_target[5]
'### CH6 - insert describtion here -
set_output[6]=set_target[6]
'set_output[6]=set_target[6]
'### CH7 - insert describtion here -
set_output[7]=set_target[7]
'set_output[7]=set_target[7]
'### CH8 - insert describtion here -
set_output[8]=set_target[8]
'set_output[8]=set_target[8]
'### CH9 - insert describtion here -
set_output[9]=set_target[9]
'set_output[9]=set_target[9]
'### CH10 - insert describtion here -
set_output[10]=set_target[10]
'set_output[10]=set_target[10]
'### CH11 - insert describtion here -
set_output[11]=set_target[11]
'set_output[11]=set_target[11]
'### CH12 - insert describtion here -
set_output[12]=set_target[12]
'set_output[12]=set_target[12]
'### CH13 - insert describtion here -
set_output[13]=set_target[13]
'set_output[13]=set_target[13]
'### CH14 - insert describtion here -
set_output[14]=set_target[14]
'set_output[14]=set_target[14]
'### CH15 - insert describtion here -
set_output[15]=set_target[15]
'set_output[15]=set_target[15]
'### CH16 - insert describtion here -
set_output[16]=set_target[16]
'set_output[16]=set_target[16]
'======================================================== SET NEW AOUT VALUES ========================================================
......@@ -343,24 +360,28 @@ EVENT:
ENDIF
' Update target values
IF(DATA_1[eventIdx+1] <= processIdx) THEN
IF(nextAInTime <= processIdx) THEN
DO
inc eventIdx
set_target[DATA_2[eventIdx]]=DATA_3[eventIDX]
UNTIL(DATA_1[eventIdx+1] > processIdx)
nextAInTime = DATA_1[eventIdx+1]
ENDIF
' Update pid target
IF(DATA_4[pidIdx+1] <= processIdx) Then
IF(nextPidTime <= processIdx) Then
DO
inc pidIdx
set_pid[DATA_5[pidIdx]]=DATA_6[pidIdx]
UNTIL (DATA_4[pidIdx+1] > processIdx)
UNTIL(DATA_4[pidIdx+1] > processIdx)
nextPidTime = DATA_4[pidIdx+1]
ENDIF
'### Debug Timer
par_13=READ_TIMER_SYNC() - timer
'DATA_99[processIdx] = par_13
IF (processIdx<MAX_EVENTS) THEN
DATA_31[processIdx] = par_13
ENDIF
par_15=processIdx
FINISH:
......
No preview for this file type
......@@ -56,6 +56,9 @@ DIM DATA_11[MAX_TICO_EVENTS] AS LONG 'DIO1 digital output values
DIM DATA_20[MAX_TICO_EVENTS] AS LONG 'DIO2 TiCo times
DIM DATA_21[MAX_TICO_EVENTS] AS LONG 'DIO2 digital output values
' TO BE REMOVED IN REAL USAGE !!
DIM DATA_31[MAX_EVENTS] AS LONG ' Workload Array for testing
'Declare arrays to store TICO memory pointers
DIM PTR_TICO1[150] AS LONG
DIM PTR_TICO2[150] AS LONG
......@@ -80,6 +83,8 @@ DIM processIdx AS LONG
DIM eventIdx AS LONG
DIM pidIdx AS LONG
DIM aInIdx AS LONG
DIM nextPidTime AS LONG
DIM nextAInTime AS LONG
DIM timer AS LONG 'timing the event duration
DIM i AS LONG 'for loop index
......@@ -104,6 +109,8 @@ init:
eventIdx = 0
pidIdx = 0
aInIdx = 0
nextPidTime = DATA_4[1]
nextAInTime = DATA_1[1]
'===========================================================INITIALIZE TICOS============================================================
'Set DIO channels as outputs
......@@ -144,6 +151,10 @@ init:
pid_P[2] = 1
pid_I[2] = 1
pid_D[2] = 1
'A_IN 9 - AOM: PID Testing -
pid_P[1] = 0.01
pid_I[1] = 0.01
pid_D[1] = 0
'Initialize Integrator and Difference
FOR i=1 TO AOUTNO
......@@ -213,7 +224,11 @@ init:
'Start Conversion for first event
P2_Sync_All(001100b)
'Wait for 200 * 10ns to make sure that first ADC values are ready
CPU_Sleep(200)
CPU_Sleep(200) ' TODO: Do we still need to wait if we set DIOs after Sync All?
' Set first output values at DIOs
P2_DIGOUT_LONG(DIO1,DATA_11[1])
P2_DIGOUT_LONG(DIO2,DATA_21[1])
'========================================================================================================================================
'= EVENT LOOP =
......@@ -237,81 +252,84 @@ EVENT:
P2_Sync_All(001100b)
'=======================================================CALCULATE NEW SET VALUES =======================================================
FOR i=1 TO 16
pidn = set_pid[i]
if (pidn = 0) then
'No PID active
set_output[i]=set_target[i]
pid_sum[i] = act_values[pidn]-N
pid_prev_dError[i] = 0
else
'Get deviation from target voltage
pid_error = set_target[i]- act_values[pidn]
'Get proportional part
pid_lin=pid_P[pidn]*pid_error
'Get integral part
pid_sum[i] = pid_sum[i] + pid_I[pidn]*pid_error
'Get differential part
pid_dError = pid_D[pidn]* pid_error
pid_diff = pid_dError - pid_prev_dError[i]
pid_prev_dError[i] = pid_dError
'Check for integral overflow
if (pid_sum[i] > N) then pid_sum[i] = N
if (pid_sum[i] < -N) then pid_sum[i] = -N
set_output[i]=(pid_lin+pid_sum[i]+pid_diff) + N
endif
' Check that output is within safe limits
if (set_output[i] < -N) then set_output[i] = - N
if (set_output[i] > 65535) then set_output[i] = 65535
NEXT i
'### CH1 - insert describtion here -
'set_output[1]=set_target[1]
pidn = set_pid[1]
if (pidn = 0) then
'No PID active
set_output[1]=set_target[1]
pid_sum[1] = act_values[pidn]-N
pid_prev_dError[1] = 0
else
'Get deviation from target voltage
pid_error = set_target[1]- act_values[pidn]
'Get proportional part
pid_lin=pid_P[pidn]*pid_error
'Get integral part
pid_sum[1] = pid_sum[1] + pid_I[pidn]*pid_error
'Get differential part
pid_dError = pid_D[pidn]* pid_error
pid_diff = pid_dError - pid_prev_dError[1]
pid_prev_dError[1] = pid_dError
'Check for integral overflow
if (pid_sum[1] > N) then pid_sum[1] = N
if (pid_sum[1] < -N) then pid_sum[1] = -N
set_output[1]=(pid_lin+pid_sum[1]+pid_diff) + N
endif
' Check that output is within safe limits
if (set_output[1] < -N) then set_output[1] = - N
if (set_output[1] > 65535) then set_output[1] = 65535
'### CH2 - insert describtion here -
set_output[2]=set_target[2]
'set_output[2]=set_target[2]
'### CH3 - insert describtion here -
set_output[3]=set_target[3]
'set_output[3]=set_target[3]
'### CH4 - insert describtion here -
set_output[4]=set_target[4]
'set_output[4]=set_target[4]
'### CH5 - insert describtion here -
set_output[5]=set_target[5]
'set_output[5]=set_target[5]
'### CH6 - insert describtion here -
set_output[6]=set_target[6]
'set_output[6]=set_target[6]
'### CH7 - insert describtion here -
set_output[7]=set_target[7]
'set_output[7]=set_target[7]
'### CH8 - insert describtion here -
set_output[8]=set_target[8]
'set_output[8]=set_target[8]
'### CH9 - insert describtion here -
set_output[9]=set_target[9]
'set_output[9]=set_target[9]
'### CH10 - insert describtion here -
set_output[10]=set_target[10]
'set_output[10]=set_target[10]
'### CH11 - insert describtion here -
set_output[11]=set_target[11]
'set_output[11]=set_target[11]
'### CH12 - insert describtion here -
set_output[12]=set_target[12]
'set_output[12]=set_target[12]
'### CH13 - insert describtion here -
set_output[13]=set_target[13]
'set_output[13]=set_target[13]
'### CH14 - insert describtion here -
set_output[14]=set_target[14]
'set_output[14]=set_target[14]
'### CH15 - insert describtion here -
set_output[15]=set_target[15]
'set_output[15]=set_target[15]
'### CH16 - insert describtion here -
set_output[16]=set_target[16]
'set_output[16]=set_target[16]
'======================================================== SET NEW AOUT VALUES ========================================================
......@@ -343,24 +361,31 @@ EVENT:
ENDIF
' Update target values
IF(DATA_1[eventIdx+1] <= processIdx) THEN
IF(nextAInTime <= processIdx) THEN
DO
inc eventIdx
set_target[DATA_2[eventIdx]]=DATA_3[eventIDX]
UNTIL(DATA_1[eventIdx+1] > processIdx)
nextAInTime = DATA_1[eventIdx+1]
ENDIF
' Update pid target
IF(DATA_4[pidIdx+1] <= processIdx) Then
IF(nextPidTime <= processIdx) Then
DO
inc pidIdx
set_pid[DATA_5[pidIdx]]=DATA_6[pidIdx]
UNTIL (DATA_4[pidIdx+1] > processIdx)
UNTIL(DATA_4[pidIdx+1] > processIdx)
nextPidTime = DATA_4[pidIdx+1]
ENDIF
'### Debug Timer
par_13=READ_TIMER_SYNC() - timer
'DATA_99[processIdx] = par_13
' TO BE REMOVED IN REAL USAGE !!
IF (processIdx<MAX_EVENTS) THEN
DATA_31[processIdx] = par_13
ENDIF
par_15=processIdx
FINISH:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment