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.

MSP430I2041: How to get continuous conversion result sets without interrupts

Part Number: MSP430I2041
Other Parts Discussed in Thread: MSP430AFE253, MSP430I2040

I have an MSP430i2041 board using the first 3 A/D channels, with
the 4th channel's inputs shorted together and grounded.

I need a simultaneous sample from all three channels 5000 times
per second, so I am constrained to use Oversampling Ratio 32.
This results in 8000 sample-set results per second. This is
fine with me, because I actually WANT to sample faster than I use
without averaging. (Yes, this is unusual, but I want to do this
to be less susceptible to periodic noise.)

What I DON'T want to do is suffer an interrupt for each A/D sample
set. I want the ONLY interrupt in my system to be the periodic
timer that tells me to return a sample every 1/5000th of a second.

How to do this? One surefire way would be to start a single A/D
conversion (on the group of three channels) every 1/5000th of a
second and then just poll for the IFG bit on the Master Channel
and then read and report the results (via UART). This would
introduce a latency of 125 microseconds (1/8000th of a second)
waiting for the A/D conversion but I could live with that.

A better way might be to run continuous conversions on the A/D
converter, and just "grab" a sample set every 1/5000th of a
second. The problem with this is that I cannot tell from the
documentation how to GUARANTEE that I get a simultaneous set
of three samples every time (short of suffering an interrupt
and reading/storing the samples 8000 times per second, and
locking out interrupts 5000 times per second while I read the
stored conversion from memory). I see a pathological scenario
where the A/D converter updates one of the SD24MEMx result
registers WHILE I am trying to read the last SET of results.

Since Plan A above really is surefire, that's what I'm going to
implement and just suffer the 125 uS latency. However, I thought
I'd run this by y'all to gather some opinions.

