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

Thread: ADC with external sync source

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Posts
    4

    ADC with external sync source

    The example for ADC with external signal https://www.pjrc.com/teensy/adc.html seems to be for Teensy 1.0 and 2.0.
    Are there examples for Teensy 3.x?

    The ADC library by pedvide does not seem to have option to acquire signals with external synchronization either.

    I am looking for some advice how to go about working through the documentation and implementing externally triggered ADC.

    My goal is to improve the code examples for the C12880ma spectrometer which provides a trigger signal for reading each spectral channel. The example software for that micro spectrometer does not take advantage of trigger signals. Ideally the ADC runs at >=200k/S/sec.

    Urs Utzinger

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,329
    The simplest way is probably to write an interrupt handler to trigger a ADC conversion and to attach this to a GPIO pin interrupt. I’d try that out first to see if this meets your requirements in terms of latency and precision.

  3. #3
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    Quote Originally Posted by Theremingenieur View Post
    The simplest way is probably to write an interrupt handler to trigger a ADC conversion and to attach this to a GPIO pin interrupt. Id try that out first to see if this meets your requirements in terms of latency and precision.
    I am looking at https://www.pjrc.com/teensy/K20P64M72SF1RM.pdf and it says in chapter "31.3.6 Status and Control Register 2 (ADCx_SC2)" there is a hardware trigger option.

    The Audio library for the teensy uses the PDB (timer) as hardware trigger source for 41kHz sampling and maybe extending the ADC library to use hardware trigger similar to audio library would be most useful.

    I understand there is also DMA functionality and one can enable an interrupt that handles a ring buffer after each conversion.

    I understand that is not the fastest way to go about this but it appears to me it would result in minimal latency and functionality similar to something like the National Instruments USB 6003 device that costs about $500.-.

  4. #4
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,876
    I'm not sure if all of the pieces will work together, but given that audio lib uses the PDB to trigger ADC. There is also a way to drive the PDB with an external trigger, see
    https://forum.pjrc.com/threads/24492...l=1#post128046
    I think the audio lib also utilizes the DMA half-full/full interrupts to do DMA ring buffering

  5. #5
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,329
    The DMA ring buffer solution is for sure the most precise and elegant way. But it requires some experience and studying/understanding the source code of the audio lib. That's why I suggested to start with a simple pin interrupt handler to have an immediately working solution which can be refined later.

  6. #6
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,876
    Another obtuse example is triggering ADC from LPTMR which is triggered by an external signal
    https://github.com/manitou48/teensy3...r/adclptmr.ino

  7. #7
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    @manitou Thank you for sharing. I tested your lptmr code and added DMA. The issues I am having is that it looks like I need twice the desired frequency on the lptmr pin. In my setup the external ADC sync signal is generated by the sensor and I can not double its frequency.

  8. #8
    Hi there. Thanks for sharing this information.

  9. #9
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,329
    @nicfaust: Вы украинский бот? Я за вами присматриваю...

  10. #10
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    I added pdb and lptmr external trigger support to ADC library with DMA examples.
    https://github.com/uutzinger/ADC
    lptmr needs to be triggered at twice the sampling frequency
    pdb triggering works at the desired sampling frequency

Posting Permissions

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