0
\$\begingroup\$


I am currently attempting to read a value from ADC10MEM and convert it to a usable value to process. However, the value I am receiving (random value) is not what was anticipated (approx. 0.1 volts). The error may be in my conversion from ADC10MEM to my value. Any help is greatly appreciated!


unsigned int value = 0;
double accurateValue = 0;

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD; // Stop WDT
  ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE + REFON;
  /*    
   *    ADC10CTL0:
   * 
   *    ADC10SHT_3  =>  SampleHoldTime: "64 x ADC10CLKs" 
   *    ADC10ON     =>  ADC10:          "ADC10 On/Enable"
   *    ADC10IE     =>  Interrupts:     "ADC10 Interrupt Enabled"
   *    REFON       =>  Internal Ref:   "ADC10 Internal Ref On"
   *    REF2_5V     =>  Ref Volt:       "ADC10 Ref 0: 1.5V" 
   *    
   */


  ADC10AE0 |= 0x01;
  /*
   *    ADC10AE0    =>  Channel:    "P2.0" (board pin 3)
   */

  for (;;)
  {
    ADC10CTL0 |= ENC + ADC10SC;
    /*
     *  ENC     =>  "ADC10 Enable Conversion" 
     *  ADC10SC =>  "ADC10 Start Conversion"
     */

    __bis_SR_register(CPUOFF + GIE);        // LPM0, ADC10_ISR will force exit

    /*
     *  ADC10MEM:
     *  
     *  Conversion:     
     *      
     *  Nadc = 1023 * (Vin - Vr-) / ( Vr+ - Vr- )
     *  
     *  Vin = ( Nadc * (Vr+ - Vr-) / 1023 ) + Vr-
     *  
     *  Assuming Vr- == 0;
     *  
     *  Vin = Nadc * 1.5 / 1023
     *  
     */

    value = ADC10MEM * 15 / 1023; // 15 instead of 1.5 (using integers)

    accurateValue = ( (float)value ) / 10; // actual value (type double)
  }
}

    Additional Requirements

  • The input should be between 0.1 mV and 1 V
\$\endgroup\$
  • 1
    \$\begingroup\$ Bare metal programming requires you to set up everything. I would start with Figure 22-1 on page 535 of the MSP430 family pdf you pointed to. \$\endgroup\$ – st2000 Nov 14 '16 at 1:39
2
\$\begingroup\$

As per the comment on your question, you do need to set up everything, including IO pins, clocking source, connection to peripherals instead of digital IO, etc.

Your startup code would normally run to 10 - 100 lines depending on what you initialise. I always initialise absolutely everything, my startup code is normally around 400 lines or so.

BUT ALSO on the F2274 (as for most of the F2 and F1 series), its very important to make sure you follow the hardware design recommendations, specifically you need the capacitor on the ADC reference voltage that appears externally. If you don't have that cap you get random rubbish in your readings.

\$\endgroup\$
  • \$\begingroup\$ Amended: You need the external cap for ADC12. For ADC10, it seems you do not need it (Refer SLAU144J, F2xx Users Guide, Section 22.2.3. \$\endgroup\$ – quickly_now Apr 10 '17 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.