-eNick

  • Hello Nick,

    The MSP430i2041 works well when sampling continuously. One of the advantages of this mode is that the decimation filter stays full whereas when triggering the SD ADC module via software, the decimation filter won't be full which impacts the accuracy. Since you only need three ADC channels, have you considered the MSP430AFE253? Its clocking structure for the SD ADC should allow you to configure a 5kHz sampling frequency that can run continuously. This would be easier to accomplish and perhaps even more accurate (higher OSR?) than using software triggering on MSP430i2041. By the way, is your 5kHz sampling frequency a hard requirement?

    Regards,

    James

  • >The MSP430i2041 works well when sampling continuously. One of the
    >advantages of this mode is that the decimation filter stays full

    A very good point, sir.


    >Since you only need three ADC channels, have you considered the
    >MSP430AFE253?

    I looked at the 'AFE and it mostly just seems older, slower, and
    more expensive. :-)


    >Its clocking structure for the SD ADC should allow you to configure
    >a 5kHz sampling frequency that can run continuously.

    As I mentioned before, we WANT to return results at a frequency
    that is different from the sample frequency (and not by an integer
    amount) to try to tune out periodic noise. (I haven't actually tried
    this before, so it could turn out to be a bust.) Neither of these
    chips has near enough horsepower to be doing any significant arithmetic
    on the samples 5000 times per second.

    I should note that the A#1 reason for selecting the i20x0 chip is
    the ability of its A/D converter to measure differential inputs that
    can go below AVSS. I don't know of any other manufacturer whose A/Ds
    can do that! We know from experience that having to bias the inputs
    to obtain such true bipolar behavior is HIGHLY PROBLEMATIC (particularly
    where circuit board ground planes are concerned).


    >is your 5kHz sampling frequency a hard requirement?

    Yeah, pretty much. We are replacing an existing device that returns
    samples at approximately that rate.


    James, I like your point about the decimation filter staying full,
    and you have changed my mind. I now plan to spend a microsecond or
    so 8000 times per second eating an interrupt where I will simply
    grab and store the latest set of conversion results. Another
    interrupt 5000 times per second will tell me to grab the results from
    memory (with interrupts locked out) and report them via UART. The
    A/D conversion interrupts will add a microsecond or so of jitter to
    my sample report packet rate, but I can live with that.

    Thank you very much for your ideas, James. I will close this thread
    after waiting one more day to see if anyone else wants to weigh in.

    -eNick

  • That statement about me closing this thread by now is no longer
    operative. :-)
    I have tried the interrupt method, and I am getting strange bahavior.
    Specifically, I am running the A/D converter continuously, using OSR_32
    and getting an A/D interrupt every 31.4 microseconds, and I expected
    an interrupt every 128 uS. Can anyone explain why I am getting the
    interrupts so often? My code is shown below:


    //Initialize the A/D converter
    SD24CTL = SD24REFS; //use Internal Voltage-Reference
    SD24CCTL0 |= SD24GRP | SD24DF | SD24OSR_32; //Channel #0 is grouped with the next channel, and 2s-complement
    SD24CCTL1 |= SD24GRP | SD24DF | SD24OSR_32; //Channel #1 is grouped with the next channel, and 2s-complement
    SD24CCTL2 |= SD24DF | SD24OSR_32; //Channel #2 is the Master-Channel, and 2s-complement
    SD24CCTL2 |= SD24IE; //interrupt-enable
    SD24CCTL2 |= SD24SC; //start A/D conversions (will run continuously)


    #pragma vector=SD24_VECTOR
    __interrupt void SD24_ISR(void)
    {
    TMP_INDICATOR_PORT |= TMP_INDICATOR_BITP; //turn the Temporary Indicator signal ON

    SACount16 = SD24MEM0; //fetch the 16-bit result from Channel #0
    TVCount16 = SD24MEM1; //fetch the 16-bit result from Channel #1
    BVCount16 = SD24MEM2; //fetch the 16-bit result from Channel #2

    TMP_INDICATOR_PORT &= ~TMP_INDICATOR_BITP; //turn the Temporary Indicator signal OFF
    }


    Since I am having trouble with the interrupt solution, and therefore may
    have to resort to my original plan, I would like to note that my original
    question in this thread was never actually answered. Specifically, none
    of the documentation states that an overflow condition with a group of
    A/D channels is an *atomic* operation. CAN a 3-channel simultaneous
    overflow be INTERRUPTED by software trying to read three SD24MEMx registers?
    I need three SIMULTANEOUS conversion results, even if they happen to be
    stale. Note that locking out interrupts while the software tries to fetch
    three SD24MEMx results would not help, becauce the overflow operation is
    performed by the A/D HARDWARE. I need to know if the hardware overflow
    operation on a group of channels is atomic or not. I'm hoping that TI
    will GUARANTEE that the overflow is atomic. :-)

    -eNick

  • The OSR field is a divisor, so OSR=32 means a period of (32/1024000)=31.25 usec. With OSR=128 it's (128/1024000)=125 usec, which sounds more or less like what you're looking for.

    I've never seen a guarantee that all the MEM registers in a group are updated simultaneously. It's presumably "pretty close" but for all I know there's a serialization in the Verilog somewhere that throws it off by a microsecond or so. I do believe the IFGs, though.

    If the plan is to always pick up the samples (that wasn't true in your original plan) you could use the OVIFG as an indicator -- read them all (per SD24IFG), then see if any of the OVIFGs is set. If so, you lost the race. (This would mean you're extremely late in the ADC cycle, and could be coded as "highly unlikely".)

    [Edit: Fixed typo]

  • >The OSR field is a divisor, so OSR=32 means a period of (32/1024000)=31.5 usec.

    I cannot even tell you where I got the idea that OSR_32 should take 125 uS, but
    I thank you for setting me straight on that.


    >I've never seen a guarantee that all the MEM registers in a group are updated
    >simultaneously.

    Me either. However, all the TI interrupt code examples assume that the
    results for a group of channels are simultaneously valid. I'm willing to
    trust TI on that, because the overhead of the interrupt process itself would
    surely give the A/D hardware time to update all registers in the group. There
    is no TI example code for letting the conversions overflow before reading them.


    >If the plan is to always pick up the samples (that wasn't true in your
    >original plan) you could use the OVIFG as an indicator -- read them all
    >(per SD24IFG), then see if any of the OVIFGs is set. If so, you lost
    >the race.

    Yes, my original plan was to grab the overflowed samples when needed.
    However, I now plan to suffer the interrupt 8000 times per second so
    that I can grab the completed sample sets, KNOWING that the A/D hardware
    will never have seen an overflow condition. These interrupts will cost me
    about 2 uS each, so they will introduce up to 2uS of jitter in the samples
    I transmit 5000 times per second. 5000 samples/second == 200 uS/sample,
    so the 2 uS of jitter is 1% which I think I can live with.

    Thank you very much for your input, Bruce. I have a plan now, and I
    will just go ahead and close this thread.

    -eNick

  • Very interesting. I have a similar case in which I need to digitize a 5 KHz signal (exactly) also on the three channels synchronously, with MSP430i2040. Mi concern is with what is described in Fig 13-5 of SLAU335 (page 330): Digital Filter Step Response and Conversion Points Digital Filter Output:: "For step changes at the input after start of conversion, a settling time must be allowed before a valid conversion result is available  ...  An asynchronous step requires four conversions before valid data is available"

    I understand from this text and the figure that each conversion will have a memory of the previous 2 or 3 conversion. which may be negligible for slow varying signals but at 5 kHz may compress and/or distort the readings bigly.

    Is there something I do not understand here? I also went through search of SAR parts but found out (the ones I looked at at least) that they use a multiplexer and single ADC - not good.

    Or: is there a way to compensate, knowing the signal is a 5 kHz sine and some odd harmonics?

    Using SD24INTDLY seems useless since the signal keeps moving...

    Mac

  • Hi Mac,

    Marco Caceci74 said:

    I understand from this text and the figure that each conversion will have a memory of the previous 2 or 3 conversion. which may be negligible for slow varying signals but at 5 kHz may compress and/or distort the readings bigly.

    Is there something I do not understand here?

    I think your understanding is correct. For sampling a 5 kHz signal, you'd need at least a 10 kHz sampling frequency. To digitize it better, you'd need a much higher sampling rate. SD ADCs offer higher resolution but lower sampling rates. The MSP430i20xx devices can sample up to 32 kHz using the lowest supported OSR value of 32. As you can see from the figure below found in the i20xx datasheet, the higher the sampling rate (lower OSR), the lower the SINAD performance too.

    Our MSP430F67xxA family of devices may offer more flexibility for sampling this signal but they are larger and higher cost.

    Regards,

    James

  • Hi Mac, and thanks for your response. I didn't see it in a timely fashion,
    because I did not get an email about it. I assume that is because I had
    closed this thread (or at least thought I did). Maybe the sysop decided to
    keep the thread open for a while; dunno because I am new to this the forums.
    Anyway, this is my first brush with sigma-delta A/D converters, so don't
    believe anything I say about them. :-)
    My understanding is that SD24INTDLY is only for when you WANT to introduce
    a delay between channels (which you apparently don't).


    >I also went through search of SAR parts but found out (the ones I looked
    at at least) that they use a multiplexer and single ADC - not good.

    FWIW, there are MCUs available that have multiple (at least two) entirely
    separate SAR A/D converters, so you could get high-speed SAR that way by
    triggering them simultaneously. Note that these MCUs ain't likely to be cheap.

    -eNick

  • SD24PREx introduces a delay (time skew) between channels (in a group).

    SD24INTDLY delays presenting the first sample until the 4th output from the filter. This makes sure the filter is fully charged. It is in some sense a convenience, since you could get the same effect by having your software throw away the first 3 samples it gets.

    My observation was that the INTDLY was rather important -- those first 3 samples, while the filter was still settling, were rather ratty. Sigma-delta ADCs really "like" to be run continuously, but yeah if you only want 1sps you don't really want to run it all the time.

**Attention** This is a public forum