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: Variable time for the delay_cycles() function observed.

Part Number: MSPM0C1104

Dear Sir,

 

Please help regarding following concerns for the code hysteresis loop for sensor (ADC).

following code is woking perfectly on the launch pad.But same code when dumped on the 8 pin MCU on the application board found some times working some times not working.

Also delay_cycles (100) is not giving same delay every time.

 

#include "ti_msp_dl_config.h"

volatile bool gCheckADC;
volatile uint16_t gAdcResult;
volatile int16_t gADCOffset;
bool LED = false;
volatile uint16_t gCounterutp;
volatile uint16_t gCounterltp;


int main(void)
{   

    delay_cycles(100);
    SYSCFG_DL_init();
    gCheckADC = false;
    gCounterutp = 0;
    gCounterltp = 0;
    DL_GPIO_setPins(GPIO_GRP_0_PORT, GPIO_GRP_0_PIN_0_PIN);
    gCounterltp = 0;

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

    NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN);

    while (1)
     {
      DL_ADC12_startConversion(ADC12_0_INST);

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

      gAdcResult = DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0);

      if (gAdcResult < 0x1E) //96mv  //30 ADC value
      {
       
        if (gCounterutp == 0x03) {
          DL_GPIO_clearPins(GPIO_GRP_0_PORT, GPIO_GRP_0_PIN_0_PIN); // LAMP on
          DL_GPIO_clearPins(GPIO_GRP_0_PORT, GPIO_GRP_0_PIN_0_PIN); // LAMP on
          gCounterutp = 0;
        } else {
          delay_cycles(12000000 * 8); // 12000000 //1505000  // 2sec dealay
          gCounterltp = 0;
          gCounterutp++;
        } 
        gCheckADC = false;
        DL_ADC12_enableConversions(ADC12_0_INST);
      }

else {
        if (gAdcResult > 0xE6) // 25//37D//740mv  230 adc value
        {
          if (gCounterltp == 0x03) {
            DL_GPIO_setPins(GPIO_GRP_0_PORT, GPIO_GRP_0_PIN_0_PIN);
            DL_GPIO_setPins(GPIO_GRP_0_PORT, GPIO_GRP_0_PIN_0_PIN);
            gCounterltp = 0;

          } else {
            delay_cycles(12000000 * 8); // 12000000 //1505000
            gCounterutp = 0;
            gCounterltp++;
          }
          gCheckADC = false;
          DL_ADC12_enableConversions(ADC12_0_INST);
        }
      }
    }
}

void ADC12_0_INST_IRQHandler(void) {
  switch (DL_ADC12_getPendingInterrupt(ADC12_0_INST)) {
  case DL_ADC12_IIDX_MEM0_RESULT_LOADED:
    gCheckADC = true;
    break;
  default:
    break;
  }
}