Teensy 3.5 - How to write data to DAC pins easily?

Status
Not open for further replies.

mike6789

Member
Hi all,

I want to just output some values to the DAC pins in my loop() code.

Cannot seem to find information on how to do this.

I don't want to use the audio library.

Any help?

Thanks!
 
Hi all,

I want to just output some values to the DAC pins in my loop() code.

Cannot seem to find information on how to do this.

I don't want to use the audio library.

Any help?

Thanks!

You use the analogWrite function. If you are writing to a DAC pin (A21/A22 on the Teensy 3.5/3.6, A14 on the Teensy 3.1/3.2, or A12 on the Teensy LC), it does a real analog write (i.e. adjusts the voltage of the pin). You might need an amplifier on the pin(s) before connecting it to a speaker.

Due to poor naming of the function from original Arduino systems, analogWrite on a digital pin that supports PWM, rapidly turns the pin on/off, so that it approximates an analog signal (if you are looking at a LED, it will appear to dim the LED, as the light turns on/off faster than the eye can see). Typically you would need a low pass filter if you want a PWM output to better approximate an analog signal.

And yes, IMHO, the original Arduino should have called the second function something like pwmWrite, but they didn't.
 
You use the analogWrite function. If you are writing to a DAC pin (A21/A22 on the Teensy 3.5/3.6, A14 on the Teensy 3.1/3.2, or A12 on the Teensy LC), it does a real analog write (i.e. adjusts the voltage of the pin). You might need an amplifier on the pin(s) before connecting it to a speaker.

Due to poor naming of the function from original Arduino systems, analogWrite on a digital pin that supports PWM, rapidly turns the pin on/off, so that it approximates an analog signal (if you are looking at a LED, it will appear to dim the LED, as the light turns on/off faster than the eye can see). Typically you would need a low pass filter if you want a PWM output to better approximate an analog signal.

And yes, IMHO, the original Arduino should have called the second function something like pwmWrite, but they didn't.

Oops... duh... thanks guys! :)
 
Status
Not open for further replies.
Back
Top