SAADC sampling at different rates, but not simultaneously

OK, I'm working with the nRF52832 and NCS V2.6.0, and I have two different actions I need to complete at various times with the SAADC:

  1. Every ~ 3 seconds, I need to sample one ADC input (called "RMS Voltage") for 32 samples, at 312usec between each sample (I'm basically taking 32 samples of a 1/2 cycle of the 50Hz AC voltage and using that to calculate RMS voltage and do an FFT on the sampled waveform to get an idea of harmonics present on the supply).  I only need to do this measurement once every 3 seconds, so am only in this mode for 10msec every 3 sec, as this is the time it will take to get my 32 samples
  2. For the remaining time, have the SAADC sampling at maximum rate (I think this is something like 200kHz) and checking a different ADC input (called "LIMIT") to see if it is above or below limits.  I want to do this for all the time that I'm not doing the first part (so, the remaining 2.99 seconds of each 3 second cycle)

I'm just trying to get a picture of the best way of approaching this, before I spend a heap of time going down a path that isn't going to work.

Two options I'm considering are:

1. For the RMS voltage measurement, initialise the SAADC in simple non-blocking mode, then trigger the sampling using a counter and a call to nrfx_saadc_mode_trigger each time the counter callback is called (I'm actually doing it this way successfully at the moment, but haven't implemented the second part of what I need to do).  Then, when this is done, reconfigure the SAADC in advanced non-blocking mode, with the limits enabled for the LIMIT ADC input, and a buffer to store all the results its accumulating, and set it off at maximum sampling rate, using PPI to trigger the sampling to keep it going.  Then, when I come back around to the time I want to check the RMS voltage, reconfigure the SAADC back to its original setting.  Then I just cycle around this process indefinitely, switching from one configuration to the next and back again

2. Set everything up in the advanced non-blocking mode, and have the sampling being done at maximum speed on both ADC inputs simultaneously.  I'll only have the limits set and enabled for the LIMIT ADC input, and not the RMS voltage input.  Then (and I'm not sure how this would work), when it comes to doing the RMS voltage measurement, I use my 312usec counter to grab a result for the RMS Voltage ADC channel from the buffer.

There are pros and cons to both approaches as I see it:

  • The first one I can control the RMS Voltage sampling rate much more accurately, but I have to configure and reconfigure the saadc each time I want to do one measurement or the other.
  • The second one may be easier to set up and get working, but there is potential for my 312usec period to not be that accurate.  If a sample takes 10usec to aquire and convert, then I'm realistically looking at a time between samples of either 310usec or 320usec.  Not sure this will have a massive impact on the accuracy of my RMS voltage measurement to be honest.  But then I'm not sure how I identify that particular sample in the buffer that I want to use when my counter expires.  Basically, I'm not sure how the buffers are all configured in advanced mode with multiple channels (I've been looking at the advanced non-blocking with internal timer example, and its not clear from that how I expand things to cover more than one channel being sampled) and how I would know which sample in the buffer was the one at my 312usec (or, 310usec realistically) sample period.

Can anyone that's more knowledgeable about the SAADC and nrfx drivers give me a bit of guidance on which is the easiet of the two options to implement, and how I might go about setting things up?

Regards,

Mike

Parents
  • My first comment is that working with a half-cycle of an AC signal seems problematic, at least to me. Signals with frequency near or below the bandwidth of the window you've selected are not easy to analyze with FFT. Something like 5 or 6 cycles would give ~0.1 s of data to work with, and more accurate determination of the fundamental for comparison with the harmonics. 

    My second comment is that it's not clear to me that you're taking advantage of the hardware's ability to sample all the channels into a buffer using a sequence, and unpack after during processing. Sampling at 200 kHz will be much faster and noisier than you want for the "RMS Voltage" input, but you can do the averaging in software. You might find this code I wrote helpful, which does something similar, or at least related. I think we're using different drivers, however.

Reply
  • My first comment is that working with a half-cycle of an AC signal seems problematic, at least to me. Signals with frequency near or below the bandwidth of the window you've selected are not easy to analyze with FFT. Something like 5 or 6 cycles would give ~0.1 s of data to work with, and more accurate determination of the fundamental for comparison with the harmonics. 

    My second comment is that it's not clear to me that you're taking advantage of the hardware's ability to sample all the channels into a buffer using a sequence, and unpack after during processing. Sampling at 200 kHz will be much faster and noisier than you want for the "RMS Voltage" input, but you can do the averaging in software. You might find this code I wrote helpful, which does something similar, or at least related. I think we're using different drivers, however.

Children
No Data
Related