analogWriteResolution(12); //12 bits resolution
analogWrite(DAC1, b); // output values of varible b at the Digial to analog converter
delayMicroseconds(14);
Serial.println (b);
I just made a brief test with your code but simulating the digital input, and got in my oscilloscope a 13 seconds ramp from 0.6v to 2.8v at the DAC1 pin which means to me that your code should run OK. A caveat regarding DAC Due outputs: do not connect any load directly to the DAC pins of the Arduino Due. Use an amplification circuit between the DAC pin and the load as is shown here: http://arduino.cc/en/Tutorial/SimpleAudioPlayer
Here my test code:
const int digitalInputPin = 26;
void setup() {
pinMode (DAC1,OUTPUT);
pinMode (digitalInputPin,INPUT);
Serial.begin(9600);
}
void loop() {
int b;
for(int i=0; i<4096; i++)
{
b = digitalRead (digitalInputPin);// Read pin 26
analogWriteResolution(12); //12 bits resolution
analogWrite(DAC1, i); // output values of varible b at the Digial to analog converter
delayMicroseconds(14);
Serial.println (b);
}
while(0){ // loop goes forever
}
}
thank thank you so much Palliser for verifying the code. with your help,i feel i am still on track.
i hope you don't mind if i ask another question,
i wrote a code to convert an analog signal to digital on Due. the results ,i am getting on the oscilloscope, of the ADC as shown in Frequency_5Hz (attached) for analog square wave = 1v at the pin( A1). fre = 5Hz.
and by increasing the frequency to 50Hz at scope Frequency_50Hz, the ADC seems like it can't catch up with the input signal.
the code i wrote is:
int a;
a = analogRead(InputPin);
digitalWrite(OutPin,a);
Serial.println(a);
while(0){
}
}
a confusing point is that in Frequency_5Hz i can see that ADC is responding but not correctly. i think that i should see a series of binaries not a plus looks similar to the input signal.