Teensy LC "true 12 bit digital to analog converter" -- how to?

Status
Not open for further replies.

mpark

Member
Just got a Teensy LC, largely because it's supposed to have a DAC, but I haven't been able to find any information about it. Can someone please point me to some docs or post some code showing me how to output an analog signal? I don't even know what pin it's supposed to use.
 
... Now how do I use it?

Need details on the usage case? AudioLibrary writes to it one way - or manually perhaps like here http://www.hobbytronics.co.uk/teensy-v31
Code:
//*Simple*DAC*sine*wave*test*on*Teensy*3.1

float phase = 0.0;
float twopi = 3.14159 * 2;
elapsedMicros usec = 0;

void setup() {
**analogWriteResolution(12);
}

void loop() {
**float val = sin(phase) * 2000.0 + 2050.0;
**analogWrite(A14, (int)val);
**phase*=*phase*+*0.02;
**if (phase >= twopi) phase = 0;
**while (usec < 500) ; // wait
**usec*=*usec*-*500;
}
 
Yes, just use analogWriteResolution() and analogWrite(), the same way you would do for PWM. By giving those functions the DAC's pin number, A12 or 26, they'll control the actual analog output from the DAC.

The audio library currently doesn't work on Teensy LC, because it requires the more powerful DMA controller and DSP extensions of Cortex-M4.

The Talkie library is an example of one that does work on Teensy LC and uses the DAC output. As I recall, it just uses analogWrite.

If you *really* want to dig into the actual code to directly access the DAC, the just look at the analogWrite code. The part specific to Teensy LC's DAC begin on line 531. As you can see, once the DAC is configured, you can update it by just writing 16 bits to the DAC0_DAT0L register.

For complete documentation about the DAC's details, you'll need the reference manual. The DAC is covered in chapter 30, starting on page 557.
 
Indeed Talkies uses :
Code:
#if defined(__MKL26Z64__)
	analogWrite(A12, nextPwm);

Above pasted example post #7 shows commands noted in post #8 - but as noted uses DAC T_3.1 pin A14 not A12 as shown on the card/web link.

And no AudioLib won't work on T_LC, but does it through register the way linked github code - but use case isn't noted - that would require a T_3.X
 
Status
Not open for further replies.
Back
Top