Go Down

Topic: analogWrite Arduino DAC1 output like pwm digitalWrite (Read 2059 times) previous topic - next topic

wdclot1

I use analogWrite(DAC1,Output) in my code, but I find it like digital pulse output, rather than expected analog continuous curve, i don't know why, forgive a fresh people in C language.
Code: [Select]


#include<PID_v1.h>
double Setpoint, Input, Output;
PID myPID(&Input,&Output,&Setpoint,2,5,30,DIRECT);
void setup()
{
 
  Input= analogRead(A0);
 
  Setpoint = 3000;
  Serial.begin(9600);
  myPID.SetMode(AUTOMATIC);
  myPID.SetSampleTime(10);
  // put your setup code here, to run once:

}

void loop() {
  Input = analogRead(A0);
  Serial.print("Input = ");
  Serial.println(Input);
  myPID.Compute();
  analogWrite(DAC1,Output);
  Serial.print("Output = ");
  Serial.println(Output);
 
  // put your main code here, to run repeatedly:

}


wdclot1

I have  some Arduino Due borads, so there is DAC1 pin



wdclot1

Sorry, I have tried it just now, but it's not useful, then the output in oscialloscope are very small. A proportion reduce to 255/4096.

vaj4088

I do not have a Due so I cannot comment directly.

The documentation at
https://www.arduino.cc/en/Reference/AnalogWrite
in the third paragraph says

Quote
The Arduino Due supports analogWrite() on pins 2 through 13, plus pins DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to Analog converters, and act as true analog outputs.

wdclot1

But in my code, the analogWrite(DAC1, Output)still output signal like PWM, some pulses



dlloyd

Note that the voltage range on the DAC output is 0.55V to 2.75V for 0 to 4095 in code. (1/6 to 5/6 of Vcc)

Go Up