Arduino has functions such as outputting digital signals and PWM signals, but does not have the ability to output analog signals. In this article, we will introduce a DA converter that can realize this analog signal output.
A digital signal is a signal represented by the binary digits 0 and 1. In the field of electronic circuits, it is also sometimes referred to as "low high" or "on off". Phenomena in nature and signals that humans can perceive are analog signals. Analog signals are characterized by their size, time, and number being continuous.
A converter is a converter that converts a digital signal into an analog signal and outputs it.
Audio and ** are analog signals. However, in recent years, audio processing and image processing have begun to require digital signals. Filtering and compression are not supported when processing analog signals, while digital signals do. Converting the processed digital signal back to an analog signal requires a DA converter.
Arduino includes a variety of products such as Arduino Uno, Arduino Leonardo, and Arduino Nano.
The Arduino Due is one of the Arduino with a built-in DA converter. However, the shape of the DU is different from that of the Arduino Uno and the operating voltage is 33V, the way to use it is also different.
If you want to use the Arduino UNO, which is already popular, to output analog signals, you need an external DA converter IC.
This time, instead of using an expansion board with a built-in DA converter, we tried to connect the DA converter IC directly to the Arduino to see if we could output an analog signal. We are using ROHM's DA converter IC "BH2219FVM" (8-bit resolution, dual channel).
Since the BH2219FVM is in an MSOP8 package, we will use a conversion board to make it compatible with the multi-purpose board.
Unlike the D-A converters of the I2C and SPI methods, this DA converter operates through three-wire serial communication. Since it is its own way and does not conform to a specific protocol, you need to create your own serial communication processing in order for the DA converter to work properly in the sketch.
Check the technical specifications of the BH2219FVM while connecting to Arduino. Connect the oscilloscope probe to the output pin and confirm the waveform.
The technical data sheet for the BH2219FVM provides detailed instructions on how to use it. In addition to the maximum rating and electrical characteristics, the technical specifications also provide operating instructions on how to apply signals to operate, and it is necessary to think about how to deal with them while reading these contents.
Reference: D A converter Standard 8-bit resolution Dual-channel Triple-channel Rohm
The control method of the BH2219FVM is simple. The port (4 bits) and 8 bits of data (4 bits, 8 bits, 12 bits) that output analog signals are sequentially transmitted to the DI pin in 1-bit increments. The BH2219FVM reads the DI pin on the rising edge of the CLK pin. After the 12-bit transmission is completed, if the LD pin is on, an analog signal corresponding to the data is output.
The following is to output 2 to the AO1 portThe 5V voltage is illustrated as an example.
According to the preceding table Channel Settings (BH2219FVM), the first four digits indicate that Port AO1 has a fixed value of 0000.
The next data is the one that says "25v" of the 8-bit value, passed.
256 Output Voltage Supply Voltage Data".
Make the calculations. The result is:
256 × 2.5[v] ÷5[v] =128”。
Since 25V is "half of the supply voltage", so the data is "half of the number (256) that can be represented by 8 bits", which is "128". When expressed in binary, 128 is "10000000".
Send "0000" and "10000000" to the BH2219FVM by making the DI pins on (1 0) in the order of the ON of the CLK pins. Finally, as long as the LD pin is ON and off, BH2219FVM can output 25V analogue signal.
The sketch below is to send data from Arduino to the BH2219FVM via serial communication and output a "sawtooth wave" to the AO1 pin of the BH2219FVM.
#define ld 8#define clk 7#define di 6boolean d[12];Convert the input value to binary and save it in array d0 d7int binary(int out)} save the output port specified result in array d8 d11int chselect(int outpin) }else if (outpin == 2) output the array to dacvoid outconfirm() digitalwrite(ld, high); digitalwrite(ld, low);} Pass the output value and output port to each variable int operationout(int value, int ch)void setup() void loop().This sketch is more focused on ease of understanding, so the efficiency is not very good, and the conversion cycle is a bit slow.
Each piece of work in the sketch is explained below.
#define ld 8#define clk 7#define di 6boolean d[12];First, associate the pins of the DA converter to be connected to the pin number of the Arduino. LD is pin 8, CLK is pin 7, and DI is pin 6. Next, an array d is defined to hold the 12-bit information to be sent to the DI pin. In order to hold 0 1 for 12 bits, 12 array elements are required. Since only 0 and 1 are saved, we use the boolean data type.
void setup()Set the work of the pin to be used via the setup function. All three pins are used for the output. Specifying the LD pin as low in the setup function is intended to prevent its state from being unstable.
void loop()The "data to be output" and "port number" are passed to the operationout function (which is used to output the signal to the DA converter described below) via the loop function. For Data to be output, a value is set to increase progressively from 0 to 255 using the for statement. Since the work is repeated every time the loop function is called, the output voltage is a "sawtooth wave".
int operationout(int value, int ch)The operationout function has passed the arguments to the function that performs the actual processing. Three functions are then called: the chselect function, which expands the port number (the upper 4 bits) to 0 or 1, the binary function, which expands the data to be output (the lower 8 bits) to 0 or 1, and the outconfirm function, which transfers the contents of the array d to the da converter.
int chselect(int outpin) }else if (outpin == 2)Use the chselect function to perform operations up to 4 bits. When the port number 1 is specified from the parameter, 0 is saved in elements 8 through 11 of array d. When port number 2 is specified from the argument, 1 is saved in element 8 of array d, and 0 is saved in elements 9 through 11.
int binary(int out)}The incoming decimal number is converted to an 8-bit binary number by the binary function and stored in d[0] to d[7]. This technique is often used in binary conversion. Repeat the execution with the for statement "Find the remainder after dividing by 2 (Is the lowest digit 0 or 1?) ), divide by 2 (round off the lowest digit)" to "convert from the lowest digit to a binary number in turn".
void outconfirm() digitalwrite(ld, high); digitalwrite(ld, low);}Through the final outconfirm function, the data in the array d is transferred to the da converter and the analog signal is output.
The order in which 0 1s in the array d is reversed from the order in which it is transmitted to the d a converter. Thus, the for statement loops in descending order from 11 to 0 and outputs the contents of array d in the correct order. In the loop, CLK processing is also performed. After the end of the for statement, when the rising edge signal of the LD pin is added, an analog signal corresponding to the transmitted data is output from the DA converter.
Below is a voltage plot for each point observed with an oscilloscope.
The waveform when the BH2219FVM is operated by Arduino outputs a 19Hz sawtooth wave from the output pin of the DA converter.
Look at the waveforms on the DI pin (top) and the CLK pin (bottom). You can see how the DI pin is on and off based on the action of the CLK.
Zoom in on the waveform to see how the signal is being sent. The image shows that the signal of 180 is sent to the AO1 pin of the DA converter. According to this signal output 352V voltage.
With the advancement of digitalization, DA converters are widely used in various products such as ** equipment, communication equipment, and motor drive equipment.
By adding analog signal processing using a DA converter to the Arduino, it can be used in a variety of scenarios.
In this case, the data transfer method may seem a bit complicated, but it is easier and simpler to use a converter that supports common data transfer standards such as I2C or SPI. When you need an analog output, give a DA converter a try!
If you need to purchase a D a converter, apply for sample testing, BOM matching and other needs, **Customer Service WeChat: 13310830171.