gatheround
Well-known member
I'm have a strange issue with using the DAC on a Teensy LC. This code works fine on a Teensy 3.2, so I'm a bit confused.. maybe I'm missing something obvious?
The code basically reads the ADC value at A9 (at 16 bits) and then outputs the reading as 12 bits to the DAC pin. It works fine from 0 to 1.5V and then just holds 1.5V as the readings from A9 continue to increase.
I'm getting:
The code basically reads the ADC value at A9 (at 16 bits) and then outputs the reading as 12 bits to the DAC pin. It works fine from 0 to 1.5V and then just holds 1.5V as the readings from A9 continue to increase.
Code:
#include <ResponsiveAnalogRead.h>
ResponsiveAnalogRead ring(A9, false);
uint8_t dacpin = A12; // pin for DAC (A14 on Teensy 3.2, A12 on Teensy LC)
void setup()
{
Serial.begin(115200); // start Serial connection for debug console
delay(2000); // chill for a bit
analogWriteResolution(12); // DAC
pinMode(dacpin, OUTPUT); // DAC
analogWrite(dacpin, 0); // set DAC to 0V.
ring.setAnalogResolution(65536);
analogReadAveraging(16); // set analog read averaging (1 - 32) 16 tested really good here.
analogReadRes(16); // 0 - 65535
}
void loop()
{
ring.update();
dopitchfreeze();
}
void dopitchfreeze(void)
{
analogWrite(dacpin, ring.getValue() >> 4);
Serial.print("Dac to ");
Serial.print(ring.getValue() >> 4);
Serial.print("\n");
}
I'm getting:
Code:
Dac to 625 (.5V)
Dac to 1254 (.995V)
Dac to 1634 (1.3V)
Dac to 1906 (1.475V)
Dac to 2360 (1.480V)
Dac to 3193 (1.480V)