Simulating a signal and sending to audio shield (T4)

Status
Not open for further replies.

sheinb

Member
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!
 
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".
 
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.)
 
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.
 
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).
 
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.
 
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-projects.com/mcp4922.html and http://little-scale.blogspot.com/2016/11/multiple-midi-controlled-12-bit-dacs.html.
 
Status
Not open for further replies.
Back
Top