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.

Simple question about ADC reference voltage

Other Parts Discussed in Thread: MSP430G2231

Hi,

I had a few questions about the ADC in the MSP430G2231 (Launchpad version):

I know the reference voltage can be several different things (1.5v, 2.5v?, some arbitrary voltage that I apply externally to a pin).

My question is:

What are all the different choices for pre-set and non-preset reference voltages?

Can you link me to a tutorial/explanation of how to set each one of the options that are possible?


Thanks in advance,

Kevin

  • Kevin,

     

    The reference voltage is used during the conversion. Look at page 542 of the User's Guide here:

    http://www.ti.com/litv/pdf/slau144h

     

    If you look at the equation, the actual voltage you get is heavily dependant on the voltage provided. When you use an internal reference that's stable (since it's regulated from VCC), then you know waht to expect. If you use VCC, the battery voltage might drop. This is also true when you're using the MSP430 to measure it's own VCC. You need to use a reference and use VCC/2 since VCC/2 is less than 2.5V (so we can capture it in that range of 0 to 2.5V).

    Therefore, you can get more sensitivity if you make your range smaller (by choosing a smaller reference voltage) because the voltage range decreases and the # of steps is the same. So the value for each step (the amount of voltage needed to have a change in the corresponding code) is smaller. Of course there are limits and noise is one of them. If you can tailor your voltage references to the voltage range you'll expect, do so.

    BTW, usually VREF- is chosen as GND. Note it is only from 0V to 1.4V

     

    The datasheet for the part specifies what reference voltages are possible on page 29. It's 1.4V to VCC.

     

    Gustavo

  • Kevin Ting said:
    What are all the different choices for pre-set and non-preset reference voltages?


    First., you decide whether to use an internal or external reference. This can be done using the SREFx bits in ADC10CTL0.
    For external reference, it may not be higher than VCC and not lower than ~1V (see the device datasheet for details/limits).
    If using an internal reference, you need to 1) enable it (REFON bit) and 2) decide whether to use the 1.5V or 2.5V reference (REF2_5V bit). and 3) wait for it to settle (see datasheet for the settling time) before you can start a conversion.

    Kevin Ting said:
    Can you link me to a tutorial/explanation of how to set each one of the options that are possible

    It's a rather simple combination of bits, teh table is in the ADC register description. You don't need a tutorial for this. The ADC10 Operation chapter also tells you how things work, including some assembly samples I think.

  • So for this code, do I just add the REFON bit setting and REF2_5V bit setting?  Do I need to delete any of the lines of code I already have, or change a part of a line so that nothing conflicts?  What I want to do is to set it to internal reference and then set the reference voltage to 2.5 V.  Thanks!!

     

    #include  <msp430g2231.h>

     

    void main(void)

    {

      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

     

      ADC10CTL1 = INCH_7 + SHS_1;               // P1.7, TA1 trigger sample start

      ADC10AE0 = 0x80;                          // P1.7 ADC10 option select

      P1DIR |= 0x01;                            // Set P1.0 to output direction

      TACCTL0 = CCIE;                           // Enable interrupt

      TACCR0 = 32-1;                            // PWM Period

      TACCTL1 = OUTMOD_3;                       // TACCR1 set/reset

      TACCR1 = 2;                               // TACCR1 PWM Duty Cycle

      TACTL = TASSEL_1 + MC_1;                  // ACLK, up mode

      __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3, enable interrupts

    }

     

    // ADC10 interrupt service routine

    #pragma vector=ADC10_VECTOR

    __interrupt void ADC10_ISR(void)

    {

      ADC10CTL0 &= ~ENC;                        // ADC10 disabled

      ADC10CTL0 = 0;                            // ADC10, Vref disabled completely

      P1OUT = 0x00;

      if (ADC10MEM < 0x88)                      // ADC10MEM = A7 > 0.2V?

        //P1OUT &= ~0x01;                         // Clear P1.0 LED off

        P1OUT |= 0x01;

      else

        //P1OUT |= 0x01;                          // Set P1.0 LED on

        P1OUT &= ~0x01;

    }

  • also, for the same code I pasted above, how would I set it so that the reference voltage was VCC?  Which lines do I need to change/delete in order to make the code work without conflicts?

     

    thanks, 

    Kevin

  • In ADC10CTL0 you use the SREFx bits to define which reference to use: VCC, internal or external. and whetehr you want to measure relative to VSS or VeREF-.
    Only if oyu use a mode where VREF+ is used, you need to activate the internal reference and speify whether it shall be 1.5 or 2.5V.

    However, you missed to post the code where you actually configure the ADC10. I guess it is in the timer ISR. So I cannot say what to change adn I don' tknow what's already there.

     

  • oh whoops you are right, here it is:

    so im guessing I just add REF2_5V to the ADC10CTL0 and that will do what I want??

     

    #pragma vector=TIMERA0_VECTOR

    __interrupt void Timer_A(void)

    {

      ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;

      ADC10CTL0 |= ENC;                         // ADC10 enable set

    }

  • Kevin Ting said:
    o im guessing I just add REF2_5V to the ADC10CTL0 and that will do what I want??

    Well, no. At least not exactly.

    Yes, it will activcate 2.5V reference, while REFON alone is activating 1.5V reference.

    However, the reference takes some time to start up (remember, this is a low-power chip, so the whole circuitry is dead if the reference is not used). If you enable it immediately before sampling and deactivate it right after, it will be, well, somewhere, but not on the desired votage. See the datasheet for details and exact timing requirements.

  • Ok so im looking at the datasheet and it says it needs a little bit more than 100 ns for the settling time.  

    How do I code this into my program so I can have a steady reference voltage?  Can I just use the delay function?

    Also will this delay cause problems if I want to take samples every second? (because i assume it would have to convert the voltage to 2.5V everytime the sampling is called)

     

    Thanks so much for your help by the way, 

    Kevin

  • Kevin Ting said:
    says it needs a little bit more than 100 ns for the settling time

    The datasheet says 30µs for 3,6V VCC. Likely more for lower VCC.
    (the 400ns is the load regulation time ).

    If your samples are more than 30µs apart, then it might be an idea of setting up a second timer that fires >30µs before you want to take the sample. In the meantime, the device can stay in low power mode.

    If low power isn't that much of a concern, you can simply activate the reference at the start of main and leave it on all the time. It takes 250µA to 1,1mA, depending on whether you use the reference buffer or not and if then if in highspeed or low speed mode.

    P.s.: you can leave the reference on but the reference buffer off. then the settling time is only 2µs. If you select a sampling time >2µs (on 6MHz ADC clock it is ADC10SHT_2 or _3) then the reference buffer is settled when the sampling time expires and the conversion begins.

    Since the conversion itself takes only 2µs too, it makes no sense returning to LPM when you started the ADC and wait for the ADC10 interrupt. It would be better to wake the main, let main wait for the conversion interrupt flag in a while loop and deactivate the ADC and reference buffer then. Depending on the current MCLK speed, the conversion is maybe already done when the timer ISR returns (4µs are only 4 MCLK cycles on 1MHz)

    Kevin Ting said:
    Can I just use the delay function?

    You can. Yet the delay is in MCLK cycles and therefore dependent of the current MCLK speed. Waiting too long wastes time, waiting a shorter time will fail if you later rise the MCLK speed for more ccalculation power and forget to adjust all the delays you have here and there.

    I always recomment using timers for timings. If you do delays based on a timer tick, you only have to adjust the timer source when you change the system speed, and all timings will adjust autoimatically.

  • Hi Jens-Michael, 

    I have another question about the MSP430's ADC10 capabilities...if my VREF+ is set to internal reference at 2.5 V, what happens if I apply a voltage greater than that to the pin that is being sampled?  

    For example, if my program does something simple such as turn the led ON if the voltage on the pin that is being sampled is greater than 1.2 volts, what happens if I apply 3 volts to that pin?  Does it just not do anything because the ADC10MEM shows overflow?  Or does it actually properly handle that value?

    Thanks so much you are so helpful!!

    -Kevin 

  • If the applied voltage reaches or exceeds the selected reference, the ADC10 will return 0x3FF.

    If the applied voltage is > VCC, current flows through the clamp diodes to VCC. If the current exceeds 2mA, the diodes will eventually melt, causing the pin to be either permanently on VCC level or leving it unprotected. In the latter case, the MSP internals will likely take permanent damage, in the first case, only this pin is permanently damaged.

**Attention** This is a public forum