#1 Arduino Uno R4 Wi-Fi Board - Using DAC output to dim/fade LED

#1 Arduino Uno R4 Wi-Fi Board - Using DAC output to dim/fade LED

 

RA4M1 microcontroller has 2-channels of 8-bit DAC and 1-channel of 12-bit DAC. 12-bit DAC has output amplifier and 8-bit DAC doesn’t have output amplifier. The 8-bit DAC output is given to the on-chip comparator as reference voltage. 12-bit DAC output is available on the A0 pin of the Arduino Uno R4 Wi-Fi. The range of the output is from 0 to 3.3V. 12-bit DAC is preferred for smooth LED fading. We can see the DAC output highlighted in green (P014_AN09_DAC) in the below snapshot of the schematic.

Pin (Arduino Connector)

MCU Pin

Functionality

Remarks

DAC0 (A0)

RA0

12-bit DAC, Analog In

True analog output, 0–3.3V, use for LED dimming

D2 – D13

-

Digital I/O, PWM capable

8-bit PWM output, can simulate analog voltage

D9, D10, D11, D12, D13

-

8-bit DAC output via PWM

Simulated analog output (not true DAC)


While using the A0 pin for the 12-bit DAC, unfortunately with the Arduino Core, it uses only 8-bit output and not full 12-bit. So, the maximum analog value of 3.3V on A0 pin will be reached for a value of 255 max. DAC value.

Below is the code for the same:

const int dacPin = A0;        // DAC0 pin
const int minDAC = 100;       // Minimum DAC value for LED to visibly glow
const int maxDAC = 200;      // Maximum DAC value (full brightness)
const int step = 1;          // Increment/decrement step
const int delayTime = 50;      // Delay in ms per step

void setup() {
  // No pinMode needed for DAC
  Serial.begin(9600);
  Serial.println("LED Fading Process");
  analogWrite(dacPin, maxDAC);
  delay(5000);
  analogWrite(dacPin, 0);
  delay(5000);
}

void loop() {
 
  // Fade up
  Serial.println("Fade Up started");
  for (int value = minDAC; value <= maxDAC; value += 10) {
    analogWrite(dacPin, value);
    delay(500);
    Serial.println("Fade up processing\n");
    Serial.println(value);
    }

  // Fade down
  Serial.println("Fade Down started");
   for (int value = maxDAC; value >= minDAC; value -= 10) {
    analogWrite(dacPin, value);
    delay(500);
    Serial.println("Fade down processing\n");
    Serial.println(value);
  }
}

Here is the link to the video from our YouTube Channel Way2Know:

Post a Comment

0 Comments