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;
}
}