introduction
In the design process of automatic control products, the choice of implementation scheme is often very contradictory. Using programmable logic controller (PLC) and human-machine interface (HMI) to achieve development is fast, but the cost is too high, and the developed products are not competitive in the market; using single-chip microcomputer development is low-cost, but the development cycle is long, the development volume is large, and the versatility is poor. Users need a controller with low cost, short development cycle, and good versatility, so full-function industrial controllers have a large application market.
The entire circuit of the full-function industrial controller is divided into signal isolation input part, controller output part, real-time clock and historical data storage part, color LCD display and touch screen control part, communication interface, etc.
1 Signal isolation input circuit
The signal isolation input circuit is divided into switch quantity isolation input, analog quantity isolation input, and high-speed electric pulse isolation input. The circuit is shown in Figure 1. The switch quantity isolation input is relatively simple. The input signal is isolated by optical coupler and then sent to the ordinary I/O of the single chip. The single chip microcomputer collects the data by query.
Figure 1 Signal isolation input circuit
When collecting high-speed electrical pulses, it should be noted that the designed circuit must meet the requirements of high-speed signal collection, so the isolation optocoupler should use a high-speed optocoupler (such as 6N137, etc.). Collecting high-speed pulses in a query manner is prone to loss of collected data, so high-speed pulses should be collected in an interrupt manner.
Analog quantity isolation acquisition is a key and difficult point of this controller. The author has previously used linear optocouplers and other methods to perform analog quantity isolation acquisition experiments, but none of them achieved satisfactory results. Here, a method is used to digitize the analog quantity first (using AD7705), and then send it to the CPU through an optocoupler-isolated data port for analog quantity isolation acquisition, which has an ideal effect.
2 Controller output circuit
The output modes of the controller include relay output, transistor output, and analog voltage output, as shown in Figure 2. The relay output and transistor output circuits are relatively simple and will not be introduced in detail here. The following focuses on the principle of generating analog voltage.
Figure 2 Controller output circuit
The output of analog voltage is mainly realized by PWM port of ATmega128. The PWM output pulse is isolated by optocoupler and then filtered to generate the required DC signal. In order to improve the driving ability, an emitter follower is added, as shown in the upper half of Figure 2.
The procedure for implementing PWM voltage regulation is as follows:
#define PWM1_IN(){DDRB.5=1;PORTB.5=0;}//PWM port control
#define PWM1_OUT() DDRB.5=1;
/**********************
PWM initialization procedure:
Use TIMER1, set the prescaler to 8, set the 10-bit fast PWM mode, and disable the interrupt
**********************/
void pwm_init(void){
TIMSK&=0xC3; //Disable TIMER1 interrupt
ETIMSK&=0xFE;
TCCR1A=0; //Turn off the timer
TCCR1B=0;
OCR1A=0x0000; //Turn off output
OCR1B=0x0000;
TCCR1A=0xA3; //Set 10-bit fast PWM
//Mode, pre-scaling is 8
TCCR1B=0x0A;
PWM1_IN()
}
/*******************************
PWM channel control program: Function: can switch and adjust the output of a single channel
Entry parameter - b is channel control (1 - change value, 2 - open port, 3 - close port); [page]
c is the PWM change value
***************************/
void pwm(unsigned char b,unsigned int c){
switch(b){
case 1://Change PWM1 value
if(c<=0x03FF)OCR1A=c;
break;
case 2://Open PWM1 port
if(c<=0x03FF)OCR1A=c;
PWM1_OUT()
break;
Case 3://Close PWM1 port
OCR1A=0x0000;
PWM1_IN()
break;
}
}
3 Real-time clock and historical data storage module
Many industrial controllers need to record relevant data before shutting down so that the previously set parameters can be used next time they are turned on; some working data also need to be saved in real time to ensure that they are not affected by accidents such as power failure. Using EEPROM for storage has slow reading and writing speeds and is limited by the number of uses; using ferroelectric memory can achieve this, but it generally has a small capacity and a high price.
Industrial control operations are often associated with the current real-time clock, which is a very important component in industrial controllers.
The DS1642 from Dallas, USA, combines the real-time clock and historical data storage into one, and the price is also relatively moderate. The circuit connection method is shown in Figure 3.
DS1642 contains a 2K×8 non-volatile SRAM and a real-time clock/calendar, as well as an embedded crystal oscillator and lithium battery. The access method of the clock register and memory register of DS1642 is the same as that of ordinary RAM, and the timing register adopts a double buffering method to ensure uninterrupted timing during the memory access process. When the power monitoring circuit detects power failure, DS1642 will turn on the internal power supply to ensure that the time is kept and the memory data is not damaged, with an accuracy of up to 1 min/month. For details, please refer to the relevant data sheet.
4 color LCD display module
The color LCD display function is realized by directly using the ZTCOLOR3 color LCD driver module of Shenzhen Zhongtian Yuehua Automatic Control Technology Co., Ltd. The circuit interface is shown in Figure 3.
The module is very simple to use, and it has functions such as data refresh. When the displayed image does not change, the microcontroller does not need to operate the module; when the display interface needs to be changed, data can be written in the register. (See the manufacturer's instruction manual for details)
Figure 3 Clock and data storage and LCD display module connection circuit,
5 Touch screen control module
The touch screen uses a four-wire resistive touch screen, and uses the A/D port of ATmega128 to sample the voltage value of each touch point of the touch screen after power is turned on, so as to determine the user's touch position and perform corresponding operations. The circuit is shown in Figure 4.
Figure 4 Touch screen control module circuit
The specific implementation procedures are as follows:
#define TX1_0(){PORTE.3=1;DDRE.3=1;}
#define TY1_1(){PORTE.5=0;DDRE.5=1;}
#define TY1_0(){PORTE.5=1;DDRE.5=1;}
#define TX0_1(){PORTE.4=1;DDRE.4=1;}
#define TX0_0(){PORTE.4=0;DDRE.4=1;}
#define TY0_1(){PORTE.6=1;DDRE.6=1;}
#define TY0_0(){PORTE.6=0;DDRE.6=1;}
#define TINT_IN() {DDRE.7=0;} //Touch screen interrupt port is input mode
#define TINT_INPUT PINE.7
#define TADX_IN(){DDRF|=1;PORTF&=0xFE;delay_us(50);DDRF&=0xFE;}//Touch screen ADC port is input mode#define TADY_IN(){DDRF|=2;PORTF&=0xFD;delay_us(50);DDRF&=0xFD;}
/******************************
Touch screen initialization: Initialize the touch screen four-wire port, initialize the touch screen interrupt port, initialize the ADC port
******************************/
void touch_init(void){
unsigned char i;
TX1_0() //Initialize the four-wire port
TX0_0()
TY1_1()
TY0_0()
TINT_IN() //Touch screen interrupt port is input mode
EICRB|=0xC0; //Set INT7 to rising edge trigger and clear interrupt
// Flag, open interrupt
EIFR|=0x80;
EIMSK|=0x80;
TADX_IN() //Set the touch screen ADC port as input
TADY_IN()
}[page]
/******************************************
INT0 interrupt program (touch screen data acquisition program)
Use interrupt mode to perform A/D conversion in the interrupt program to read the touch screen data
*************************************/
interrupt[9] int7_touch(void){ //Touch screen data acquisition program
touch_int();
TADY_IN()
TADX_IN()
TX1_0() //Start ADC to convert Y-axis data
TX0_0()
TY0_1()
TY1_1()
delay_us(400);
for(i=0;i<15;i++){
ADCSRA=0xA3;
ADMUX=0x41;
ADCSRA|=0x40;
while(!ADCSRA.4){;}
touch_ydata[i]=ADC&0x03FF;
}
TY1_0() //Start ADC to convert X-axis data
TY0_0()
TX1_1();
TX0_1()
delay_us(400);
for(i=0;i<15;i++){
ADCSRA=0xA3;
ADMUX=0x40;
ADCSRA|=0x40;
while(!ADCSRA.4){;}
touch_xdata[i]=ADC&0x03FF;
}
EIMSK&=0x7F;
//Once data reception is completed, turn off interrupt
TX1_0()
TX0_0()
TY1_1()
TY0_0()
TINT_IN()
TADX_IN()
TADY_IN()
EIFR|=0x80;
// Clear the interrupt flag
TADY_IN()
TADX_IN()
}
6 Communication Interface
The controller communication interface is an RS485 interface with noise immunity, long-distance transmission and multi-station connection capabilities. It is implemented by using the single-chip microcomputer serial port through optical coupling isolation and then through the Maxim RS485 chip. It is mainly used for networking and convenient communication with the host computer. The specific circuit is shown in Figure 4.
Conclusion
The full-function industrial controller introduced in this article has high versatility and has been used in mass production. The relevant circuits and programs have been verified and can be directly quoted.
Previous article:Design of Natural Gas Engine System Based on AVR Single Chip Microcomputer
Next article:Atmel QTouch-based ATmega48 sensor button design
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- I'm begging for the full datasheet of the Marvell 88e6171/6175 switch chip
- [Vote] Is it harder to read code or write code? Let’s talk about it
- 【GD32307E-START】DAC+ADC test
- EZ-BLE PRoC Low Power Bluetooth Module Introduction
- Can someone help me analyze what this circuit does?
- Ding~ You have a review information waiting to be received~ Please open this post to view
- Simple stopwatch based on MSP430f149 MCU
- New Edition of Electrical Control and PLC Application Technology
- Notes on Foobar2000 APE Splitting
- Op amp circuit waveform analysis problem