The following works as expected here, giving independent control of the two DACs:
while (true)
{
analogWrite(DAC0, 240);
delayMicroseconds(200);
for (int i = 0; i < 8; i++)
{
analogWrite(DAC1, 240);
delayMicroseconds(20);
analogWrite(DAC1, 120);
delayMicroseconds(80);
}
analogWrite(DAC0, 0);
analogWrite(DAC1, 0);
delay(9);
}
Several people in this forum seem to have had trouble and have possibly blown their DAC output(s) by following an Audio example with a loudspeaker (which I haven't tried).
For anyone following with an 'early production' Due like me, please note that the constant 'DAC0' (66) corresponds to pin 'DAC2' on the board header, and 'DAC1' (67) corresponds to pin 'DAC1'.
Attached are screenshots from a Rigol scope. N.B. I'm using x10 probes.
i guess you are writing DAC in loop() but my (non-working) example was writing DAC in setup(), your code also has delay before writing second DAC channel, just like my second (working) example. In my opionion, there is bug in analogWrite(), related to initialization of DAC.
V.
I tried your code and from what i can tell (using Velleman HPS5), it works as expected, BUT it is equivalent to example from my first post which works as expected:
Insertion of some delay between first two writes is perfectly acceptable workaround for me, but IMO this behaviour is bug and should be fixed. Am i crying on wrong place(forum)?
Is it possible to change the DAC resolution using the dacc_write_conversion_data(DACC_INTERFACE, value);?
It's always using 12 bits, even if I change using that command: analogWriteResolution(8);.
Is it seem the analogWriteResolution(8); only works when we write a value using analogWrite(DAC0, value);
Hi. I'm trying to use the DAC from my due to make a square wave. After analogWrite(DAC0,value), the output voltage won't reach 0V again. I know that the voltage output will always be between 0.55 and 2.75V, but i really need 0V... There is a way to turn off the DAC0? I've tried digitalWrite(DAC0,LOW) with and without pinmode() function.
How to get rid of the 0.55 Vdc from the DAC output---
You will have to waste an amplifier on this to do it right, otherwise a series capacitor will do the trick. I'll show you in text so everyone can see it:
----|(---- use a nice big capacitor; 47uf will pass just about all frequencies, 0.047pf will block all frequencies.