Analog isolation acquisition based on ATtiny13

Publisher:温雅如风Latest update time:2009-12-25 Source: 单片机与嵌入式系统Keywords:Isolation Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Overview

In industrial control applications, analog signal acquisition usually requires isolation technology to prevent power and ground line fluctuations caused by the start-up or switching of large electrical equipment from affecting weak current control systems. Common analog isolation methods include isolation amplifiers, electromagnetic isolation, and photoelectric isolation. Isolation amplifiers have good accuracy but high cost; electromagnetic isolation has large equipment size and poor accuracy.

Photoelectric isolation technology is a very effective anti-interference method. Optocouplers are common photoelectric isolation devices and are mainly used for digital quantity isolation transmission. If optocouplers are used to transmit analog quantities, the nonlinearity of the optocouplers must be very small to ensure the linearity of the input analog signal, which is difficult to achieve for most optocouplers. In order to achieve photoelectric isolation acquisition of analog quantities, analog/digital (A/D) conversion must be performed first before the converted digital quantity can be passed to the next level circuit via the optocoupler.

The traditional method is to directly use A/D chips for analog/digital conversion, and then transmit through optocouplers. According to the interface form, A/D chips can be divided into two types: parallel and serial access. The higher the acquisition accuracy of the parallel A/D chip, the more optocouplers are occupied by the parallel data line, and it is necessary to match the corresponding isolation signal to control the A/D conversion operation. This method has more wiring and occupies more resources; the serial A/D chip can save a lot of optocouplers, but it requires complex timing to complete the A/D read and write operations.

This paper proposes a method of using the micro single-chip microcomputer AT-tiny13 with integrated A/D for analog quantity isolation acquisition, and uses a single data line to complete data transmission. The analog quantity isolation acquisition adopts a simplified UART communication method, that is, a simplex communication method, which only requires a send line TXD and no receive line RXD. In this way, a single data line can undertake the task of sending A/D conversion values, and the receiver can easily obtain the isolated analog value as long as it has a hardware UART or software UART (receive).

2 ATtiny13 Introduction

ATtiny13 has 1 KB Flash, 64 bytes of EEPROM, 64 bytes of SRAM, 6 general-purpose I/O lines, 32 general-purpose working registers, an 8-bit timer/counter with compare mode, internal/external interrupts, and 4-channel 10-bit ADC.

3 Hardware Design

The analog isolation acquisition circuit is shown in Figure 1. ATtiny13 has two 10-bit ADCs that can be controlled and selected. Only one ADC is used in this design. Optocoupler PC817 is used to transmit A/D conversion values. CLKI represents the clock source introduced from the outside.

Analog isolation acquisition circuit

4 Software UART

ATtiny13 does not have an integrated UART function. To make up for this defect, the software can be used to control the I/O pins to simulate the UART function and output the A/D conversion value through optocoupler isolation according to the set acquisition rate.

4.1 Asynchronous Serial Protocol

When using UART asynchronous serial protocol communication, data is output bit by bit in sequence. The receiver determines the start and end of a frame of information by monitoring the start bit (low level is valid) and the stop bit (high level is valid). The data frame can also include several data bits and parity bits. The start bit and stop bit of the asynchronous serial protocol must be used, and the remaining bits can adjust the bit length. The format of the asynchronous serial protocol is as follows:

Asynchronous serial protocol format

This article defines the frame format as: start bit (1 bit), data bit (5 bits), no parity bit, stop bit (1 bit). ATtiny13 has a built-in A/D converter with a precision of 10 bits, and the data bit is set to 5 bits wide, so it is necessary to send two asynchronous serial communication frames in succession to transmit a complete A/D conversion value. According to the high-bit first-out method, the high 5 bits of the A/D conversion value are sent first, and the low 5 bits are sent next.

4.2 Baud rate setting

Baud rate is a very important parameter in UART asynchronous serial communication. Both parties must communicate at an agreed rate to ensure successful communication. Baud rate is closely related to the time occupied by a "bit" in the asynchronous serial protocol. For binary signals, the time occupied by each bit in the data frame is the reciprocal of the baud rate. Therefore, how to accurately determine the time width of each bit becomes a key factor in ensuring the success of serial communication.

ATtiny13 does not have an integrated UART, but it has an 8-bit timer/counter inside, which can be controlled by software to generate baud rate. The MCU's built-in RC oscillator can be used as a clock source, but the oscillation frequency has a maximum error of ±10% and is greatly affected by temperature. This will cause an unstable baud rate, and data may not be received during communication, or data bits may be lost, garbled characters, and wrong codes may appear. ATtiny13 introduces a 7.372 8 MHz active crystal oscillator clock signal from the outside, thereby ensuring the stability of the main clock frequency.

The asynchronous communication baud rate can be calculated according to formula (1).

formula

Where: XTAL is the main clock frequency introduced; Baud is the baud rate to be set; C is the timer clock division factor; n is the preloaded comparison value of the 8-bit timer/counter. The timer/counter works in CTC mode (clear the timer when compare match).

XTAL is 7.3728 MHz, Baud is set to 9600, and the timer clock signal is divided by 4 of the main clock (i.e. C=4), so n=192. Therefore, when the 8-bit timer/counter counts from 0 to 192, a comparison interrupt is generated, and the software controls the sending of a new bit of information.

4.3 Data transmission

The UART asynchronous serial protocol stipulates that when there is no data frame to be sent, the logic "1" indicates that it is currently in an idle state. If there is data to be sent, first pull the transmit line TXD down to logic "0" and keep it for a basic time unit; then output it bit by bit in sequence according to the binary value of the data to be sent. The parity bit is not used in this design, and the related processing is omitted. After the 5-bit data is sent, TXD is immediately pulled up to logic "1" to indicate the end of the frame. The software UART sending process is shown in Figure 2.

Software UART sending process

The function Uart_SendByte(unsigned char data) implements the above function and sends 5 bits of data at a time. In the analog isolation acquisition, the microcontroller continuously obtains the A/D conversion value and sends it out by calling the above function.

Conclusion

This article introduces an analog isolation acquisition circuit based on ATtiny13. Due to the limitations of the maximum sampling rate of ADC and the transmission bandwidth of optocoupler PC817, it is only suitable for analog signals with slow frequency conversion. The circuit is small in size, low in cost, and simple in wiring. It has been used for finished switching power supply detection.

Keywords:Isolation Reference address:Analog isolation acquisition based on ATtiny13

Previous article:Design of earthquake information acquisition module based on ADS1255
Next article:Improve the accuracy of analog-to-digital converters and reduce system costs

Recommended ReadingLatest update time:2024-11-16 21:28

element14 launches sales of Analog Devices multi-channel system clock devices
Shanghai, China, April 21, 2023 – element14, a global distributor of electronic component products and solutions owned by Avnet, announced the launch of Analog Devices’ AD-SYNCHRONA14-EBZ multi-channel system clock device. The AD-SYNCHRONA14-EBZ is a stand-alone device ideal for evaluation and prototyping of applicati
[Network Communication]
element14 launches sales of Analog Devices multi-channel system clock devices
ATtiny13 I/O Memory
ATtiny13 I/O P150 "Register Overview". All ATtiny13 I/O and peripherals are placed in I/O. I/O locations can be accessed through LD/LDS/LDD and ST/STS/STD instructions to transfer data between 32 general working registers and I/O. I/O registers with addresses 0x00 - 0x1F can also be directly bit-addressed using SBI a
[Microcontroller]
Latest Analog Electronics Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号