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

Thread: Simulating a signal and sending to audio shield (T4)

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Posts
    5

    Simulating a signal and sending to audio shield (T4)

    I have an application that simulates physiological signals at approximately 10khz. This works great on the Teensy and I can stream data out through the USB device without a problem to a virtual scope on the host.

    Iíd like to add real DAC output because for teaching itís important to demonstrate how real scopes work. My thought is to up the timer interrupt rate to 11025 and toss the simulated value into a buffer repeated four times and use the Audio Queue interface to push 128 of these samples (every 32 wakeups) as soon as the next buffer is ready. Does this approach seem like it should work?

    If there are DAC options other than the I2S to audio shield for the 4.0/4.1 Iíd of course consider them (SPI is surely fast enough for this app, Iíd assume).

    Thank you!

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,056
    Just use the Teensy audio library, and use 44100, not 11025. But I'm not sure what you mean with "Interrupt rate" - Which interrupt exactly?
    11025 are not enough if you want to use a 10kHz signal. You need much more. Absolute minimum is double the rate of the signal.

    For a "real" DAC, it's easiest just use a Teensy with inbuilt dac.

    Edit: Hm, no even easier is to just use an analog oscillator. Don't know why everything needs a microcontroller these days or needs to be "digital".

  3. #3
    Junior Member
    Join Date
    Sep 2021
    Posts
    5
    Thanks Frank. I have a timer interrupt fire 10 times per ms that is used (to tell my loop) to read some sensors and generate the next update to the simulated output. I then have the digital value of voltage for that time step. I have actually tested the time to drive a MAX11300 DAC using SPI and it seems like itís about 5 microseconds per channel, which would fit inside my 100usec frame time, so thatís probably easiest. Small jitter for the DAC is not a huge deal because the simulation includes noise anyway. If itís close to 10khz thatís fine. (These signals are not pure tones but rather simulated noisy membrane potentials.)

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,180
    Quote Originally Posted by sheinb View Post
    I have a timer interrupt fire 10 times per ms that is used (to tell my loop) to read some sensors and generate the next update to the simulated output.
    That's a real signal from the sensors isn't it? A simulated signal would just be generated programmatically with no reference
    to anything else.

  5. #5
    Junior Member
    Join Date
    Sep 2021
    Posts
    5
    Quote Originally Posted by MarkT View Post
    That's a real signal from the sensors isn't it? A simulated signal would just be generated programmatically with no reference
    to anything else.
    The sensors modulate the ongoing signal, so the simulation output is based on the sensor values as well as a time dependent history (and noise).

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,180
    Could that simulation be mapping into Audio library flowgraph?

  7. #7
    Junior Member
    Join Date
    Sep 2021
    Posts
    5
    Thatís an interesting thought. Itís a little faster that Iíd been running it at and I do like that the general simulation and USB stream are hardware independent, so I was hoping the DAC code could be a conditional inclusion for the Teensy 4 (as itís available for so many other MCUs on chip like T3.6). Latest plan is to try the fast cheap MCP4922 using SPI, outputting to the dual DAC every simulation update cycle.

  8. #8
    Junior Member
    Join Date
    Sep 2021
    Posts
    5
    Just to close the loop on this thread, I did get some MCP4922 DACs ($3.23 each from Mouser) and using SPI, analog out from the Teensy 4 works perfectly for my needs. To be clear, this thread probably doesn't belong in the "Audio Projects" forum, as this is really not high quality audio but rather simulated physiological signals (that you can listen to, if you want). In any case update is a very solid 10Khz, and while there is an arduino library for the chip (https://github.com/michd/Arduino-MCP492X) the update function is quite straightforward. The Microchip data sheet is, as usual, very clear. See also https://www.best-microcontroller-pro...m/mcp4922.html and http://little-scale.blogspot.com/201...-bit-dacs.html.

Tags for this Thread

Posting Permissions

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