Other Parts Discussed in Thread: C2000WARE
Dear community member,
I am new to PID controller simulation. I checked the Digital Control Library (DCL). I want to simulate the simple PID block. I have some errors in building the file. Please suggest.
Steps which I followed as given below:
1- Firstly, I select "Example_F28069_PID.c" from the DCL libraries(C:\ti\c2000\C2000Ware_4_03_00_00\libraries\control\DCL\c28\examples\F28069_PID).
2- Then I uploaded in my CCS program and changed the header files from F2806x to DSPf2833x (lines 9-11) because I am using the f28335 device (Control card with evaluation board). Also you can see the included files in Project Explore sections. See the picture below.

3- When I build the Project, I had 18 errors in the console window. See the attached error file & the problem window picture:
**** Build of configuration Debug for project Example_2833xEPwmUpDownAQ ****
"C:\\ti\\ccs1220\\ccs\\utils\\bin\\gmake" -k all
Building file: "../Example_2833xEPwmUpDownAQ.c"
Invoking: C2000 Compiler
"C:/ti/ccs1220/ccs/tools/compiler/ti-cgt-c2000_22.6.0.LTS/bin/cl2000" -v28 -ml -mt --float_support=fpu32 --include_path="C:/ti/c2000/C2000Ware_4_03_00_00/device_support/f2806x/headers/include" --include_path="C:/ti/c2000/C2000Ware_4_03_00_00/device_support/f2806x/common/include" --include_path="C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include" --include_path="C:/ti/ccs1220/ccs/tools/compiler/ti-cgt-c2000_22.6.0.LTS/include" --include_path="C:/ti/c2000/C2000Ware_4_03_00_00/device_support/f2833x/headers/include" --include_path="C:/ti/c2000/C2000Ware_4_03_00_00/device_support/f2833x/common/include" --include_path="C:/ti/c2000/C2000Ware_4_03_00_00/libraries/math/IQmath/c28/include" --include_path="C:/ti/c2000/C2000Ware_4_03_00_00/libraries/math/FPUfastRTS/c28/include" --define=_DEBUG --define=LARGE_MODEL -g --diag_suppress=10063 --diag_warning=225 --issue_remarks --verbose_diagnostics --quiet --preproc_with_compile --preproc_dependency="Example_2833xEPwmUpDownAQ.d_raw" "../Example_2833xEPwmUpDownAQ.c"
>> Compilation failure
subdir_rules.mk:79: recipe for target 'Example_2833xEPwmUpDownAQ.obj' failed
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 216: note: declaration may not appear after executable
statement in block
float32_t beta1 = -(float32_t) crealf(q->z1 + q->z2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 217: note: declaration may not appear after executable
statement in block
float32_t beta0 = (float32_t) crealf(q->z1 * q->z2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 218: note: declaration may not appear after executable
statement in block
float32_t alpha1 = -(float32_t) crealf(q->p1 + q->p2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 219: note: declaration may not appear after executable
statement in block
float32_t alpha0 = (float32_t) crealf(q->p1 * q->p2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 220: note: declaration may not appear after executable
statement in block
float32_t T = p->css->T;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 221: note: declaration may not appear after executable
statement in block
float32_t a0p = 4.0f + (alpha1 * 2.0f * T) + (alpha0 * T * T);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 222: note: declaration may not appear after executable
statement in block
float32_t b0 = q->K * (4.0f + (beta1 * 2.0f * T) + (beta0 * T * T)) / a0p;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 223: note: declaration may not appear after executable
statement in block
float32_t b1 = q->K * (-8.0f + (2.0f * beta0 * T * T)) / a0p;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 224: note: declaration may not appear after executable
statement in block
float32_t b2 = q->K * (4.0f - (beta1 * 2.0f * T) + (beta0 * T * T)) / a0p;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 225: note: declaration may not appear after executable
statement in block
float32_t a2 = (4.0f - (alpha1 * 2.0f * T) + (alpha0 * T * T)) / a0p;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 226: note: declaration may not appear after executable
statement in block
float32_t c2 = -a2;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 227: note: declaration may not appear after executable
statement in block
float32_t tau = (p->css->T / 2.0f) * (1.0f - c2) / (1.0f + c2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 230: note: declaration may not appear after executable
statement in block
float32_t det = (c2 + 1.0f);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 240: note: declaration may not appear after executable
statement in block
float32_t k1 = (c2*b0 - b1 - (2.0f + c2)*b2) / det;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 241: note: declaration may not appear after executable
statement in block
float32_t k2 = (c2 + 1.0f) * (b0 + b1 + b2) / det;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 242: note: declaration may not appear after executable
statement in block
float32_t k3 = (c2*c2*b0 - c2*b1 + b2) / det;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 275: note: declaration may not appear after executable
statement in block
float32_t beta1 = -(float32_t) crealf(q->z1 + q->z2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 276: note: declaration may not appear after executable
statement in block
float32_t beta0 = (float32_t) crealf(q->z1 * q->z2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 277: note: declaration may not appear after executable
statement in block
float32_t alpha1 = -(float32_t) crealf(q->p1 + q->p2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 278: note: declaration may not appear after executable
statement in block
float32_t alpha0 = (float32_t) crealf(q->p1 * q->p2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 279: note: declaration may not appear after executable
statement in block
float32_t T = p->css->T;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 280: note: declaration may not appear after executable
statement in block
float32_t a0p = 4.0f + (alpha1 * 2.0f * T) + (alpha0 * T * T);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 281: note: declaration may not appear after executable
statement in block
float32_t b0 = q->K * (4.0f + (beta1 * 2.0f * T) + (beta0 * T * T)) / a0p;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 282: note: declaration may not appear after executable
statement in block
float32_t b1 = q->K * (-8.0f + (2.0f * beta0 * T * T)) / a0p;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 283: note: declaration may not appear after executable
statement in block
float32_t b2 = q->K * (4.0f - (beta1 * 2.0f * T) + (beta0 * T * T)) / a0p;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 284: note: declaration may not appear after executable
statement in block
float32_t a2 = (4.0f - (alpha1 * 2.0f * T) + (alpha0 * T * T)) / a0p;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 285: note: declaration may not appear after executable
statement in block
float32_t c2 = -a2;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 286: note: declaration may not appear after executable
statement in block
float32_t tau = (p->css->T / 2.0f) * (1.0f - c2) / (1.0f + c2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 289: note: declaration may not appear after executable
statement in block
float32_t det = (c2 + 1.0f);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 513: note: declaration may not appear after executable
statement in block
float32_t z1 = (float32_t) crealf(q->z1);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 514: note: declaration may not appear after executable
statement in block
float32_t T = p->css->T;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 539: note: declaration may not appear after executable
statement in block
float32_t z1 = (float32_t) crealf(q->z1);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 540: note: declaration may not appear after executable
statement in block
float32_t T = p->css->T;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 912: note: declaration may not appear after executable
statement in block
float32_t a0p = 2.0f - (float32_t) crealf(q->p1) * p->css->T;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1094: note: declaration may not appear after executable
statement in block
float32_t beta2 = -(float32_t) crealf(q->z1 + q->z2 + q->z3);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1095: note: declaration may not appear after executable
statement in block
float32_t beta1 = (float32_t) crealf((q->z1 * q->z2) + (q->z2 * q->z3) + (q->z1 * q->z3));
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1096: note: declaration may not appear after executable
statement in block
float32_t beta0 = -(float32_t) crealf(q->z1 * q->z2 * q->z3);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1098: note: declaration may not appear after executable
statement in block
float32_t alpha2 = -(float32_t) crealf(q->p1 + q->p2 + q->p3);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1099: note: declaration may not appear after executable
statement in block
float32_t alpha1 = (float32_t) crealf((q->p1 * q->p2) + (q->p2 * q->p3) + (q->p1 * q->p3));
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1100: note: declaration may not appear after executable
statement in block
float32_t alpha0 = -(float32_t) crealf(q->p1 * q->p2 * q->p3);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1102: note: declaration may not appear after executable
statement in block
float32_t T = p->css->T;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1104: note: declaration may not appear after executable
statement in block
float32_t a0p = 8.0f + (alpha2 * 4.0f * T) + (alpha1 * 2.0f * T * T) + (alpha0 * T * T * T);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1306: note: declaration may not appear after executable
statement in block
float32_t beta1 = -(float32_t) crealf(q->z1 + q->z2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1307: note: declaration may not appear after executable
statement in block
float32_t beta0 = (float32_t) crealf(q->z1 * q->z2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1308: note: declaration may not appear after executable
statement in block
float32_t alpha1 = -(float32_t) crealf(q->p1 + q->p2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1309: note: declaration may not appear after executable
statement in block
float32_t alpha0 = (float32_t) crealf(q->p1 * q->p2);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1311: note: declaration may not appear after executable
statement in block
float32_t T = p->css->T;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1312: note: declaration may not appear after executable
statement in block
float32_t a0p = 4.0f + (alpha1 * 2.0f * T) + (alpha0 * T * T);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1341: note: declaration may not appear after executable
statement in block
float32_t T = p->css->T;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1342: note: declaration may not appear after executable
statement in block
float32_t v1 = wn*wn*T*T;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1343: note: declaration may not appear after executable
statement in block
float32_t a2p = 1.0f / (4.0f + 4.0f*z*wn*T + v1);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1606: note: declaration may not appear after executable
statement in block
float32_t beta2 = -(float32_t) crealf(q->z1 + q->z2 + q->z3);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1607: note: declaration may not appear after executable
statement in block
float32_t beta1 = (float32_t) crealf((q->z1 * q->z2) + (q->z2 * q->z3) + (q->z1 * q->z3));
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1608: note: declaration may not appear after executable
statement in block
float32_t beta0 = -(float32_t) crealf(q->z1 * q->z2 * q->z3);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1610: note: declaration may not appear after executable
statement in block
float32_t alpha2 = -(float32_t) crealf(q->p1 + q->p2 + q->p3);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1611: note: declaration may not appear after executable
statement in block
float32_t alpha1 = (float32_t) crealf((q->p1 * q->p2) + (q->p2 * q->p3) + (q->p1 * q->p3));
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1612: note: declaration may not appear after executable
statement in block
float32_t alpha0 = -(float32_t) crealf(q->p1 * q->p2 * q->p3);
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1614: note: declaration may not appear after executable
statement in block
float32_t T = p->css->T;
^
"C:/ti/c2000/C2000Ware_4_03_00_00/libraries/control/DCL/c28/include/DCLF32.h",
line 1615: note: declaration may not appear after executable
statement in block
float32_t a0p = 8.0f + (alpha2 * 4.0f * T) + (alpha1 * 2.0f * T * T) + (alpha0 * T * T * T);
^
"../Example_2833xEPwmUpDownAQ.c", line 42: error: struct "PIE_VECT_TABLE" has
no field "ADCINT1"
PieVectTable.ADCINT1 = &control_Isr; // [F28069_PID_cisr.c]
^
"../Example_2833xEPwmUpDownAQ.c", line 75: error: struct "ADC_REGS" has no
field "ADCCTL1"
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 0; // early interrupt generation
^
"../Example_2833xEPwmUpDownAQ.c", line 76: error: struct "ADC_REGS" has no
field "INTSEL1N2"
AdcRegs.INTSEL1N2.bit.INT1E = 1; // enabled ADCINT1
^
"../Example_2833xEPwmUpDownAQ.c", line 77: error: struct "ADC_REGS" has no
field "INTSEL1N2"
AdcRegs.INTSEL1N2.bit.INT1CONT = 0; // disable ADCINT1 continuous mode
^
"../Example_2833xEPwmUpDownAQ.c", line 78: error: struct "ADC_REGS" has no
field "INTSEL1N2"
AdcRegs.INTSEL1N2.bit.INT1SEL = 1; // setup EOC1 to trigger ADCINT1
^
"../Example_2833xEPwmUpDownAQ.c", line 79: error: struct "ADC_REGS" has no
field "INTSEL1N2"
AdcRegs.INTSEL1N2.bit.INT2E = 0; // enable ADCINT2
^
"../Example_2833xEPwmUpDownAQ.c", line 80: error: struct "ADC_REGS" has no
field "INTSEL1N2"
AdcRegs.INTSEL1N2.bit.INT2CONT = 0; // disable ADCINT1 continuous mode
^
"../Example_2833xEPwmUpDownAQ.c", line 81: error: struct "ADC_REGS" has no
field "INTSEL1N2"
AdcRegs.INTSEL1N2.bit.INT2SEL = 0; // setup EOC1 to trigger ADCINT2
^
"../Example_2833xEPwmUpDownAQ.c", line 82: error: struct "ADC_REGS" has no
field "ADCSOC0CTL"
AdcRegs.ADCSOC0CTL.bit.CHSEL = 0; // set SOC0 channel select to ADCINA0
^
"../Example_2833xEPwmUpDownAQ.c", line 83: error: struct "ADC_REGS" has no
field "ADCSOC1CTL"
AdcRegs.ADCSOC1CTL.bit.CHSEL = 8; // set SOC1 channel select to ADCINB0
^
"../Example_2833xEPwmUpDownAQ.c", line 84: error: struct "ADC_REGS" has no
field "ADCSOC0CTL"
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; // set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
^
"../Example_2833xEPwmUpDownAQ.c", line 85: error: struct "ADC_REGS" has no
field "ADCSOC1CTL"
AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 5; // set SOC1 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
^
"../Example_2833xEPwmUpDownAQ.c", line 86: error: struct "ADC_REGS" has no
field "ADCSOC0CTL"
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; // set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
^
"../Example_2833xEPwmUpDownAQ.c", line 87: error: struct "ADC_REGS" has no
field "ADCSOC1CTL"
AdcRegs.ADCSOC1CTL.bit.ACQPS = 6; // set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
^
"../Example_2833xEPwmUpDownAQ.c", line 142: error: struct "ADC_REGS" has no
field "ADCINTFLGCLR"
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
^
"../Example_2833xEPwmUpDownAQ.c", line 145: error: identifier "AdcResult" is
undefined
yk = ((float) AdcResult.ADCRESULT0 - 2048.0f) / 2047.0f;
^
16 errors detected in the compilation of "../Example_2833xEPwmUpDownAQ.c".
gmake: *** [Example_2833xEPwmUpDownAQ.obj] Error 1
gmake: Target 'all' not remade because of errors.
**** Build Finished ****

4- The code is attached here:
/* Example_F28069_PID.c
*
* Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
* ALL RIGHTS RESERVED
*
*/
// header files
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#include "DSP2833x_GlobalPrototypes.h"
#include "DCLF32.h"
// function prototypes
extern interrupt void control_Isr(void);
// global variables
long IdleLoopCount = 0;
long IsrCount = 0;
float rk = 0.25f;
float yk;
float lk;
float uk;
DCL_PID pid1 = PID_DEFAULTS;
float Duty;
float upperlim = 0.95f;
float lowerlim = 0.05f;
unsigned int clampactive;
/* main */
main()
{
/* initialise system */
InitSysCtrl(); // [F2806x_SysCtrl.c]
DINT; // disable interrupts
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl(); // initialise PIE control registers [F2806x_PieCtrl.c]
InitPieVectTable(); // initialise PIE vector table [F2806x_PieVect.c]
EALLOW;
PieVectTable.ADCINT1 = &control_Isr; // [F28069_PID_cisr.c]
EDIS;
/* configure ePWM1 */
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
InitEPwm(); // [F2806x_EPwm.c]
EPwm1Regs.TBCTL.bit.CTRMODE = 3; // freeze TB counter
EPwm1Regs.TBCTL.bit.PRDLD = 1; // immediate load
EPwm1Regs.TBCTL.bit.PHSEN = 0; // disable phase loading
EPwm1Regs.TBCTL.bit.SYNCOSEL = 3; // disable SYNCOUT signal
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0; // TBCLK = SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // clock divider = /1
EPwm1Regs.TBCTL.bit.FREE_SOFT = 2; // free run on emulation suspend
EPwm1Regs.TBPRD = 0x2328; // set period for ePWM1 (0x2328 = 10kHz)
EPwm1Regs.TBPHS.all = 0; // time-base Phase Register
EPwm1Regs.TBCTR = 0; // time-base Counter Register
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 1; // select SOC from zero match
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // generate pulse on 1st event
EPwm1Regs.CMPCTL.bit.SHDWAMODE = 0; // enable shadow mode
EPwm1Regs.CMPCTL.bit.LOADAMODE = 2; // reload on CTR=zero
EPwm1Regs.CMPA.half.CMPA = 0x0080; // set compare A value
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // HIGH on CMPA up match
EPwm1Regs.AQCTLA.bit.ZRO = AQ_CLEAR; // LOW on zero match
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
/* configure ADC */
InitAdc(); // [F2806x_Adc.c]
EALLOW;
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 0; // early interrupt generation
AdcRegs.INTSEL1N2.bit.INT1E = 1; // enabled ADCINT1
AdcRegs.INTSEL1N2.bit.INT1CONT = 0; // disable ADCINT1 continuous mode
AdcRegs.INTSEL1N2.bit.INT1SEL = 1; // setup EOC1 to trigger ADCINT1
AdcRegs.INTSEL1N2.bit.INT2E = 0; // enable ADCINT2
AdcRegs.INTSEL1N2.bit.INT2CONT = 0; // disable ADCINT1 continuous mode
AdcRegs.INTSEL1N2.bit.INT2SEL = 0; // setup EOC1 to trigger ADCINT2
AdcRegs.ADCSOC0CTL.bit.CHSEL = 0; // set SOC0 channel select to ADCINA0
AdcRegs.ADCSOC1CTL.bit.CHSEL = 8; // set SOC1 channel select to ADCINB0
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; // set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 5; // set SOC1 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; // set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
AdcRegs.ADCSOC1CTL.bit.ACQPS = 6; // set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
EDIS;
/* configure GPIO */
InitGpio(); // [F2806x_Gpio.c]
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0; // GPIO34 = I/O pin
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // GPIO34 = output
GpioDataRegs.GPBSET.bit.GPIO34 = 1; // GPIO34 = 1
GpioCtrlRegs.GPBMUX1.bit.GPIO39 = 0; // GPIO39 = I/O pin
GpioCtrlRegs.GPBDIR.bit.GPIO39 = 1; // GPIO39 = output
GpioDataRegs.GPBCLEAR.bit.GPIO39 = 1; // GPIO39 = 0
EDIS;
/* initialise controller variables */
pid1.Kp = 9.0f;
pid1.Ki = 0.015f;
pid1.Kd = 0.35f;
pid1.Kr = 1.0f;
pid1.c1 = 188.0296600613396f;
pid1.c2 = 0.880296600613396f;
pid1.d2 = 0.0f;
pid1.d3 = 0.0f;
pid1.i10 = 0.0f;
pid1.i14 = 1.0f;
pid1.Umax = 1.0f;
pid1.Umin = -1.0f;
rk = 0.25f; // initial value for control reference
lk = 1.0f; // control loop not saturated
/* enable interrupts */
PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // enable PIE INT 1.1 (ADCINT1) - [adcisr]
IER |= M_INT1; // enable core interrupt 1 (ADC) - [control_isr]
SetDBGIER(0x0001); // enable real-time debug interupts
EINT; // enable global interrupt mask
EALLOW;
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // PWM1 timer: count up and start
EDIS;
/* idle loop */
while(1)
{
IdleLoopCount++; // increment loop counter
asm(" NOP");
} // while
} // main
/* control ISR: triggered by ADC EOC */
interrupt void control_Isr(void)
{
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
// read ADC channel
yk = ((float) AdcResult.ADCRESULT0 - 2048.0f) / 2047.0f;
// run PID controller
uk = DCL_runPID_C4(&pid1, rk, yk, lk);
// external clamp for anti-windup reset
clampactive = DCL_runClamp_C1(&uk, upperlim, lowerlim);
lk = (clampactive == 0U) ? 1.0f : 0.0f;
// write u(k) to PWM
Duty = (uk / 2.0f + 0.5f) * (float) EPwm1Regs.TBPRD;
EPwm1Regs.CMPA.half.CMPA = (Uint16) Duty;
IsrCount++;
}
/* end of file */
Community members, please suggest to resolve the issue.
Regards
Arsalan
















