1

I am as new to Arduino as it can get. To start off, I am trying to build a DAC using an Arduino Leonardo. I have a digital signal coming from my dual differential comparator. I want to convert this to an analog signal.

First, I will read the digital signal in a digital pin (can someone point me which is good? There are so many of them. I was overwhelmed). Then I send out a PWM signal (confused with the pin again). Then I use a simple RC circuit to filter out the PWM signal to produce a simple sine wave.

Am I going towards the correct direction? If not, please any suggestion would be helpful.

enter image description here

  • Which dual differential comparator you are using. It would be great if you could add your circuit and any details of what you have tried and what didn't work. – sa_leinad Jan 1 '18 at 14:39
  • A dual differential comparator is a type of comparator which gives digital signal as output – Jack Jan 1 '18 at 16:51
  • @sa_leinad LM2903 – Jack Jan 2 '18 at 6:23
  • 1
    please describe the signals at the comparator inputs and how they relate to the final analog output – jsotola Jan 2 '18 at 6:50
  • @sa_leinad: please check the edited picture. I have added my circuit diagram. I have a hall sensor which varies its output voltage with respect to the magnetic field. This output is connected to the Comparator. which outputs a digital signal. – Jack Jan 2 '18 at 14:43
0

Yes you are going in the right direction.

Comparators
You haven't as yet detailed how you plan to connect the 2 comparators to the Arduino, but I imagine it would be something similar to this:

schematic

simulate this circuit – Schematic created using CircuitLab

In the circuit above, X and Y are either high or low based on the analog voltages of A, B, C & D. I have created a truth table below with some arbitrary voltages to output. The value column corresponds to the value needed for the analogWrite() function.

truth table

Note: If you need your analog output to be able to source some current you can add an Op-Amp in a unity gain configuration at the output of the RC filter.


Examples To Read
To output the analog value, the 4 best suited inbuilt examples/tutorials to look at are:

Dimmer: Send serial values to change the brightness of an LED.
Fading: Use an analog output (PWM pin) to fade an LED.
Analog In Out Serial: Read an analog input pin, map the result, and then use that data to dim or brighten an LED.
Read ASCII String: Parse a comma-separated string of integers to fade an LED.

What all of these examples have in common is the analogWrite() function:

// writes the analog value (range from 0 to 255):
analogWrite(pin, value);

Dimmer is a simple example where a serial value is read and then output on one of the PWM pins.
Fading is probably the most basic example of using the analogWrite() function (PWM output).
I included Analog In Out Serial as it uses the map() command.
I included Read ASCII String as it shows how to parse multiple values on the serial string.


PWM Pins
You can use pins 3, 5, 6, 9, 10, 11, and 13 on the Arduino Leonardo to output the PWM using the analogWrite() function.


Control
I recommend the following tutorials for your control. You could either use the if-else command or the switch-case command.

  • Thanks for your detailed reply. But I have only 1 comparator, how do I modify this to my need? – Jack Jan 3 '18 at 16:04
  • What analog voltages do you need? (One for your LOW signal and one for your HIGH). What you have tried and what didn't work? – sa_leinad Jan 4 '18 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.