pinMode(66, OUTPUT); Causes Strange Behavour on Due DAC0, how do you reset the pin mode?
I'm creating a project using the Arduino Due's DAC. For reasions related to the project I at some times want to be able to set the DAC0 pin to LOW.
I've noticed strange behaviour when using the command:
pinMode(66, OUTPUT);
Without the command present I see a nice output signal on an oscilloscope consistent with what I'm aiming for:
(sorry I can only include one image)
However if pinMode(66, OUTPUT); is used I get a flickering result:
Does anyone know what state the DAC0 pin mode is set to as default and what command can put it back into that state?
I have tested pinMode set to INPUT and INPUT_PULLUP and they both give similar problems.
If it helps please find some sample code below:
// True Due DAC Range 0.54V 2.74 V
void setup() {
// resolution to 12, you can use analogWrite() with values between 0 and 4095
// default resolution to 8, you can use analogWrite() with values between 0 and 255
analogWriteResolution(12);
//Serial.begin(115200);//Set the baudrate to 115200,same as the software settings
pinMode(66, OUTPUT);
// pinMode(66, INPUT);
// pinMode(66, INPUT_PULLUP);
}
void moveRight(int x) {
int y;
for (int y = x; y > 0; y = y - 1) {
// right
analogWrite(DAC0, 0); //0.54V -low part
delayMicroseconds(80); //low duration . Should be 80us
for (int i = 117; i < 4095; i = i + 117) { //should be 140us
analogWrite(DAC0, i); // makes a linear rise t=140us, x=4us, +117 each step, loop=35
delayMicroseconds(4);
}
analogWrite(DAC0, 4095); //high period. Should be 160us
delayMicroseconds(160);
}
}
void moveLeft(int x) {
int y;
for (int y = x; y > 0; y = y - 1) {
//left
analogWrite(DAC0, 4095); //high period. Should be 160us
delayMicroseconds(160);
for (int i = 4095; i > 0; i = i - 117) { //should be 140us
analogWrite(DAC0, i); // makes a linear rise t=140us, x=4us, +117 each step, loop=35
delayMicroseconds(4);
}
analogWrite(DAC0, 0); //0.54V -low part
delayMicroseconds(80); //low duration . Should be 80us
}
}
void loop() {
analogWrite(DAC1, 0); //0.54V -Use DAC1 to give ground reference?
moveRight(1);
// pinMode(66, OUTPUT);
// digitalWrite(66, LOW);
// delayMicroseconds(200);
// digitalWrite(66, HIGH);
// delayMicroseconds(200);
}
