Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Interrupt controlled measurement of analogue values with TEENSY 3.6, FFT

  1. #1
    Junior Member
    Join Date
    Mar 2018
    Posts
    3

    Interrupt controlled measurement of analogue values with TEENSY 3.6, FFT

    Hey guys,
    I'm an absolute newbie.
    I would like to solve the following problem:
    From a technical process I get 10 different analogue values of pressure sensors.
    The expected frequency of each signal is between 1 to 300 Hz.
    I need to write this values in arrays (one per channel) with specific sample rate (about 1kHz = 1 point per millisecond; length of the array:8000 -> 8000 values in 8 seconds).
    Are the two ADCs fast enough for the desired sample rate of 1 kHz per channel (10 channels)?
    How coult I realize the sampling per time interrupt?
    Does anyone have experience with time controlled recording of analogue values?
    The next step is to make a FFT analysis from each of the 10 arrays.
    I need the main frequency, the maximum amplitude and mean value of each channel.
    I would like to transfer these values via CAN bus to a PLC (SIEMENS).
    Are there good libraries for coupling via CAN bus?
    Whitch libraries I could use for FFT analysis?
    Is the TEENSY 3.6 fast enough to realize my project?

    Where I can find literature and examples to realize spectral analysis with the TEENSY?

    Thank you in advance.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,687
    Wow, many questions in 1 message. Here's some quick answers.

    Quote Originally Posted by GP71 View Post
    Are the two ADCs fast enough for the desired sample rate of 1 kHz per channel (10 channels)?
    Yes. The simplest way with analogRead() takes ~10 us per reading. Plenty fast enough.

    Of course more advanced and efficient ways involving DMA and non-blocking reads are possible. Look at the ADC lib. The Teensy Audio Library does this too, though it's designed for audio rather than your signals. Still might be useful for code samples if you *really* want to dig into the low-level programming. But for this speed, you probably won't need that sort of code.

    How coult I realize the sampling per time interrupt?
    A loop checking elapsedMicros might be simplest. IntervalTimer gives excellent performance, but adds the complexity of interrupts.

    https://www.pjrc.com/teensy/td_timin...pedMillis.html

    https://www.pjrc.com/teensy/td_timin...rvalTimer.html

    Does anyone have experience with time controlled recording of analogue values?
    Yes, many people do. It's been discussed over and over on this forum with lots of success stories. Maybe you can find some by searching?

    The next step is to make a FFT analysis from each of the 10 arrays.
    I need the main frequency, the maximum amplitude and mean value of each channel.
    FFT gives you "bins", but not a specific frequency number. Generally a window scaling needs to be applied, unless your signal is perfectly periodic and exactly some multiple of the FFT length. Window scaling prevents spectral leakage, but also tends to decrease spectral resolution. The audio library tutorial has a lengthy explanation of these FFT details.

    Getting what you want from FFT might not be as easy as it first seems....

    I would like to transfer these values via CAN bus to a PLC (SIEMENS).
    Are there good libraries for coupling via CAN bus?
    FlexCAN

    A transceiver chip is needed between the CAN RX & TX signals on Teensy and the actual CAN bus.


    Whitch libraries I could use for FFT analysis?
    arm_math.h

    It's used within the Audio library, so maybe look in that code for an example.

    Is the TEENSY 3.6 fast enough to realize my project?
    Very likely yes. Certainly 10 kHz acquisition rate is doable.


    Where I can find literature and examples to realize spectral analysis with the TEENSY?
    Perhaps look at the YIN algorithm, which is used in "notefreq" in the audio library. It may be a better fit for your needs than FFT. Maybe?

  3. #3
    Junior Member
    Join Date
    Mar 2018
    Posts
    3
    Hallo Mister Stoffregen.
    Thank you for accepting my problem.
    It's very kind of you to answer me so quickly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •