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.

Move ADC10-prog from g2231 to g2553 (ADC10 seem to hang)

Other Parts Discussed in Thread: MSP430F2013


Wanted to move a ADC10-prog that read p1.5 from g2231  to g2553 but it seem to not read.
Using debugger it seem to hang waiting "adc to finish reading" "while (!(ADC10CTL0 & ADC10IFG));"
Asume that the use of ADC10CTL0 and ADC10IGF is different. Appresiate if someone could explain the dif and where to find the info. Have looked in slau144i. Are there other doc that explain the dif.

This is part of the prog to  ((c) B. Nollmeyer 01/2011 #### ---- */
void main (void)
{
    WDTCTL = WDTPW + WDTHOLD;                                     // Stop watchdog timer
    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;                                         // SMCLK = DCO = 1MHz

// ---- initialise the GPIO's ----
    P1SEL |= TXD;
    P1DIR |= LED1 + LED2 + TXD;                                   // LED1, LED2, TXD as Output
    P1OUT &= ~ (LED1 + LED2);                                     // LED's = OFF

// ---- Soft. UART Timer Setup ----
    CCTL0 = OUT;                                                  // TXD Idle as Mark = '1'
    TACTL = TASSEL_2 + MC_2;                                      // SMCLK, continuous mode

// ---- initialise the ADC ----
    ADC10CTL1 |= INCH_5;                                          // ADC IN @ P1.5
    ADC10CTL0 = SREF_1 + ADC10SHT_2 + REF2_5V + REFON + ADC10ON;  // SHT 16x ADC10CLKs, VREF 2.5V, ADC ON
    ADC10AE0 |= AdcInput;                                         // ADC Input Enable @ P1.5

    __bis_SR_register (GIE);                                      // interrupts enabled

    for (;;) {
        AdcValOut (getAdcValue ());
        __delay_cycles (500000);                                  // ~ 2x per Second
    }
}

// ---- ADC Oversampling 12 BIT, Linearization, ADC Low Pass Filter, Offset + Gain Compensation ----

uint16_t getAdcValue (void)
{
    uint16_t AvgCount = 0, measVal = 0;
    uint32_t AvgSum = 0;

    for (AvgCount = 0; AvgCount < 1024; AvgCount ++) {
        ADC10CTL0 &= ~ADC10IFG;
        ADC10CTL0 |= ENC + ADC10SC;                               // Start the ADC conversion
        while (!(ADC10CTL0 & ADC10IFG));                          // ADC busy ?
        AvgSum += ADC10MEM;                                       // Build an ADC average
    }
    measVal = ((((AvgSum >> 8) * Factor) + Offset) >> 16);        // Scale the ADC -> 12 BIT

  • Kjell Holen said:
    ---- ADC Oversampling 12 BIT, Linearization,

    Sorry, just sampling the same value more than once is not oversampling. It's only averaging and reduces noise (if any), but does not increase the resolution of the conversion result. You could as well apply a low-pass filter before feeding the signal into the MSP.

    If you, say, read 16 times 0x80, the result of the averaging will still be 0x80 (or 0x200, added and then shifted by 2 bit), even though the 'real' value of  a 12 bit ADC would have been 0x203.

    To get a resolution increase through oversampling, you'll have to overlay the input signal with a periodic (triangle or sinusodial) signal with the same frequency as your base sampling frequency and at least +-1LSB amplitude. So the overlaid signal 'shifts' the sampled value above the next conversion value threshold for some time, increasing the reading for some of the samples.

    About the problem, well, the main differene between 2231 and 2553 is that the 2331 has an USI module and the 2553 has an USCI. I see you setting a TXD bit in main, however, it seems to have no further use, so this is unimportant. Next difference is the availability of a second timer, adn more CCR registers per timer. Well, you use TACTl and CCTL0, but again it isn't used later. I guess these are remains from the software UART once present in the program. Last difference is the comparator. Still nothing that should make a difference.

    However, the code you posted is incomplete. The AdcValOut function and perhaps the rest of the software UART code is missing. And I suspect the problem there.

  • Many thanks for explaining the dif between oversampling and average,  and the dif between 2231 and 2553. Thought I should get more that 10 bit. Will proabely buy a      MSP430F2013 , that should have 16-bit Sigma Delta and 4 ADC and I can use the launchpad for testing.

  • Well, I suggest going for an MSP with an ADC12 then. It is much easier to handle than the SD16 and offers different references. However, I guess there is no DIL-cased MSP with ADC12, even though you can use the LaunchPad to program most MSPs with SBW protocol by wiring the three lines (GND, SBWTCK, SBWDIO) to the target board. (short, equal length wires!)

**Attention** This is a public forum