Teensy LC, DAC

mkoch

Active member
Hello,

where can I find a code example for the DAC on Teensy LC? What's the output voltage range? Does the DAC use the same reference voltage as the ADC? Is it possible to make the internal 2.56V reference available at an output pin? I mean not the DAC pin.

Thanks,
Michael
 
Here is the most basic code to use the DAC on the Teensy LC:
Code:
void setup() {
  analogWriteResolution(12);   // set to 12 bits
  analogWrite(A12, 4095);      // value 0 - 4095, 0V - 3.3V
}

void loop() {
}

The AREF pin on the Teensy LC is the analog reference.

For more info, google for "site:forum.pjrc.com teensy lc dac".

Paul
 
Where can I find the documentation for analogWriteResolution() and analogWrite() functions?
The AREF pin is only an input, correct?

Michael
 
On this page.
Don't get confused by the PWM stuff - when you specify an actual DAC pin for analogwrite(pin), the software will output an analog value, not PWM.
Yes, the AREF pin is input only.

Paul
 
Well, I have an example running with ADC and DAC, but I'm still unable to find any documentation for the functions. For example, there is a function analogReference(). Where is the documentation for this function, including the complete list of the possible arguments?
If there exists no documentation, then alternatively where can I find the source code of the function?

Michael
 
I haven't seen formal documentation for the analogReference() function, but searching on this forum revealed this:
analogReference(INTERNAL), analogReference(DEFAULT) and analogReference(EXTERNAL). DEFAULT == EXTERNAL.
analogReference(INTERNAL) is 1V2 for Teensy 3.x.
analogReference(INTERNAL) is not available on Teensy LC.

Paul
 
On this page
https://www.pjrc.com/store/teensylc.html
is written:
"The AREF pin is used to set the analog input range. By default, AREF is 3.3V due to a resistor. External shunt-type reference chips may be connected for lower reference voltage."

But when I measure the voltage at the AREF pin, it is zero. There is no resistor connected to it. What's wrong here? An external shunt reference can't work without a voltage.

Michael
 
Last edited:
You're right. I verified the AREF pin to be zero on my LC as well. Tried a sketch which does an analogRead(A0) but the AREF voltage is still zero.
I guess it's internally connected to 3V3 by means of firmware.
From C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\analog.c:
Code:
#elif defined(__MKL26Z64__)
if (analog_reference_internal) {
  ADC0_SC2 = ADC_SC2_REFSEL(0); // external AREF
} else {
  ADC0_SC2 = ADC_SC2_REFSEL(1); // vcc
}
#endif

When I print out ADC0_SC2, it is indeed set to 1.

Paul
 
Back
Top