**1.1. Functional requirements **
The topic requires making a minimum system of 51 microcontroller. The ADS1115 is controlled by the microcontroller to collect the voltage in the voltage range of 0-5V, and the voltage is displayed by setting two different display voltage modes. At the same time, a DA conversion circuit needs to be designed on this basis, and the output is determined. The voltage value is 0~5V, which is used to check the accuracy of the voltmeter.
**1.2.Technical performance indicators **
(1) ADS 1115 chip: A high-precision analog-to-digital converter (ADC) with 16-bit resolution, using ultra-small leadless QFN-10 package or MSOP-10 package. Designed with accuracy, power consumption and ease of implementation in mind. The ADS1115 features an on-board programmable gain amplifier (PGA) that provides an input range from the supply voltage down to ±256mV, enabling high-resolution measurement of both large and small signals.
(2) DAC0832 is a device that converts digital signals into analog signals. Its main technical indicators and meanings are as follows: Resolution: 8 bits, which can convert 8-bit digital quantities into analog quantities; Setup time: 1μS, that is, from writing digital quantities to the 8-bit DAC register to generating and inputting digital quantities. Corresponding analog output time; input signal: binary signal compatible with TTL level; output signal: current signal corresponding to the input binary signal; power supply: single +5V power supply;
1.3.Prepare knowledge
(1) Working principle of microcontroller
(2) ADS1115 chip
(3) DAC0832 chip
(4) Digital-to-analog and analog-to-digital conversion principles and circuit diagrams
**2.1 Theoretical Analysis **
(1) AD conversion circuit design analysis:
The AD conversion circuit uses the ADS1115 chip. The ADS1115 is a high-precision analog-to-digital converter (ADC) with 16-bit resolution and adopts an ultra-small leadless QFN-10 package or MSOP-10 package. Designed with accuracy, power consumption and ease of implementation in mind. The ADS1115 features an on-board programmable gain amplifier (PGA) that provides an input range from the supply voltage down to ±256mV, enabling high-resolution measurement of both large and small signals.
(2) DA conversion circuit design analysis:
The DA conversion circuit uses the DAC0832 chip. This chip is an 8-bit D/A converter chip with a resolution of 5V/256=19.5mV. That is, the voltage change caused by unit data input is 19.5mV, which meets the requirements to a certain extent. The question requires that a voltage value be set arbitrarily in the range of 0 to 5V.
**2.2 Basis and reasons for choosing TI devices **
The design of this system uses six TI devices, namely STC89c51 microcontroller, Ch340G model chip, Type-c model chip, ADS1115 chip, DAC0832 chip and LM324 operational amplifier.
(1) STC89c51 microcontroller
STC89C51 is a low-power, high-performance CMOS 8-bit microcontroller with 8K in-system programmable Flash memory. Manufactured using high-density non-volatile memory technology, it is fully instruction- and pin-compatible with industrial 80C51 products. On-chip Flash allows the program memory to be programmable in the system and is also suitable for conventional programmers. On a single chip, it has a smart 8-bit CPU and online system programmable Flash, making the STC89C52 a highly flexible and ultra-effective solution for many embedded control application systems. STC89C52 has the following standard features: 8k bytes of Flash, 256 bytes of RAM, 32-bit I/O lines, watchdog timer, 2 data pointers, three 16-bit timers/counters, a 6-vector level 2 interrupt structure, full-duplex serial port, on-chip crystal oscillator and clock circuit. In addition, STC89C52 can reduce to 0Hz static logic operation and supports 2 software-selectable power-saving modes. In idle mode, the CPU stops working, allowing RAM, timers/counters, serial ports, and interrupts to continue working. In the power-down protection mode, the RAM contents are saved, the oscillator is frozen, and all work of the microcontroller stops until the next interrupt or hardware reset.
(2) CH340 USB to serial port IC
USB to serial port chip CH340 is a USB bus adapter chip that realizes USB to serial port or USB to print port. In serial port mode, CH340 provides commonly used MODEM contact signals, which are used to expand asynchronous serial ports for computers, or directly upgrade ordinary serial port devices to USB bus. The CH340 chip has a built-in USB pull-up resistor, and the UD+ and UD- pins should be directly connected to the USB bus. The CH340 chip has a built-in power-on reset circuit. When the CH340 chip works normally, it needs an external clock signal of 12MHz to be provided to the XI pin. Generally, the clock signal is generated by the built-in inverter of CH340 through crystal stable frequency oscillation. The peripheral circuit only needs to connect a 12MHz crystal between the XI and XO pins, and connect the oscillation capacitors from the XI and XO pins to ground respectively. CH340 chip supports 5V power supply voltage or 3.3V power supply voltage. When using a 5V working voltage, the VCC pin of the CH340 chip inputs an external 5V power supply, and the V3 pin should be connected to an external power supply decoupling capacitor with a capacity of 4700pF or 0.01uF. When using 3.3V working voltage, the V3 pin of the CH340 chip should be connected to the VCC pin, and an external 3.3V power supply should be input at the same time, and the working voltage of other circuits connected to the CH340 chip should not exceed 3.3V. CH340 automatically supports USB device suspension to save power consumption. When the NOS# pin is low level, USB device suspension will be prohibited.
(3) ADS1115 chip
The ADS1115 is a high-precision analog-to-digital converter (ADC) with 16-bit resolution, available in an ultra-small, leadless QFN-10 or MSOP-10 package. The ADS1115 has an internal oscillator of 1MHz, producing a sampling frequency of 250 kHz. The ADS1115 resets on power-up and sets all bits in the Config register to their corresponding default settings. After completing the reset, the ADS1115 enters a power-down state, with the device interface and digital modules active, but no data conversion is performed. The main thing used here is the mode in which the ADS1115 chip collects voltage. The ADS1115 uses a switched capacitor input stage, where the capacitor is continuously charged and then discharged to measure the voltage between AINP and AINN. It operates in one of two modes: continuous conversion or single-shot Shoot. ADS1115 has many advantages such as low power consumption, 4-channel input, internal reference, and PGA.
(4) DAC0832 chip
DAC0832 is an 8-bit D/A conversion integrated chip. Fully compatible with microprocessors. This DA chip has the advantages of low price, simple interface, and easy conversion control. By inputting '0' or '1' through the 8 IO ports of the microcontroller, the voltage output can be controlled accordingly.
(5) LM324
The LM324 series of devices are quad operational amplifiers with true differential inputs. They have some significant advantages over standard op amps for single-supply applications. The quad amplifier can operate from supplies as low as 3.0 volts or as high as 32 volts with a quiescent current that is one-fifth that of the MC1741. The common-mode input range includes the negative supply, eliminating the need for external biasing components in many applications.
**2.3 Demonstration of design plan **
DA conversion circuit solution
方案一:通过PWM来实现DA转换。PWM 是一种对模拟信号电平进行数字编码的方法。通过高分辨率计数器的使用,方波的占空比被调制用来对一个具体模拟信号的电平进行编码。但由于PWM DAC的精度没有DAC的高,因此我们选择放弃这个方案。
方案二:利用DAC0832芯片来实现DA转换。该电路采用DAC0832的直通方式,此方式适用于连续反馈控制线路和不带微机的控制系统.由于DAC0832输出的是电流,因此在输出端我们接了一个LM324运算放大器实现了电流到电压的转换.因该转换电路操作方便、转换控制容易,所以我们最终选择了此方案.
**3.1硬件设计**
3.1.1系统框图(参考文档)
3.1.2不同功能单元电路的功能描述
(1)时钟电路
时钟电路就是产生像时钟一样准确运动的振荡电路。任何工作都按时间顺序。用于产生这个时间的电路就是时钟电路。时钟电路由晶体振荡器、晶振控制芯片和电容组成。
(2)复位电路
复位电路是一种用来使电路恢复到起始状态的电路设备,它的操作原理与计算器有着异曲同工之妙,只是启动原理和手段有所不同。复位电路,就是利用它把电路恢复到起始状态。就像计算器的清零按钮的作用一样,以便回到原始状态,重新进行计算。和计算器清零按钮有所不同的是,复位电路启动的手段有所不同。一是在给电路通电时马上进行复位操作;二是在必要时可以由手动操作;三是根据程序或者电路运行的需要自动地进行。复位电路都是比较简单的大都是只有电阻和电容组合就可以办到了,再复杂点就有三极管等配合程序来进行了
(3)串口下载电路
编译好程序后的烧录,带有type-c接口。
(4)采集电压电路
AD模块采用ADS1115芯片采集电压值,可利用独立按键分别控制两种模式,模式一无记忆功能,能够迅速地检测并且更新当前电压。模式二有记忆功能,按下按键后才能更新当前的电压,并能存储五组电压数据。
(5)DA转换电路
DAC0832有三种工作方式:直通方式、单缓冲方式、双缓冲方式。而我们使用的方式为直通方式。直通方式是资料不经两级锁存器锁存,即 CS*,XFER* ,WR1* ,WR2* 均接地,ILE接高电平。此外,由于DAC0832为电流输出型D/A转换器,因此为得到电压的输出,在其电流输出端接了LM248运算放大器。转换数据通过DI0~DI7口输入。当数据全为1时,输出5V电压;数据全为0时,输出0V电压。
(6)显示电路
原理图中留有LCD1602显示屏的接口,由于OLED多为彩屏,是点阵结构,适于显示图形,其用法和TFT彩屏类似。但OLED屏一般尺寸较小,大尺寸较贵,OLED屏无背光,靠像素点的LED自发光,功耗比较低。LCD分单色屏和彩屏,单色屏分为段式结构和点阵结构,段式结构只能显示简单字符,点阵结构可显示简单图形。本项目只要求显示数值,考虑到成本因素,这里使用LCD1602显示屏。LCD显示器根据ADS1115的工作模式显示不同数据,连续转换模式下LCD不断刷新显示的数据,单次转换模式下按下开关,LCD才更新显示数据,并且这里使用LCD滚动刷新数据,可同时显示五组数据,已达到记忆和回看功能。
**不同功能单元电路及接口设计**
(1)时钟电路
由于单片机正常工作需要一个时钟,因此就需要在单片机晶振引脚上外接一个晶振(我们使用的 STC89CXX 单片机晶振引脚是 18 和 19 脚),至于需要多大晶振这就取决于你所使用的单片机,由于我们使用的是 51 单片机,其时钟频率可在 0-40MHZ 上运行,一般情况下我们建议选择 12M(适合计算延时时间)或者是 11.0592M(适合串口通信)。若直接将此晶振接入单片机晶振引脚,会发现系统工作不稳定,这是因为晶振起振的一瞬间会产生一些电感,为了消除这个电感所带来的干扰,可以在此晶振两端分别加上一个电容,电容的选取需要无极性的,另一端需要共地。根据选取的晶振大小决定电容值,通常电容可在 10-33PF值范围内选取。我们使用的是 22PF 电容。这样一来就构成了晶振电路。只有保证晶振电路稳定,单片机才能继续工作。其电路如下所示:
(2)复位电路
复位电路是一种用来使电路恢复到起始状态的电路设备,它的操作原理与计算器有着异曲同工之妙,只是启动原理和手段有所不同。复位电路,就是利用它把电路恢复到起始状态。就像计算器的清零按钮的作用一样,以便回到原始状态,重新进行计算。复位电路工作原理如图所示,VCC上电时,使电容C充电,在10K电阻上出现高电位电压,使得单片机复位;几个毫秒后,C充满,10K电阻上电流降为0,电压也为0,使得单片机进入工作状态。工作期间,按下S22,C放电,放电结束后,在10K电阻上出现电压,使得单片机进入复位状态,直到S松手,C充电完毕,随后,单片机进入工作状态。
(3)串口下载电路
电路图如下:
在CH340的数据手册上有引脚的介绍以及作用:
这两个引脚:DTR#和RTS#都是 输出类型, MCUISP(一键下载工具)会控制CH340这两个引脚的高低电平状态。
DTR# | 输出 | MODEM联络输出信号,数据终端就绪,低(高)有效 |
RTS# | 输出 | MODEM联络输出信号,请求发送,低(高)有效 |
通过控制DTR#和RST#这两个引脚的高低电平状态,从而控制STM32的BOOT0 和 RESET.
用万用表测量可知,DTR#、RST#初始状态的时都是高电平,在启用下载的时候,DTR#维持高,RST#拉低,此时两个三极管Q2 和Q3 导通,那么BOOT0 为高电平,RESET为低电平复位,然后DTR#变低,Q2不导通,复位结束,此时BOOT0 为高电平。
由启动模式可知:
B00T0 | B00T1 | 启动模式 | 说明 |
X | 0 | 用户闪存储存器 | 用户闪存储存器,即FLASH启动 |
0 | 1 | 系统储存器 | 用于串口下载 |
1 | 1 | SRAM启动 | 用于在SRAM中调试代码 |
可知,stm32的启动模式变为从系统存储器启动,启用串口下载,STM32 和 MCUISP下载软件进行通信,进行代码下载,等到代码下载结束时 RST#先变为高电平,然后DTR#在变成高电平。 如果DTR#先变成高电平,那么会在一次产生复位。
(4)AD转换电路
AD转换电路使用ADS1115转换器。ADS1115包含输入多路复用器(MUX),可以测量四个单端或两路差分信号。这里使用AIN0和AIN1单端输入,电路板中留一个2p的排针,用来接入量程为5V的交变电源,最后检测得的电压值应为VAIN0-VAIN1。在检测电压读值的准确性时利用开关控制电路转为用DA模块产生电压,输入AIN0和AIN1。将AIN2和AIN3连接0.1μF电容并接地,SCL和SDA为输出端。引脚功能如图:
The ADS1115 resets on power-up and sets all bits in the Config register to their corresponding default settings. The ADS1115 resets on power-up and sets all bits in the Config register to their corresponding default settings. When the MODE bit in the Config register is set to 1, the ADS111x enters power-down state and operates in single-shot mode. Until 1 is written to the operating status (OS) bit in the Config register. When the OS bit is set, the device will power up within 25μs, reset the OS bit to 0, and begin a conversion. In continuous conversion mode (MODE bit set to 0), the ADS1115 performs conversions continuously. After the conversion is complete, the ADS1115 places the result in the conversion register and immediately begins another conversion.
ADS1115 communicates through the I2C interface. The I2C bus consists of two lines, SCL and SDA. SCL provides the clock and SDA carries data. SDA (serial data line) and SCL (serial clock line) are both bidirectional I/O lines. The interface circuit is an open-drain output and needs to be connected to the power supply VCC through a 10k pull-up resistor. 89C51 drives SDA and SCL as a host, and SDA and SCL are connected to the P2.6 and P2.7 ports of the host respectively. The ADDR pin is used to configure the I2C address of the device. This pin can be connected to GND, VDD, SDA or SCL.
The ADS1115 uses the address pointer register through the I2C interface to access the conversion register (contains the last conversion result), the Config register (change the operating mode and query the status of the device), the Lo_thresh and Hi_thresh registers (set the threshold for the comparator function). This circuit mainly uses conversion register and Config.
The full-scale range of the ADS1115 is configured by the gain amplifier controlled by Config's PGA[2:0]. This experiment requires detection of voltage values between 0 and 5V, so VDD of 5V is used, PGA[2:0] is set to 0x000, and the full scale is
6.144V, the data error is approximately 187.5μV.
(5) DA conversion circuit
The internal structure of DAC0832 is as shown below
CS* is the chip select signal, WR1* is the first signal (input), WR2* is the second signal (input), and XFER* is the data transfer control signal. The above signals are all active at low level. When the working mode of DAC00832 is pass-through mode, they can all be connected to ground. ILE is the data latch enable signal (input), which is active at high level, so it is connected to VCC externally. As shown below. DI0 to DI7 are conversion data inputs, which we correspond to the P0 port of the microcontroller. Through the data input of the P0 port, the voltage output can be controlled.
The 8-bit D/A conversion and operational amplifier are roughly as shown below
DAC output voltage calculation formula: V0=Vref*z/256
z in the formula represents the digital quantity given by the microcontroller, vref is the reference voltage, usually we connect it to the system
On the power supply, that is, 5V, the value 256 means that the DAC accuracy is 8 bits.
Simulation circuit diagram (including AT89C51, independent buttons, AD module, DA module, LCD1602, crystal oscillator circuit):
Since Keil does not have the simulation component ADS1115 chip, it uses another ADS1015 chip with similar functions instead. The functions of the two chips are basically the same, except for some default register settings, so it does not affect the implementation of the experimental functions.
Test Results:
Through division of labor, our team is responsible for different modules such as programming and simulation. The functions finally implemented in our simulation results are: memoryless mode and memory mode of ADS1015, and the detection circuit of DAC0832.
The simulation results this time did not reach the initial expected results. Unfortunately, the accuracy of the voltage value collected by ADS1015 was not well controlled. There is a large gap between the output voltage value and the real voltage value. We will continue to review the data and rewrite it. Code and schematics to try to solve this problem.
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet