Teensy 3.2 DAC output voltage

Status
Not open for further replies.

pmartin

Member
Hi,
I have an array of float values that i must output to the Teensy 3.2 board built-in DAC (pin A14).
I have setup analogWriteResolution(12) (so 4096 possible values). I'd like to normalize the output to the range 0 - 3.3V.

What is the relation between a float value and its output voltage on the DAC pin?
Thanks in advance

Best Regards
pmartin
 
First, the DAC doesn't work with floats, but with unsigned 16bit integers (where the highest 4 bits have to be always 0 with respect to the 12bit resolution).

Writing a 0 to A14 will output 0V, writing a 4095 to A14 will output 3.3V. That's how all unipolar DACs work.

Now, you have to look at your float array and to detect the lowest and the highest possible values. From this, you can write a simple function which rescales, rounds and casts your float values from float_min to float_max towards (uint16_t) 0 to (uint16_t) 4095. That should be easy, since in most cases, rescaling can be done with a first order polynome.
 
Last edited:
First, the DAC doesn't work with floats, but with unsigned 16bit integers (where the highest 4 bits have to be always 0 with respect to the 12bit resolution).

Writing a 0 to A14 will output 0V, writing a 4095 to A14 will output 3.3V. That's how all unipolar DACs work.

Now, you have to look at your float array and to detect the lowest and the highest possible values. From this, you can write a simple function which rescales, rounds and casts your float values from float_min to float_max towards (uint16_t) 0 to (uint16_t) 4095. That should be easy, since in most cases, rescaling can be done with a first order polynome.

Thanks!
It seems to work:

max and min are float, so:

to output the correct float value:

analogWrite(A14,(unit16_t)(4095.0*(value - min)/(max - min)))

Best Regards,
pmartin
 
Status
Not open for further replies.
Back
Top