ADC library, with support for Teensy 4, 3.x, and LC

When using averaging. Is it possible to average using floating point math into a float or double variable?

Also is it possible in stead of averaging to use median?

I could do it in my program but wondering if it can be done with the library?
 
The internal (hardware) average only does a mean, not median. It outputs an integer as well, so you have to use software for any other statistics.
 
Hi, How fast could it go with DMA? Do you have an example using a single channel with DMA for the Teensy4.0 ?

Thank you
 
Thank you. I found them.

So far, I have a loop rreading 12 bits at 1usec/sample by using the following in place of analogRead(pin) in your speed test. I checked your source and found most of it is inlined, so that was very nice - and convenient.

Code:
inline int fastAnalogRead( uint8_t pin ) {
  adc->adc0->startReadFast(pin);
  while ( adc->adc0->isConverting() );
  return adc->adc0->readSingle();
}

What I hope to do is run the ADC by DMA sychronized to a 1MHz clock, and start the dma within 1 clock period from an isr tied to a digital pin.
 
Last edited:
Just helping - not code written here ...

Check out this in the install directory there may be better ways to capture: {local install}\hardware\teensy\avr\libraries\ADC\docs\Teensy_4_html\index.html

Wow hat path really is unique for IDE 2: "C:\Users\{YOU}\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.57.1\libraries\ADC\docs\Teensy_4_html\index.html"

Also there are other examples that show triggering with interrupt.

One non-blocking way to start it an interrupt could use:
Code:
        /////////////// NON-BLOCKING CONVERSION METHODS //////////////

        //! Starts an analog measurement on the pin and enables interrupts.
        /** It returns immediately, get value with readSingle().
        *   If this function interrupts a measurement, it stores the settings in adc_config
        *   \param pin can be any of the analog pins
        *   \param adc_num ADC_X ADC module
        *   \return true if the pin is valid, false otherwise.
        */
        bool startSingleRead(uint8_t pin, int8_t adc_num = -1);

Then just read the prior value ( that will be completed if running ADC fast enough ) before next startSingleRead()
 
Thank you, I saw that. I meant to track down the start time code and see what the limits are on the frequency.
 
@Pedvide Hi Pedro, I had opportunity to really look through your ADC code. Nice job, really. Thank you.
 
Im new to the ADC peripheral of the Teensy 4.x and I'd like to measure three analog inputs: two are differential voltage signal and one is a current signal from an Current Transformer.

I would like to sample all three inputs at the same time, at a rate of 250 to 500Khz if possible, and fill a buffer for each pin (I'll determine adequate buffer size later on)

Once the buffers arefull, I need the sampling to stop transferring unlit triggered again by software.

I've taken a look at the examples, and while I saw the DMA examples and kind of understand them, I'm not sure how to sample each pin into it's own buffer.

Could someone help me with a basic sketch?


Thanks
 
Back
Top