The Arduino has no integrated DAC; to create analog output values, we have to use the standard Arduino function analogWrite(). This creates a so called PWM DAC, a PWM signalwhich has to be filtered with a low-pass filter. However, the standard analogWrite() function is very slow, don’t use it anymore. We use the <TimerOne> Libary:
const int dacPin11 = 11;
const int dacPin12 = 12;
const int dacPin13 = 13;
void initVolt(){
pinMode(dacPin11, OUTPUT);
pinMode(dacPin12, OUTPUT);
pinMode(dacPin13, OUTPUT);
Timer1.initialize(32);
Timer1.pwm(dacPin11, 0);//Need to set value
Timer1.pwm(dacPin12, 0);//Need to set value
Timer1.pwm(dacPin13, 0);//Need to set value
}
void setVolt(double setV1,double setV2){
//Values between 0-1024(0..5V)
Timer1.setPwmDuty(dacPin11, setV1);
Timer1.setPwmDuty(dacPin12, setV2);
}
That’s it.