This here is a DAC module, or digital to analog converter. As its name implies,
this module could create analog voltages and we can set the output values using digital numbers.
The Arduino for example, doesn’t have a DAC, only ADCs.
That’s why this module is great in order to have a steady DC output.
You will see that it’s also capable of generating signals, so that’s also interesting. So Stick
around in order to learn more about this module and how to use it. So guys, let’s get started.
What’s up my friends, welcome back.
This is the MCP47 25 module and this is a DAC or digital to analog converter.
It means that we can send digital instructions to it and it will output a steady DC value. But it
could also create analog signals such as a sine wave, sawtooth, triangle or square signals, so
it could be just like a small function generator but as we will see later it has its limitations.
So, this works with i2c communication. So we connect the SCL and SDA pins for clock and data
to the pins of the Arduino, pins A4 and A5 as always. The module works at 5V
so we also connect the supply and ground from the Arduino. On the out pins we will get the output.
Before we see the code and some other examples, let’s check some specs.
This is a 12-bit DAC. 12 bits is quite a lot, that means we could use digital values from 0 to 4095
and working with 5V, that equals to a precision of only 1.2mV for each digital state.
Basically, we divide the scale from 0 to 5V into 4095 steps. Each step is equal to around 1.2mV.
So the question is simple. If 4095 is for 5V, what value should we send for let’s say 3V. Well, it is
the simple rule of 3. We should send 3 multiplied by 4095 and divided by 5, equal to a value of
2457. Quite easy, right? Now the current output is very low so we can’t use this as a supply
so be careful. We can only use it as a voltage reference and later we will see some examples.
By the way, it also has an EEPROM memory incorporated.
Using that it will store the last value and in case the module resets or loses power,
when it starts back up it could continue with the last stored value.
The i2c address, by default, is 0x 62. But if you want to use multiple modules like this one
at the same time and have different addresses, you can use these small pads of the module
to change the address by making a solder connection to GND or VCC.
So guys, make these connections between the Arduino and the module and then run Arduino IDE.
Go to sketch, include library and open the library manager.
Here search for MCP 47 25 and select the Adafruit library and install it.
Then download from below this first example code.
As you can see, we import the needed library. Then we start an i2c communication with the
0x 60 address because my module has the ADDR pin connected to ground.
Then we use the set voltage function to set the output to 1, 2, 3, 4 and 5 volts with a 2
seconds delay in between. Upload this code to the Arduino and connect a multimeter at the output.
As you can see, each 2 seconds the value jumps 1 volt.We
can already see that the values are not exactly 1V, 2V, 3V and so on so we must tweek the digital
values in the set Voltage function and that's because, probably, the VCC value from the Arduino
is not exactly 5V. As you can see, with 4124 instead of 4095, we get perfect values.
Let’s set it to 3V and take a look on the oscilloscope. As you can see, it is a steady line.
There is no switching at all and that's great when you want a voltage reference without any noise.
Now let’s see another example generating signals. This is the code for that, and as you can see,
we now create a lookup table with the values for our signal.
This is for a sine wave of 9 bits, this one is for 8 bits, 7 bits and so on. Let’s check the
result on the oscilloscope with a resolution of 9 bits and as you can see the signal is very smooth.
Only if we zoom in almost to the maximum we can see some small steps.
Now let’s do the same with only 5 bits and as you can see this vector has only 32 different steps.
With fewer bits, is obvious that we can see the steps of the DAC. But on the other side,
with 9 bits it was practically a perfect sine wave and we can’t see any steps.
But anyway, we can always add a capacitor at the output to smooth the steps a little bit.
Now let’s make another code. This time we read the input from a potentiometer and create a delay.
Varying this delay, we can change the frequency of the signal.
Upload this new code and add a potentiometer and a push button.
As you can see we can now change the frequency as well.
Also if I push the button, we can change the signal type from sine, to triangle or sawtooth.
One thing that you can notice is that the maximum frequency is only 62 Hertz. That’s very,
very slow for a function generator, right? The i2c communication of the module works at 400Khz,
but even so, because we need to send so many bits,
and so many values for each wave, limits the maximum frequency. But anyway, at a lower
resolution we can get to higher speeds than only 62Hz. So guys, what could you use this module for?
Well, as a first example, you could connect it to a VCO or voltage-controlled oscillator.
By changing the voltage here, you change the frequency at the output.
You can make such circuits using OPAMPs and in this case the frequency could go a lot higher,
and also, having a 12 bits DAC we could precisely control the signal frequency. Using two OPAMPs you
can get a triangle and a square wave oscillator very easy with this circuit. And instead of using
OPAMPs you can make an oscillator with a 555-timer using this circuit instead and go up to 1KHz.
Another use is to control a load. Remember this project of the variable load?
If not, check the video below in order to know what I’m talking about.
Because for that project I was controlling the voltage at the MOSFET gate using this DAC module.
With that we can precisely set the voltage in order to regulate the resistance of the
variable load and this was the schematic. And If you want to use a higher voltage values than 5V,
you can always add an amplifier at the output with a certain gain. Another idea I have in
mind is to connect the DAC output at the input of a buck or boost converter like this one.
The output of this converter is controlled by the voltage value set by the potentiometer.
Instead of that we can set the voltage with our DAC
and like that we can create a digital supply as I did in one of my previous videos.
But this time, instead of using the Arduino to create the switching signal, we can use
the dedicated IC of the converter and we only have to change the voltage at the control pin.
That should make an interesting project, right? Well guys, that’s how you can use
the MCP47 25 DAC module. You have the example codes and the library below ready to download.
Check more information on electronoobs.com. I hope that you have learned something new
and if so, consider giving me a like or comment below. Thanks again and see you later guys.