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.

CCS/MSP430F5529: ADC12 on A12

Part Number: MSP430F5529

Tool/software: Code Composer Studio

I am having a weird issue getting a value using the ADC12. I want to measure a voltage on A12.   The voltage should read 0.89v but the code I am using does not appear to be reading it.  It just gets a 0.0  A little help would be great.

Thanks,

-----------

float voltage;

float bat_volts(void)
{
    ADC12CTL0 = ADC12SHT02 + ADC12ON;           // 16 samples - Sampling time, ADC12 on
    ADC12CTL1 = ADC12SHP;                       // Use sampling timer
    ADC12MCTL0 = ADC12INCH_12 + ADC12EOS;       // select A12 as the source input 
    ADC12IE = 0x01;                             // enable interrupt
    ADC12CTL0 = ADC12ENC;                       // enable conversion
    P7SEL |= BIT0;                              // Select ADC for battery voltage measurement

    int voltctl = 1000;                         // Reading Timer to get voltage reading...then abandon
    while (voltctl > 0)
    {
        ADC12CTL0 |= ADC12SC;                   // Sampling and conversion start
        voltctl--;                              // decrement the reading timer
        __bis_SR_register(LPM0_bits + GIE);     // LPM0, ADC12_ISR will force exit
    }    
    if(voltctl = 0)
    {
        voltage = 99.9;                // if this code times out change the voltage to 99.9 to indicate an error
    }
    else
    {
        __no_operation();                       // debugging
    }
    return voltage;
}
//
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch(__even_in_range(ADC12IV,34))
  {
  case  0: break;                           // Vector  0:  No interrupt
  case  2: break;                           // Vector  2:  ADC overflow
  case  4: break;                           // Vector  4:  ADC timing overflow
  case  6: break;                           // Vector  6:  ADC12IFG0
  case  8: break;                           // Vector  8:  ADC12IFG1
  case 10: break;                           // Vector 10:  ADC12IFG2
  case 12: break;                           // Vector 12:  ADC12IFG3
  case 14: break;                           // Vector 14:  ADC12IFG4
  case 16: break;                           // Vector 16:  ADC12IFG5
  case 18: break;                           // Vector 18:  ADC12IFG6
  case 20: break;                           // Vector 20:  ADC12IFG7
  case 22: break;                           // Vector 22:  ADC12IFG8
  case 24: break;                           // Vector 24:  ADC12IFG9
  case 26: break;                           // Vector 26:  ADC12IFG10
  case 28: break;                           // Vector 28:  ADC12IFG11
  case 30:                                  // Vector 30:  ADC12IFG12
           voltage = ADC12MEM12;                   // Move results from A12, IFG is cleared
           __bic_SR_register_on_exit(LPM4_bits);   // Exit active CPU
           break;
  case 32: break;                           // Vector 32:  ADC12IFG13
  case 34: break;                           // Vector 34:  ADC12IFG14
  default: break;
  }
}

  • Hi Chris,

    When setting the ADC12ENC bit in the ADC12CTL0 register you are overwriting the previous settings:

    ADC12CTL0 = ADC12ENC;

    The correct way to enable ADC conversions is with an |= operation:

    ADC12CTL0 |= ADC12ENC;

    Best regards, 
    Caleb Overbay

  • Thanks Caleb,

    This is helpful.  But I still do not see any data.  Today, I am going to attempt to try this code on a launchpad so as to remove any hardware variables. I will then try an example code and modify it until I see what is going on.    

    I would have thought the user manul would provide enough informationso I can set up any type of ADC but is just describes the registers and provides no clarity. 

  • That is why the code examples are there. The driverLib manual does give an example:

    /* Initializing ADC (MCLK/1/4) */
    MAP_ADC14_enableModule();
    MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_4,
    0);
    /* Configuring GPIOs (5.5 A0) */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5,
    GPIO_TERTIARY_MODULE_FUNCTION);
    /* Configuring ADC Memory */
    MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true);
    MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,
    ADC_INPUT_A0, false);
    /* Configuring Sample Timer */
    MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION);
    /* Enabling/Toggling Conversion */
    MAP_ADC14_enableConversion();
    MAP_ADC14_toggleConversionTrigger();
    
    /* ADC Interrupt Handler. This handler is called whenever there is a conversion
    * that is finished for ADC_MEM0.
    */
    void ADC14_IRQHandler(void)
    {
    uint64_t status = MAP_ADC14_getEnabledInterruptStatus();
    MAP_ADC14_clearInterruptFlag(status);
    if (ADC_INT0 & status)
    {
    curADCResult = MAP_ADC14_getResult(ADC_MEM0);
    normalizedADCRes = (curADCResult * 3.3) / 16384;
    MAP_ADC14_toggleConversionTrigger();
    }
    }

**Attention** This is a public forum