This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28379D: How to confirm that PWM is triggering SOC interrupt?

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

I am in the process of converting a program for a F28335 DSP to a F28379D DSP. My current focus is ADC driven by PWM. I have modified ADC channels to use banks A-D and believe that the ADC read and conversion logic is correct. I have programmed banks ADCA and ADCC to use SOCA from PWM1 for SOC trigger, and ADCB and ADCD to use SOCB from PWM1. 

The EOC is occurring and triggering execution of the EOC ISR. But when I examine ADC data acquired, everything seems to only show a non-zero but very low ADC count regardless of the amplitude of the input signal to the ADC channel.

So my question is: Is there a way I can confirm that the SOC events have occurred and that data IS being acquired? Is it possible for the SOC events not to have occurred, and the EOC interrupt still occurs? If not, is there another possible cause for failing to acquire ADC input data? Stupid question, I am sure there are many!  Do you perhaps have a publication with debugging tips for ADC on a F28379D DSP target?

  • Hello Thomas,

    I recommend first trying to use one of the ADC examples in C2000Ware to make sure it works on your device, and then debug your own program by comparing the two sets of code. The ADC examples can be found in C2000Ware_5_01_00_00\driverlib\f2837xd\examples\cpu1\adc.

    Beyond that, if you're getting an incorrect ADC result then verify that the reference is correct, the connection with the ADC pin is stable (you should also verify the voltage being applied is valid), measure the difference between what is expected and what is observed (whether it's consistent or not), verify the ADC is properly enabled (i.e. following the example code), and use a software trigger to measure a known DC voltage. These are just some items to check, unfortunately your issue isn't very specific so there aren't any targeted debug questions to ask quite yet.

  • Omer - After I placed the post I realized that I should do as you suggest - compare my ADC logic to a C2000ware example. The example project adc_soc_pwm_cpu01 is the closest to the method we are using. I currently have a prototype board with a reliable input into ADCB channel 5 that I can use for test purposes, so I created a modified version of the example source, and named the new source file adcB_soc_pwm_cpu01.c. I made local copies of the example C source and my modified C source so that either one can be included or excluded from the build to test performance of one or the other. 

    The project is now at a state that the example version accessing ADCA pin 0 runs and fills the results buffer with zeros. The ADCB pin 5 version stalls during the read loop with the results index never climbing above 0. I have attached a ZIP file of the project.  Can you let me know what I have done wrong so that the SOC or EOC events do not seem to be occurring?

     adc_soc_software_cpu01.zip

  • Hello Thomas,

    The ADCB pin 5 version stalls during the read loop with the results index never climbing above 0.

    I couldn't import your code because there were some errors, but I verified in the driverlib example adc_ex2_soc_epwm and the code executes fine when I chance ADCA_BASE to ADCB_BASE, ADCIN0 to ADCIN5, and change the interrupts to use ADCB instead of ADCA:

    //#############################################################################
    //
    // FILE:   adc_ex2_soc_epwm.c
    //
    // TITLE:  ADC ePWM Triggering
    //
    //! \addtogroup driver_example_list
    //! <h1>ADC ePWM Triggering</h1>
    //!
    //! This example sets up ePWM1 to periodically trigger a conversion on ADCA.
    //!
    //! \b External \b Connections \n
    //!  - A0 should be connected to a signal to convert
    //!
    //! \b Watch \b Variables \n
    //! - \b adcAResults - A sequence of analog-to-digital conversion samples from
    //!   pin A0. The time between samples is determined based on the period
    //!   of the ePWM timer.
    //!
    //
    //#############################################################################
    //
    // 
    // $Copyright:
    // Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //#############################################################################
    //
    
    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    
    //
    // Defines
    //
    #define RESULTS_BUFFER_SIZE     256
    #define EX_ADC_RESOLUTION       12
    // 12 for 12-bit conversion resolution, which supports (ADC_MODE_SINGLE_ENDED)
    // Sample on single pin (VREFLO is the low reference)
    // Or 16 for 16-bit conversion resolution, which supports (ADC_MODE_DIFFERENTIAL)
    // Sample on pair of pins (difference between pins is converted, subject to
    // common mode voltage requirements; see the device data manual)
    
    //
    // Globals
    //
    uint16_t adcAResults[RESULTS_BUFFER_SIZE];   // Buffer for results
    uint16_t index;                              // Index into result buffer
    volatile uint16_t bufferFull;                // Flag to indicate buffer is full
    
    //
    // Function Prototypes
    //
    void initADC(void);
    void initEPWM(void);
    void initADCSOC(void);
    __interrupt void adcA1ISR(void);
    
    //
    // Main
    //
    void main(void)
    {
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pullups.
        //
        Device_initGPIO();
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
        //
        // Interrupts that are used in this example are re-mapped to ISR functions
        // found within this file.
        //
        Interrupt_register(INT_ADCB1, &adcA1ISR);
    
        //
        // Set up the ADC and the ePWM and initialize the SOC
        //
        initADC();
        initEPWM();
        initADCSOC();
    
        //
        // Initialize results buffer
        //
        for(index = 0; index < RESULTS_BUFFER_SIZE; index++)
        {
            adcAResults[index] = 0;
        }
    
        index = 0;
        bufferFull = 0;
    
        //
        // Enable ADC interrupt
        //
        Interrupt_enable(INT_ADCB1);
    
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // Loop indefinitely
        //
        while(1)
        {
            //
            // Start ePWM1, enabling SOCA and putting the counter in up-count mode
            //
            EPWM_enableADCTrigger(EPWM1_BASE, EPWM_SOC_A);
            EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP);
    
            //
            // Wait while ePWM1 causes ADC conversions which then cause interrupts.
            // When the results buffer is filled, the bufferFull flag will be set.
            //
            while(bufferFull == 0)
            {
            }
            bufferFull = 0;     // Clear the buffer full flag
    
            //
            // Stop ePWM1, disabling SOCA and freezing the counter
            //
            EPWM_disableADCTrigger(EPWM1_BASE, EPWM_SOC_A);
            EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_STOP_FREEZE);
    
            //
            // Software breakpoint. At this point, conversion results are stored in
            // adcAResults.
            //
            // Hit run again to get updated conversions.
            //
            ESTOP0;
        }
    }
    
    //
    // Function to configure and power up ADCA.
    //
    void initADC(void)
    {
        
        //
        // Set ADCDLK divider to /4
        //
        ADC_setPrescaler(ADCB_BASE, ADC_CLK_DIV_4_0);
    
        //
        // Set resolution and signal mode (see #defines above) and load
        // corresponding trims.
        //
    #if(EX_ADC_RESOLUTION == 12)
        ADC_setMode(ADCB_BASE, ADC_RESOLUTION_12BIT, ADC_MODE_SINGLE_ENDED);
    #elif(EX_ADC_RESOLUTION == 16)
        ADC_setMode(ADCB_BASE, ADC_RESOLUTION_16BIT, ADC_MODE_DIFFERENTIAL);
    #endif
    
        //
        // Set pulse positions to late
        //
        ADC_setInterruptPulseMode(ADCB_BASE, ADC_PULSE_END_OF_CONV);
    
        //
        // Power up the ADC and then delay for 1 ms
        //
        ADC_enableConverter(ADCB_BASE);
        DEVICE_DELAY_US(1000);
    }
    
    //
    // Function to configure ePWM1 to generate the SOC.
    //
    void initEPWM(void)
    {
        //
        // Disable SOCA
        //
        EPWM_disableADCTrigger(EPWM1_BASE, EPWM_SOC_A);
    
        //
        // Configure the SOC to occur on the first up-count event
        //
        EPWM_setADCTriggerSource(EPWM1_BASE, EPWM_SOC_A, EPWM_SOC_TBCTR_U_CMPA);
        EPWM_setADCTriggerEventPrescale(EPWM1_BASE, EPWM_SOC_A, 1);
    
        //
        // Set the compare A value to 1000 and the period to 1999
        // Assuming ePWM clock is 100MHz, this would give 50kHz sampling
        // 50MHz ePWM clock would give 25kHz sampling, etc. 
        // The sample rate can also be modulated by changing the ePWM period
        // directly (ensure that the compare A value is less than the period). 
        //
        EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, 1000);
        EPWM_setTimeBasePeriod(EPWM1_BASE, 1999);
    
        //
        // Set the local ePWM module clock divider to /1
        //
        EPWM_setClockPrescaler(EPWM1_BASE,
                               EPWM_CLOCK_DIVIDER_1,
                               EPWM_HSCLOCK_DIVIDER_1);
    
        //
        // Freeze the counter
        //
        EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_STOP_FREEZE);
    }
    
    //
    // Function to configure ADCA's SOC0 to be triggered by ePWM1.
    //
    void initADCSOC(void)
    {
        //
        // Configure SOC0 of ADCA to convert pin A0. The EPWM1SOCA signal will be
        // the trigger.
        // - For 12-bit resolution, a sampling window of 15 (75 ns at a 200MHz
        //   SYSCLK rate) will be used.  For 16-bit resolution, a sampling window
        //   of 64 (320 ns at a 200MHz SYSCLK rate) will be used.
        // - NOTE: A longer sampling window will be required if the ADC driving
        //   source is less than ideal (an ideal source would be a high bandwidth
        //   op-amp with a small series resistance). See TI application report
        //   SPRACT6 for guidance on ADC driver design.
        //
    
    #if(EX_ADC_RESOLUTION == 12)
        ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_EPWM1_SOCA,
                     ADC_CH_ADCIN5, 15);
    #elif(EX_ADC_RESOLUTION == 16)
        ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_EPWM1_SOCA,
                     ADC_CH_ADCIN5, 64);
    #endif
    
        //
        // Set SOC0 to set the interrupt 1 flag. Enable the interrupt and make
        // sure its flag is cleared.
        //
        ADC_setInterruptSource(ADCB_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER0);
        ADC_enableInterrupt(ADCB_BASE, ADC_INT_NUMBER1);
        ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
    }
    
    //
    // ADC A Interrupt 1 ISR
    //
    __interrupt void adcA1ISR(void)
    {
        //
        // Add the latest result to the buffer
        //
        adcAResults[index++] = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER0);
    
        //
        // Set the bufferFull flag if the buffer is full
        //
        if(RESULTS_BUFFER_SIZE <= index)
        {
            index = 0;
            bufferFull = 1;
        }
    
        //
        // Clear the interrupt flag
        //
        ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
    
        //
        // Check if overflow has occurred
        //
        if(true == ADC_getInterruptOverflowStatus(ADCB_BASE, ADC_INT_NUMBER1))
        {
            ADC_clearInterruptOverflowStatus(ADCB_BASE, ADC_INT_NUMBER1);
            ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
        }
    
        //
        // Acknowledge the interrupt
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
    }
    

    I believe that you're missing some steps to configure the interrupts for ADC B correctly (the example you cite looks like it's using a software trigger, which may be why there's some code missing from your project). Please take a look at the driverlib example to verify you follow the correct steps there. The interrupt enable for the ADC has multiple steps (as seen within the Interrupt_enable function itself).

  • Omer - In your opening sentence, you san you ran driverlib example adc_ex2_soc_epwm as though I could just download a project from C2000ware and run it. But all I found in my copy of C200ware version 4.1 is the source file, with no project support or links to dependencies. I tried just adding the source file to my C2000ware project, and the build produced a list of 7 resources that could not be found. So you seem to have access to resources or knowledge that I am missing. Could you perhaps give me instructions on how to bring up a driverlib project when I can't locate any resources except the main C file?

  • Hello Thomas,

    I didn't know what version of C2000Ware you were using, so I referenced C2000Ware version 5.01. I installed version 4.01 and found this example, present, importable, and compiling. I'm not sure if your version of C2000Ware received modifications or if it's part of some other SDK which may not have included all the proper files, but if you do a fresh install of C2000Ware (either 4.01 or the latest) the example adc_ex2_soc_epwm is present and available for use (I have verified this today).

    Could you perhaps give me instructions on how to bring up a driverlib project when I can't locate any resources except the main C file?

    Are you able to import any driverlib project at all? There is no resource I could find on migrating from bitfields to driverlib, but in general driverlib uses the following configurations in the project properties:

    The easiest method is just by importing a driverlib project and making sure the settings are consistent, but given that it seems that's not possible you may have to verify the above options. If this still does not work, let me know.

  • Omer - Thanks for verifying that my copy of C2000ware SHOULD have importable projects. I have been doing my work for this project on a client-supplied laptop that has very aggressive security tools, so it may have quarantined the driverlib projects as dangerous. I will try a fresh copy of version 5.01.1.

    If portions of the C2000ware install are quarantined, I appreciate your instructions for creating a project. I'll get back to you when I have a working driverlib project.  

  • I have installed C2000ware 5.02 and checked against the contents of C2000ware 4.01. There were a few items missing in 4.01, but the absent files look unimportant. So it appears that Windows security was probably not to blame for what looked like missing project files. When I imported the adc_ex2_soc_pwm project from v4.01, I was unable to see any of the .projectspec files in CPU folder in the project import window. But I chose the CPU folder anyway, and the full list of projects to import did appear.

    I created a parallel source file adcB5_ex2_soc_pwm.c to read ADCB5. I ran both the A0 and B5 versions. In both cases, the adcBResults buffer reads 4095 counts for all 256 data samples. Success!. Thanks for your help. I will apply this method to my client's software