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.

MSPM0C1104: Timer PWM & ADC interrupt not working.

Part Number: MSPM0C1104

Dear Sir,

 

We are doing coding for the PWM change ,with ADC variation

Code is attached bellow.

Tried debug with ADC interrupt enable , timer interrupt is not working.

But when we disable ADC interrupt ,timer interrupt starts working.

Please communicate if any change required.

 

 

#include "ti_msp_dl_config.h"

#define PWM_PERIOD_UPDATE_CNT (10U)

const uint32_t period = 1599;
const uint32_t gDutyVal[3]   = {799, 499, 49};

volatile uint32_t gIndex;
volatile uint32_t gUpdateCnt;

volatile bool gCheckADC;
volatile uint16_t gAdcResult;
volatile int16_t gADCOffset;

int main(void)
{
    SYSCFG_DL_init();

     /* Get calibrated ADC offset - workaround for ADC_ERR_09 */
    gADCOffset =
        DL_ADC12_getADCOffsetCalibration(ADC12_0_ADCMEM_0_REF_VOLTAGE_V);

    gIndex = 0;
    gUpdateCnt = PWM_PERIOD_UPDATE_CNT;

    NVIC_EnableIRQ(PWM_0_INST_INT_IRQN);
    DL_TimerA_startCounter(PWM_0_INST);

    //NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN);

    gCheckADC = false;

    
 DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN |
        GPIO_LEDS_USER_TEST_PIN);

    while (1)
    {   
         DL_ADC12_startConversion(ADC12_0_INST);

        while (false == gCheckADC) {
            __WFE();
        }

        gAdcResult = DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0);

        /* Apply calibrated ADC offset - workaround for ADC_ERR_09 */
        int16_t adcRaw = (int16_t) gAdcResult + gADCOffset;
        if (adcRaw < 0) {
            adcRaw = 0;
        }
        if (adcRaw > 4095) {
            adcRaw = 4095;
        }
        gAdcResult = (uint16_t) adcRaw;
      // gCheckADC = false;
        DL_ADC12_enableConversions(ADC12_0_INST);

      //
       // __WFI();
    }
}

void PWM_0_INST_IRQHandler(void)
{
    switch (DL_TimerA_getPendingInterrupt(PWM_0_INST))
    {
        case DL_TIMERA_IIDX_CC0_DN:
               

        if (gAdcResult > 0x00 & gAdcResult <0x64 )   // 0 to 100
          {
            gIndex = 0;
          } 
        else if(gAdcResult > 0x64 & gAdcResult < 0xc8)  // 100 to 200
          {
            gIndex = 1;
          }
        else if(gAdcResult > 0xc8 & gAdcResult < 0xff)  // 200 to 300
         {
         gIndex = 2;
         }           
             

        DL_TimerA_setLoadValue(PWM_0_INST, period);
        DL_TimerA_setCaptureCompareValue(PWM_0_INST, gDutyVal[gIndex],
                    DL_TIMERA_CAPTURE_COMPARE_0_INDEX);                        
                          gCheckADC = false;

        default:
        break;
    }
}

void ADC12_0_INST_IRQHandler(void)
{
    switch (DL_ADC12_getPendingInterrupt(ADC12_0_INST))
    {
        case DL_ADC12_IIDX_MEM0_RESULT_LOADED:
            gAdcResult =  DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0);
            gCheckADC = true;
            DL_ADC12_startConversion(ADC12_0_INST);
            break;

        default:
            break;
    }
}

  • Hi Seema,

    The reason why the Timer interrupt handler never works when the ADC interrupt handler is enabled is because the ADC interrupt handler results in infinite ADC conversions. Move the DL_ADC12_startConversion function call in the ISR where the DL_ADC12_enableConversions function call is in main (you shouldn't need to call this here).

    In your PWM interrupt handler, you have several issues. You if/else statements should have && rather than &. You are also missing the break; statement for the first case.

    Best,

    Owen