TMS320F28069: Help me fix the error where the ADC already has a result of 1860 when I just ran the program, even though the ADC input is 0V.

Part Number: TMS320F28069
Other Parts Discussed in Thread: TMDSCNCD28069

Recently, I purchased and started using the TMS320F28069 microcontroller. However, I'm encountering issues with the ADC (Analog-to-Digital Converter) functionality and I'm in need of assistance. Despite declaring the ADC as per the provided specifications, I'm facing a persistent problem. Even after calibrating the ADC and applying offset adjustments, the initial ADC value upon program initialization remains at 1860, despite there being no input signal. This issue persists despite continuous efforts to update the ADC values. Any guidance or support in resolving this matter would be greatly appreciated.

  • this is my code.

    #include "DSP28x_Project.h"
    
    #include "controller.h"
    
    
    
    #define FRQ_CLCK 90000000          // Clock frequency
    
    #define F_SW 20000                  // Switching frequency
    
    #define PWM_CNT_UPDOWN 2
    
    
    
    // Function Prototypes
    
    void ConfigureADC(void);           // Prototype function for configuration of a ADC converter
    
    void SetupADC1(void);              // Prototype function for the setup of the AIN14 pin
    
    void SetupADC2(void);              // Prototype function for the setup of the AIN2 pin
    
    void InitEPwm1(void);              // Prototype function for configuration of the ePWMA module
    
    void SetupIntTimer(void);          // Prototype function for configuration of the CPU Timer interupt
    
    interrupt void timer_isr(void);    // Prototype function for timer interrupt service routine
    
    
    
    Uint16 Va_reg,Va;
    
    real_t Vout;
    
    
    
    real_t Vref;
    
    
    
    Uint16 Iout_reg;
    
    real_t Iout;
    
    
    
    float D;
    
    
    
    real_t Vref = 12;
    
    real_t Enable = 0;
    
    float Ts= 50;                       // Execution of the timer interrupt (us)
    
    
    
    Uint16 tbprd;
    
    
    
                                                        // Initial states for data model from code generation
    
    controller_ModelData generatedModel;                // Model structure is passed as an argument to both init and step functions - which are used to interact with the generated C code.
    
    controller_ExtIn inputs = {0};                      // Contains variables generated from the inputs of the selected subsystem
    
    controller_ExtOut outputs = {0};                    // Contains variables generated from the outputs of the selected subsystem
    
    controller_ModelStates states = {0};                // Contains variables used to preserve the state between successive calls of step function.
    
    
    
    void main(void)
    
    {
    
        // Initialize System Control
    
        InitSysCtrl();
    
    
    
        // Initialize GPIO
    
        InitGpio();                                     // Configure default GPIO
    
        InitEPwm1Gpio();                                // Configure EPWM1 GPIO pins
    
    
    
        // Clear all interrupts and initialize PIE vector table
    
        DINT;
    
        InitPieCtrl();
    
        IER = 0x0000;
    
        IFR = 0x0000;
    
        InitPieVectTable();
    
    
    
        // Setting up the timer interrupt
    
        SetupIntTimer();
    
    
    
        EALLOW;
    
        GpioCtrlRegs.GPADIR.bit.GPIO31 = 1;         // Drives LED LD2 on controlCARD
    
        EDIS;
    
        GpioDataRegs.GPADAT.bit.GPIO31 = 1;         // Turn off LED
    
    
    
        GpioCtrlRegs.GPADIR.bit.GPIO24 = 0;        // Configuring the pin as input
    
    
    
        GpioCtrlRegs.GPADIR.bit.GPIO25 = 0;        // Configuring the pin as input
    
    
    
        EALLOW;
    
        GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;         // Drives LED LD2 on controlCARD
    
        EDIS;
    
        GpioDataRegs.GPBDAT.bit.GPIO34 = 1;         // Turn off LED
    
    
    
        // Configure the ADC and power it up
    
        ConfigureADC();
    
    
    
        // Setup the ADC for ePWM triggered conversions on channel 0
    
        SetupADC1();
    
        //SetupADC2();
    
    
    
        // Initialize ePWM modules
    
        InitEPwm1();
    
    
    
        EINT;                   // Enable Global interrupt INTM
    
        ERTM;                   // Enable Global realtime interrupt DBGM
    
    
    
        // Enable PIE interrupt
    
        PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
    
        EINT;                   // Enable Global interrupt INTM
    
        ERTM;                   // Enable Global real time interrupt DBGM
    
        EDIS;
    
    
    
        // Sync ePWM
    
        EALLOW;
    
        SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
    
    
    
        // Start ePWm
    
        //EPwm1Regs.ETSEL.bit.SOCAEN  = 1;    //enable SOCA
    
        //EPwm1Regs.TBCTL.bit.CTRMODE = 2;
    
    
    
        // define initial states for data model from code generation
    
        generatedModel.p_extIn = &inputs;
    
        generatedModel.p_extOut = &outputs;
    
        generatedModel.p_States = &states;
    
        controller_init(&generatedModel);
    
        do {
    
            if (generatedModel.p_extIn->enable)
    
            {
    
                GpioDataRegs.GPADAT.bit.GPIO31 = 0;     // Turn on LED
    
                DELAY_US(1000 * 500);                   // ON delay
    
                GpioDataRegs.GPADAT.bit.GPIO31 = 1;     // Turn off LED
    
                DELAY_US(1000 * 500);                   // OFF delay
    
            }
    
        } while(1);
    
    }
    
    void ConfigureADC(void)
    
    {
    
        EALLOW;
    
        AdcRegs.ADCCTL1.bit.ADCBGPWD = 1;         // Power up bandgap reference
    
        AdcRegs.ADCCTL1.bit.ADCREFPWD = 1;        // Power up reference buffer
    
        AdcRegs.ADCCTL1.bit.ADCPWDN = 1;          // Power up rest of ADC
    
        AdcRegs.ADCCTL1.bit.ADCENABLE = 1;        // Enable ADC
    
        AdcRegs.ADCCTL1.bit.ADCREFSEL = 0;      // Select interal BG
    
        EDIS;
    
        DELAY_US(1000);                             // Delay for 1ms to allow ADC time to power up
    
    
    
        EALLOW;
    
        AdcRegs.ADCCTL2.bit.CLKDIV2EN = 1;        // ADC CLK Div2 enable
    
        AdcRegs.ADCCTL2.bit.CLKDIV4EN = 1;        // ADC CLK Div4 enable
    
        AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;      // Set pulse positions to late
    
        AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1;     // eNABLE OVERLAP OF SAMPLE
    
        EDIS;
    
    }
    
    
    
    void SetupADC1(void)
    
    {
    
        // Select the channels to convert and end of conversion flag
    
        EALLOW;
    
        AdcRegs.ADCSOC14CTL.bit.CHSEL = 0;          // SOC14 will convert pin A0 - > HIL AO pin 1
    
        AdcRegs.ADCSOC14CTL.bit.ACQPS = 6;          // Sample window is 7 SYSCLK cycles = ACQPS + 1
    
        AdcRegs.ADCSOC14CTL.bit.TRIGSEL = 2;         // Trigger on TIMER01 SOCA/C
    
        EDIS;
    
    
    
        EALLOW;
    
        AdcRegs.ADCSOC2CTL.bit.CHSEL = 8;            // SOC2 will convert pin 8- > HIL AO pin 7
    
        AdcRegs.ADCSOC2CTL.bit.ACQPS = 6;           // Sample window is 7 SYSCLK cycles = ACQPS + 1
    
        AdcRegs.ADCSOC2CTL.bit.TRIGSEL = 2;          // Trigger on TIMER01 SOCA/C
    
        EDIS;
    
    }
    
    void SetupADC2(void)
    
    {
    
        // Select the channels to convert and end of conversion flag
    
        EALLOW;
    
        AdcRegs.ADCSOC3CTL.bit.CHSEL = 13;          // SOC4 will convert pin B4
    
        AdcRegs.ADCSOC3CTL.bit.ACQPS = 6;         // Sample window is 7 SYSCLK cycles = ACQPS + 1
    
        AdcRegs.ADCSOC3CTL.bit.TRIGSEL = 2;        // Trigger on TIMER01 SOCA/C
    
        EDIS;
    
    }
    
    
    
    void InitEPwm1(void)
    
    {
    
    
    
        tbprd = FRQ_CLCK/2/F_SW;
    
        EALLOW;
    
    
    
        // Time Base block configuration
    
        EPwm1Regs.TBCTL.bit.CTRMODE = PWM_CNT_UPDOWN;            // 2h up down counter mode
    
        EPwm1Regs.TBCTL.bit.CLKDIV = 0;                          // These bits select the time base clock pre-scale value (TBCLK =EPWMCLK/(HSPCLKDIV * CLKDIV):
    
                                                                 // 000:/1 (default on reset)
    
        EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;                       //  High Speed Time Base Clock Pre-Scale Bits, TBCLK pre-scaler = /1
    
        EPwm1Regs.TBPRD = tbprd;                                 // tbprd = 10000, Set period to 10000 counts (10kHz)
    
    
    
        // Action Qualifier configuration
    
        EPwm1Regs.AQCTLA.bit.CAU=1;         // Action When TBCTR = CMPA on Up Count
    
                                            // 01: Clear: force EPWMxA output low.
    
    
    
        EPwm1Regs.AQCTLA.bit.CAD=2;         // Action When TBCTR = CMPA on Down Count
    
                                            // 10: Set: force EPWMxA output high.
    
    
    
        EPwm1Regs.AQCTLB.bit.CBU=2;         // Action When TBCTR = CMPB on Up Count
    
                                            // 10: Set: force EPWMxB output high.
    
    
    
        EPwm1Regs.AQCTLB.bit.CBD=1;         // Action When TBCTR = CMPB on Down Count                                // Clear: force EPWMxB output low.
    
    
    
        // Counter Compare block configuration:
    
    //    EPwm1Regs.CMPA.bit.CMPA  = D*tbprd; // The value in the active CMPA register is continuously compared to the time-base counter (TBCTR)
    
    //    EPwm1Regs.CMPB.bit.CMPB  = D*tbprd; // The value in the active CMPA register is continuously compared to the time-base counter (TBCTR)
    
        EPwm1Regs.CMPA.half.CMPA = D*tbprd;
    
        EPwm1Regs.CMPB = D*tbprd;
    
    
    
        // Dead Band block configuration:
    
        EPwm1Regs.DBCTL.bit.HALFCYCLE = 0;  // 0: Full cycle clocking enabled. The dead-band counters are clocked at the TBCLK rate.
    
    //    EPwm1Regs.DBCTL.bit.DEDB_MODE = 0;  // Rising edge delay and falling edge delay applied to source
    
                                            // selected by S4 switch (INMODE bits) and output to B signal path
    
                                            // only. Note: When this bit is set to 1, user should always either set
    
                                            // OUT_MODE bits such that Apath = InA OR OUTSWAP bits such
    
                                            // that OutA=Bpath
    
        EPwm1Regs.DBCTL.bit.OUT_MODE = 3;   // 11: DBM is fully enabled (i.e. both RED and FED active)
    
        EPwm1Regs.DBCTL.bit.POLSEL = 2;     // 10: Active high complementary (AHC). EPWMxB is inverted.
    
        EPwm1Regs.DBCTL.bit.IN_MODE= 0;     // 00: EPWMxA In (from the action-qualifier) is the source for both
    
                                            // rising-edge delay and falling-edge delayed signal.
    
        EPwm1Regs.DBRED = 0;
    
        EPwm1Regs.DBFED = 0;
    
    
    
        EPwm1Regs.ETSEL.bit.SOCAEN  = 0;    // Disable SOC on A group
    
        EPwm1Regs.ETSEL.bit.INTEN = 1;      // Enable ePWM Interrupt (EPWMx_INT) Generation
    
                                            // 1: Enable EPWMx_INT generation
    
    
    
        EPwm1Regs.ETSEL.bit.SOCASEL = 2;    // 010: Enable event time-base counter equal to period (TBCTR = TBPRD)
    
    
    
        EPwm1Regs.ETSEL.bit.INTSEL = 1;     // 001: Enable event time-base counter equal to zero. (TBCTR = 0x00)
    
    
    
        EPwm1Regs.ETPS.bit.INTPRD = 1;      // Generate INT on 1st event
    
    
    
        EPwm1Regs.ETPS.bit.SOCAPRD = 1;     // Generate pulse on 1st event
    
    
    
        // Setup shadow register load on ZERO
    
        EPwm1Regs.CMPCTL.bit.SHDWAMODE = 0;
    
        EPwm1Regs.CMPCTL.bit.SHDWBMODE = 0;
    
        EPwm1Regs.CMPCTL.bit.LOADAMODE = 0;
    
        EPwm1Regs.CMPCTL.bit.LOADBMODE = 0;
    
        EDIS;
    
    }
    
    
    
    interrupt void timer_isr(void)
    
    {
    
        Va_reg = AdcResult.ADCRESULT14;        // ADC result range is [0 - 4096] for the analog inputs of range [0 - 3.3V]
    
        Vout = (((float)Va_reg)*3.3*5.6)/(4096);
    
    
    
        Iout_reg = AdcResult.ADCRESULT2;       // ADC result range is [0 - 4096] for the analog inputs of range [0 - 3.3V]
    
        Iout = (((float)Iout_reg)*3.3*26.6)/(4096);
    
    
    
        // feeding data to the code genereted controller function, as a result we get new vaule for duty cycle
    
        generatedModel.p_extIn->v_ref = Vref;
    
        generatedModel.p_extIn->v_meas = Vout;
    
        generatedModel.p_extIn->i_meas = Iout;
    
        generatedModel.p_extIn->rst_alarms = ((int)GpioDataRegs.GPADAT.bit.GPIO24);
    
        generatedModel.p_extIn->enable = ((int)GpioDataRegs.GPADAT.bit.GPIO25);
    
    
    
        controller_step(&generatedModel);
    
    
    
        if (generatedModel.p_extOut->alarm)
    
        {
    
            D = generatedModel.p_extOut->m;
    
    
    
            EALLOW;
    
            EPwm1Regs.CMPA.half.CMPA = D*tbprd;
    
            EPwm1Regs.CMPB = D*tbprd;
    
            EDIS;
    
    
    
            GpioDataRegs.GPBDAT.bit.GPIO34 = 0;     // Turn off LED (Red)
    
            DELAY_US(1000 * 500);                   // ON delay
    
            GpioDataRegs.GPBDAT.bit.GPIO34 = 1;     // Turn on LED (Red)
    
            DELAY_US(1000 * 500);
    
        }
    
        else
    
        {
    
            D = generatedModel.p_extOut->m;
    
            GpioDataRegs.GPBDAT.bit.GPIO34 = 1;     // Turn off LED (Red)
    
    
    
            // scaling duty cycle for the EPWM peripheral comparator block
    
            EALLOW;
    
            EPwm1Regs.CMPA.half.CMPA = D*tbprd;
    
            EPwm1Regs.CMPB = D*tbprd;
    
            EDIS;
    
        }
    
    }
    
    void SetupIntTimer(void)
    
    {
    
        DINT; // Step 1: Disable interrupts globally (DINT or SETC INTM).
    
        InitPieCtrl();
    
        IER = 0x0000;
    
        IFR = 0x0000;
    
        InitPieVectTable();
    
    
    
    //    CpuSysRegs.PCLKCR0.bit.CPUTIMER1 = 1; // Enable timer clock
    
        SysCtrlRegs.PCLKCR3.bit.CPUTIMER1ENCLK=1;
    
    
    
        EALLOW;
    
    //    PieVectTable.TIMER1_INT = &timer_isr;  // Redirect function to interruption
    
        PieVectTable.TINT1= &timer_isr;
    
        EDIS;
    
    
    
        InitCpuTimers();
    
    
    
        ConfigCpuTimer(&CpuTimer1, 90, Ts);   // Configure cpu timer0 with 90MHz and 50us
    
    
    
        CpuTimer1Regs.TCR.all = 0x4001;
    
    
    
        IER |= M_INT13;                           // Enable lines of interrupt
    
    
    
    }
    
    
    

  • Hello,

    Please do not dump code as raw text into a post, use the Insert > Code option to make sure the post is still readable to other users.

  • #include "DSP28x_Project.h"
    #include "controller.h"
    
    #define FRQ_CLCK 90000000          // Clock frequency
    #define F_SW 20000                  // Switching frequency
    #define PWM_CNT_UPDOWN 2
    
    // Function Prototypes
    void ConfigureADC(void);           // Prototype function for configuration of a ADC converter
    void SetupADC1(void);              // Prototype function for the setup of the AIN14 pin
    void SetupADC2(void);              // Prototype function for the setup of the AIN2 pin
    void InitEPwm1(void);              // Prototype function for configuration of the ePWMA module
    void SetupIntTimer(void);          // Prototype function for configuration of the CPU Timer interupt
    interrupt void timer_isr(void);    // Prototype function for timer interrupt service routine
    
    Uint16 Va_reg,Va;
    real_t Vout;
    
    real_t Vref;
    
    Uint16 Iout_reg;
    real_t Iout;
    
    float D;
    
    real_t Vref = 12;
    real_t Enable = 0;
    float Ts= 50;                       // Execution of the timer interrupt (us)
    
    Uint16 tbprd;
    
                                                        // Initial states for data model from code generation
    controller_ModelData generatedModel;                // Model structure is passed as an argument to both init and step functions - which are used to interact with the generated C code.
    controller_ExtIn inputs = {0};                      // Contains variables generated from the inputs of the selected subsystem
    controller_ExtOut outputs = {0};                    // Contains variables generated from the outputs of the selected subsystem
    controller_ModelStates states = {0};                // Contains variables used to preserve the state between successive calls of step function.
    
    void main(void)
    {
        // Initialize System Control
        InitSysCtrl();
    
        // Initialize GPIO
        InitGpio();                                     // Configure default GPIO
        InitEPwm1Gpio();                                // Configure EPWM1 GPIO pins
    
        // Clear all interrupts and initialize PIE vector table
        DINT;
        InitPieCtrl();
        IER = 0x0000;
        IFR = 0x0000;
        InitPieVectTable();
    
        // Setting up the timer interrupt
        SetupIntTimer();
    
        EALLOW;
        GpioCtrlRegs.GPADIR.bit.GPIO31 = 1;         // Drives LED LD2 on controlCARD
        EDIS;
        GpioDataRegs.GPADAT.bit.GPIO31 = 1;         // Turn off LED
    
        GpioCtrlRegs.GPADIR.bit.GPIO24 = 0;        // Configuring the pin as input
    
        GpioCtrlRegs.GPADIR.bit.GPIO25 = 0;        // Configuring the pin as input
    
        EALLOW;
        GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;         // Drives LED LD2 on controlCARD
        EDIS;
        GpioDataRegs.GPBDAT.bit.GPIO34 = 1;         // Turn off LED
    
        // Configure the ADC and power it up
        ConfigureADC();
    
        // Setup the ADC for ePWM triggered conversions on channel 0
        SetupADC1();
        //SetupADC2();
    
        // Initialize ePWM modules
        InitEPwm1();
    
        EINT;                   // Enable Global interrupt INTM
        ERTM;                   // Enable Global realtime interrupt DBGM
    
        // Enable PIE interrupt
        PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
        EINT;                   // Enable Global interrupt INTM
        ERTM;                   // Enable Global real time interrupt DBGM
        EDIS;
    
        // Sync ePWM
        EALLOW;
        SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
    
        // Start ePWm
        //EPwm1Regs.ETSEL.bit.SOCAEN  = 1;    //enable SOCA
        //EPwm1Regs.TBCTL.bit.CTRMODE = 2;
    
        // define initial states for data model from code generation
        generatedModel.p_extIn = &inputs;
        generatedModel.p_extOut = &outputs;
        generatedModel.p_States = &states;
        controller_init(&generatedModel);
        do {
            if (generatedModel.p_extIn->enable)
            {
                GpioDataRegs.GPADAT.bit.GPIO31 = 0;     // Turn on LED
                DELAY_US(1000 * 500);                   // ON delay
                GpioDataRegs.GPADAT.bit.GPIO31 = 1;     // Turn off LED
                DELAY_US(1000 * 500);                   // OFF delay
            }
        } while(1);
    }
    void ConfigureADC(void)
    {
        EALLOW;
        AdcRegs.ADCCTL1.bit.ADCBGPWD = 1;         // Power up bandgap reference
        AdcRegs.ADCCTL1.bit.ADCREFPWD = 1;        // Power up reference buffer
        AdcRegs.ADCCTL1.bit.ADCPWDN = 1;          // Power up rest of ADC
        AdcRegs.ADCCTL1.bit.ADCENABLE = 1;        // Enable ADC
        AdcRegs.ADCCTL1.bit.ADCREFSEL = 0;      // Select interal BG
        EDIS;
        DELAY_US(1000);                             // Delay for 1ms to allow ADC time to power up
    
        EALLOW;
        AdcRegs.ADCCTL2.bit.CLKDIV2EN = 1;        // ADC CLK Div2 enable
        AdcRegs.ADCCTL2.bit.CLKDIV4EN = 1;        // ADC CLK Div4 enable
        AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;      // Set pulse positions to late
        AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1;     // eNABLE OVERLAP OF SAMPLE
        EDIS;
    }
    
    void SetupADC1(void)
    {
        // Select the channels to convert and end of conversion flag
        EALLOW;
        AdcRegs.ADCSOC14CTL.bit.CHSEL = 0;          // SOC14 will convert pin A0 - > HIL AO pin 1
        AdcRegs.ADCSOC14CTL.bit.ACQPS = 6;          // Sample window is 7 SYSCLK cycles = ACQPS + 1
        AdcRegs.ADCSOC14CTL.bit.TRIGSEL = 2;         // Trigger on TIMER01 SOCA/C
        EDIS;
    
        EALLOW;
        AdcRegs.ADCSOC2CTL.bit.CHSEL = 8;            // SOC2 will convert pin 8- > HIL AO pin 7
        AdcRegs.ADCSOC2CTL.bit.ACQPS = 6;           // Sample window is 7 SYSCLK cycles = ACQPS + 1
        AdcRegs.ADCSOC2CTL.bit.TRIGSEL = 2;          // Trigger on TIMER01 SOCA/C
        EDIS;
    }
    void SetupADC2(void)
    {
        // Select the channels to convert and end of conversion flag
        EALLOW;
        AdcRegs.ADCSOC3CTL.bit.CHSEL = 13;          // SOC4 will convert pin B4
        AdcRegs.ADCSOC3CTL.bit.ACQPS = 6;         // Sample window is 7 SYSCLK cycles = ACQPS + 1
        AdcRegs.ADCSOC3CTL.bit.TRIGSEL = 2;        // Trigger on TIMER01 SOCA/C
        EDIS;
    }
    
    void InitEPwm1(void)
    {
    
        tbprd = FRQ_CLCK/2/F_SW;
        EALLOW;
    
        // Time Base block configuration
        EPwm1Regs.TBCTL.bit.CTRMODE = PWM_CNT_UPDOWN;            // 2h up down counter mode
        EPwm1Regs.TBCTL.bit.CLKDIV = 0;                          // These bits select the time base clock pre-scale value (TBCLK =EPWMCLK/(HSPCLKDIV * CLKDIV):
                                                                 // 000:/1 (default on reset)
        EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;                       //  High Speed Time Base Clock Pre-Scale Bits, TBCLK pre-scaler = /1
        EPwm1Regs.TBPRD = tbprd;                                 // tbprd = 10000, Set period to 10000 counts (10kHz)
    
        // Action Qualifier configuration
        EPwm1Regs.AQCTLA.bit.CAU=1;         // Action When TBCTR = CMPA on Up Count
                                            // 01: Clear: force EPWMxA output low.
    
        EPwm1Regs.AQCTLA.bit.CAD=2;         // Action When TBCTR = CMPA on Down Count
                                            // 10: Set: force EPWMxA output high.
    
        EPwm1Regs.AQCTLB.bit.CBU=2;         // Action When TBCTR = CMPB on Up Count
                                            // 10: Set: force EPWMxB output high.
    
        EPwm1Regs.AQCTLB.bit.CBD=1;         // Action When TBCTR = CMPB on Down Count                                // Clear: force EPWMxB output low.
    
        // Counter Compare block configuration:
    //    EPwm1Regs.CMPA.bit.CMPA  = D*tbprd; // The value in the active CMPA register is continuously compared to the time-base counter (TBCTR)
    //    EPwm1Regs.CMPB.bit.CMPB  = D*tbprd; // The value in the active CMPA register is continuously compared to the time-base counter (TBCTR)
        EPwm1Regs.CMPA.half.CMPA = D*tbprd;
        EPwm1Regs.CMPB = D*tbprd;
    
        // Dead Band block configuration:
        EPwm1Regs.DBCTL.bit.HALFCYCLE = 0;  // 0: Full cycle clocking enabled. The dead-band counters are clocked at the TBCLK rate.
    //    EPwm1Regs.DBCTL.bit.DEDB_MODE = 0;  // Rising edge delay and falling edge delay applied to source
                                            // selected by S4 switch (INMODE bits) and output to B signal path
                                            // only. Note: When this bit is set to 1, user should always either set
                                            // OUT_MODE bits such that Apath = InA OR OUTSWAP bits such
                                            // that OutA=Bpath
        EPwm1Regs.DBCTL.bit.OUT_MODE = 3;   // 11: DBM is fully enabled (i.e. both RED and FED active)
        EPwm1Regs.DBCTL.bit.POLSEL = 2;     // 10: Active high complementary (AHC). EPWMxB is inverted.
        EPwm1Regs.DBCTL.bit.IN_MODE= 0;     // 00: EPWMxA In (from the action-qualifier) is the source for both
                                            // rising-edge delay and falling-edge delayed signal.
        EPwm1Regs.DBRED = 0;
        EPwm1Regs.DBFED = 0;
    
        EPwm1Regs.ETSEL.bit.SOCAEN  = 0;    // Disable SOC on A group
        EPwm1Regs.ETSEL.bit.INTEN = 1;      // Enable ePWM Interrupt (EPWMx_INT) Generation
                                            // 1: Enable EPWMx_INT generation
    
        EPwm1Regs.ETSEL.bit.SOCASEL = 2;    // 010: Enable event time-base counter equal to period (TBCTR = TBPRD)
    
        EPwm1Regs.ETSEL.bit.INTSEL = 1;     // 001: Enable event time-base counter equal to zero. (TBCTR = 0x00)
    
        EPwm1Regs.ETPS.bit.INTPRD = 1;      // Generate INT on 1st event
    
        EPwm1Regs.ETPS.bit.SOCAPRD = 1;     // Generate pulse on 1st event
    
        // Setup shadow register load on ZERO
        EPwm1Regs.CMPCTL.bit.SHDWAMODE = 0;
        EPwm1Regs.CMPCTL.bit.SHDWBMODE = 0;
        EPwm1Regs.CMPCTL.bit.LOADAMODE = 0;
        EPwm1Regs.CMPCTL.bit.LOADBMODE = 0;
        EDIS;
    }
    
    interrupt void timer_isr(void)
    {
        Va_reg = AdcResult.ADCRESULT14;        // ADC result range is [0 - 4096] for the analog inputs of range [0 - 3.3V]
        Vout = (((float)Va_reg)*3.3*5.6)/(4096);
    
        Iout_reg = AdcResult.ADCRESULT2;       // ADC result range is [0 - 4096] for the analog inputs of range [0 - 3.3V]
        Iout = (((float)Iout_reg)*3.3*26.6)/(4096);
    
        // feeding data to the code genereted controller function, as a result we get new vaule for duty cycle
        generatedModel.p_extIn->v_ref = Vref;
        generatedModel.p_extIn->v_meas = Vout;
        generatedModel.p_extIn->i_meas = Iout;
        generatedModel.p_extIn->rst_alarms = ((int)GpioDataRegs.GPADAT.bit.GPIO24);
        generatedModel.p_extIn->enable = ((int)GpioDataRegs.GPADAT.bit.GPIO25);
    
        controller_step(&generatedModel);
    
        if (generatedModel.p_extOut->alarm)
        {
            D = generatedModel.p_extOut->m;
    
            EALLOW;
            EPwm1Regs.CMPA.half.CMPA = D*tbprd;
            EPwm1Regs.CMPB = D*tbprd;
            EDIS;
    
            GpioDataRegs.GPBDAT.bit.GPIO34 = 0;     // Turn off LED (Red)
            DELAY_US(1000 * 500);                   // ON delay
            GpioDataRegs.GPBDAT.bit.GPIO34 = 1;     // Turn on LED (Red)
            DELAY_US(1000 * 500);
        }
        else
        {
            D = generatedModel.p_extOut->m;
            GpioDataRegs.GPBDAT.bit.GPIO34 = 1;     // Turn off LED (Red)
    
            // scaling duty cycle for the EPWM peripheral comparator block
            EALLOW;
            EPwm1Regs.CMPA.half.CMPA = D*tbprd;
            EPwm1Regs.CMPB = D*tbprd;
            EDIS;
        }
    }
    void SetupIntTimer(void)
    {
        DINT; // Step 1: Disable interrupts globally (DINT or SETC INTM).
        InitPieCtrl();
        IER = 0x0000;
        IFR = 0x0000;
        InitPieVectTable();
    
    //    CpuSysRegs.PCLKCR0.bit.CPUTIMER1 = 1; // Enable timer clock
        SysCtrlRegs.PCLKCR3.bit.CPUTIMER1ENCLK=1;
    
        EALLOW;
    //    PieVectTable.TIMER1_INT = &timer_isr;  // Redirect function to interruption
        PieVectTable.TINT1= &timer_isr;
        EDIS;
    
        InitCpuTimers();
    
        ConfigCpuTimer(&CpuTimer1, 90, Ts);   // Configure cpu timer0 with 90MHz and 50us
    
        CpuTimer1Regs.TCR.all = 0x4001;
    
        IER |= M_INT13;                           // Enable lines of interrupt
    
    }
    
    
    

  • Hi,

    Did you start with one of the examples? 

    Also, focusing on SOC14 (Input channel A0 in your code), do you have anything connected to A0? If it is floating, this result is somewhat expected.

    Could you put as breakpoint in your ADC ISR? Is it being triggered multiple times, or only once? 

    Best Regards,

    Ben Collier

  • Hello,

    I have connected to GND on SOC14 but the result is still 1860 which is obviously wrong. I don't know how to make the ADC read 0V correctly. I am using a timer interrupt to get the ADC result instead of using the ADC ISR to get the result.

    In addition to my program, I used the available EXAMPLE to get the ADC SENSOR TEMP result and here is the result. My room temperature is currently 25 degrees C while the temperature read at ADCRESULT0 is 40 degrees C.

    Please help me, thank you very much,

    Hieu

  • How to connect the reference voltage for the TMS320F28069UPZPS microcontroller, which is a 100-pin type? I am currently using the TMDSCNCD28069 controlCARD, USB EMU docking kit.

  • Hieu,

    Please see the control card user guide for that information. It will have instructions, or maybe the schematic will you show you how it is done.

    I have connected to GND on SOC14 but the result is still 1860 which is obviously wrong. I don't know how to make the ADC read 0V correctly. I am using a timer interrupt to get the ADC result instead of using the ADC ISR to get the result.

    Just to confirm, you are connecting ADC input channel A0, which is converted by SOC14, to GND? And you see values near 1800? 

    Best Regards,

    Ben Collier

  • Yes, I'm connecting ADC input channel A0 to GND and see values 1860. this is setup code for ADC. I don't know why this is so. I used two kits: Typhoon Hil DSP100 interface 3.1 and Docking_stn USB-EMU to try but the results are the same. I have 2 TMS320f28069 chips and I tried with both chips on the same code to avoid errors due to one card being damaged but the results are the same. I think my code has a problem but I don't know how to fix it because I just used TMS320F28069

    void ConfigureADC(void)
    {
        EALLOW;
        AdcRegs.ADCCTL1.bit.ADCBGPWD = 1;         // Power up bandgap reference
        AdcRegs.ADCCTL1.bit.ADCREFPWD = 1;        // Power up reference buffer
        AdcRegs.ADCCTL1.bit.ADCPWDN = 1;          // Power up rest of ADC
        AdcRegs.ADCCTL1.bit.ADCENABLE = 1;        // Enable ADC
        AdcRegs.ADCCTL1.bit.ADCREFSEL = 0;      // Select interal BG
        AdcRegs.ADCCTL1.bit.VREFLOCONV =1;
        EDIS;
        DELAY_US(1000);                             // Delay for 1ms to allow ADC time to power up
    
        EALLOW;
        AdcRegs.ADCCTL2.bit.CLKDIV2EN = 1;        // ADC CLK Div2 enable
        AdcRegs.ADCCTL2.bit.CLKDIV4EN =0;        // ADC CLK Div4 enable
        AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;      // Set pulse positions to late
        AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1;     // eNABLE OVERLAP OF SAMPLE
        EDIS;
    }
    
    void SetupADC1(void)
    {
        // Select the channels to convert and end of conversion flag
        EALLOW;
        AdcRegs.ADCSOC14CTL.bit.CHSEL = 0;          // SOC14 will convert pin A0 - > HIL AO pin 1
        AdcRegs.ADCSOC14CTL.bit.ACQPS = 6;          // Sample window is 7 SYSCLK cycles = ACQPS + 1
        AdcRegs.ADCSOC14CTL.bit.TRIGSEL = 2;         // Trigger on TIMER01 SOCA/C
        EDIS;
    
        EALLOW;
        AdcRegs.ADCSOC2CTL.bit.CHSEL = 8;            // SOC2 will convert pin 8- > HIL AO pin 7
        AdcRegs.ADCSOC2CTL.bit.ACQPS = 6;           // Sample window is 7 SYSCLK cycles = ACQPS + 1
        AdcRegs.ADCSOC2CTL.bit.TRIGSEL = 2;          // Trigger on TIMER01 SOCA/C
        EDIS;
    }
    void SetupADC2(void)
    {
        // Select the channels to convert and end of conversion flag
        EALLOW;
        AdcRegs.ADCSOC3CTL.bit.CHSEL = 13;          // SOC4 will convert pin B4
        AdcRegs.ADCSOC3CTL.bit.ACQPS = 6;         // Sample window is 7 SYSCLK cycles = ACQPS + 1
        AdcRegs.ADCSOC3CTL.bit.TRIGSEL = 2;        // Trigger on TIMER01 SOCA/C
        EDIS;
    }

  • Hieu,

    Did you try any of the ADC examples? It would be a good idea to compare your code with them.

  • thanks you, and now I have new issue. I connect ADC with 1.96V DC source but only the first ADC channel that read the right value, while the others cannot read the right value.

  • Hi,

    Could you please start a new thread for your new issue? 

    When you post the thread, please show how you are setting up your SOCs. 

    Best Regards,

    Ben Collier