Correction Method of Internal RC Oscillator of AVR Single Chip Microcomputer

Correction method of internal RC oscillator of AVR single chip microcomputer

AVR MCU has an internal RC oscillator. The correction of the internal oscillator has always been a difficult problem. Due to the trouble of this problem, many normal programs cannot work normally. This document is hereby sorted out for customers' reference. If you need English, you can download it from ATMEL's official website.

Feature L            Stk500, avrisp, jtage or jtage MKII can be used to correct L            A third-party programmer can be used to correct L            Adjust RC frequency to / - 1% accuracy L            Adjust the RC oscillator l at any voltage and temperature            Adjust the RC oscillator to the specified frequency L            Support all AVR microcontrollers with RC oscillator L            Oscillator clock frequency can be selected   This application note explains the method of quickly and accurately correcting the internal RC oscillator. It provides easy to modify firmware source code, which can be used in any AVR MCU with internal adjustable RC oscillator. This firmware allows the use of AVR stk500, avrisp or jtagice, but can also be used in third-party systems (such as programmers).   Most AVR microcontrollers provide internal RC oscillators. The frequency of this RC oscillator can be corrected to / - 1%. This feature provides greater flexibility and cost savings.   In ATMEL's factory, the correction is carried out at a fixed voltage and temperature (typically 25 ° C and 5V), while the frequency of the internal RC oscillator is affected by both temperature and voltage, which makes the user may need to correct again in a specific application environment. Re correction can obtain higher accuracy, match specific voltage or temperature, and even adjust to a completely different frequency.   The correction method described in this application note takes only a little longer than reading the factory correction byte from the signature and writing it back to the device. The total programming time is hardly affected by the correction.   Note that in some systems, the operation time is very dependent, which indicates that an accurate voltage independent system clock is required in the whole temperature range in the application. In this case, a watch crystal can provide a reliable and low-cost solution.   There is a quick start guide at the end of this document.   Operating theory - internal RC oscillator in the product, the internal RC oscillator is corrected at 5V or 3.3V. Factory corrected accuracy is / - 3 or / - 10% (refer to the data manual). If a design requires higher accuracy than the factory standard correction, the RC oscillator needs to be corrected again, so that an accuracy of about / - 1% ( / - 2% for devices with factory correction accuracy of / - 10%) can be obtained.   The setting of clock selection AVR fuse controls the clock source used by the system. In order to use the internal RC oscillator, the correct fuse needs to be selected. The fuse settings that can be used are described in the data book.   Basic frequency the following section gives the description of the internal RC oscillator of AVR MCU.   Some AVR microcontrollers have an RC oscillator, others have four different RC oscillators to choose from, and the frequency range is from 1MHz to 9.6mhz. The crystal correction register: sccal (defined in the IO header file) is used to correct the internal RC oscillator. Osccal register is a byte width, which can fine tune the system frequency. This fine tuning is used to correct the RC oscillator.   When the MCU is corrected by ATMEL, the correction byte is stored in the signature of the MCU. The correction bytes of different chips may vary greatly, because the RC oscillator is related to the process and has a certain discreteness. If the chip has more than one oscillator, each oscillator corresponds to a correction byte.   The default RC correction byte of most MCU is automatically loaded from the signature and copied to the osccal register when reset. For example, the default clock setting of ATmega8 is the internal 1MHz RC oscillator; The corresponding 1MHz correction byte is loaded automatically after reset. If the fuse is changed to a 4MHz oscillator, the correction byte needs to be manually loaded into the osccal register. The programming tool can read 4MHz correction bytes from the signature and forcibly store them in flash or EEPROM, and then read them by the user program at run time and copy them into the osccal register.   In order to easily use osccal register to adjust the oscillator, some MCU can set the pre frequency division clock of the system. The pre frequency division register (clkpr) can scale the system clock with predefined coefficients. Similarly, this prescaler can be preset through the fuse; Programming ckdiv8 fuse sets clkpr system clock frequency division 8. This ensures that the chip operates below the maximum frequency, and clkpr can be modified at runtime.   The basic frequency is defined as undivided.   RC oscillator summary AVR MCU uses different RC oscillators in different periods. A review of RC oscillators is shown in Table 1. The list of chips is sorted by oscillator type and almost by release time. Only the chips that can adjust the oscillator are listed in the table.

Table 1. Chip features with internal RC oscillator. Oscillator version device RC oscillator frequency ckdiv prsck 1.1 attiny12 1.2 -- 1.2 attiny15 1.6 -- 2.0 atmega163 1.0 -- 2.0 atmega323 1.0 -- 3.0 ATmega8 1.0, 2.0, 4.0 and 8.0 -- 3.0 ATmega16 1.0, 2.0, 4.0 and 8.0 -- 3.0 Atmega32 1.0, 2.0, 4.0 and 8.0 -- 3.1 atmega64 1.0, 2.0, 4.0 and 8.0 - xdiv (1) 3.1 ATmega128 1.0, 2.0, 4.0 and 8.0 - xdiv (1) 3.0 atmega8515 1.0, 2.0, 4.0 and 8.0 -- 3.0 atmega8535 1.0, 2.0, 4.0 and 8.0 -- 3.0 atmega26 1.0, 2.0, 4.0 and 8.0 -- 4.0 Atmega162 8.0 is 4.0 atmega169 (2) 8.0 is 4.0 atmega165 8.0 is 4.1 atmega13 4.8 and 9.6 is 4.2 atmega2313 4.0 and 8.0 is 5.0 atmega48atmega88atmega168 8.0 is 5.0 atmega25atmega45atmega85 8.0 is 5.0 atmega325atmega3250atmega645atmega6450 8.0 is 5.0 atmega329atmega3290atmega649atmega6490 8.0 is 5.0 at90can128 8.0 is 5.0 at90pwm290pwm3 8.0 Yes, yes

Correction Method of Internal RC Oscillator of AVR Single Chip Microcomputer 1

empfohlene Artikel
Info. Wissen Nachrichten
Design of Digital Voltmeter Control System Based on AT89C51 Single Chip Microcomputer
Design of Digital Voltmeter Control System Based on AT89C51 Single Chip Microcomputer
introductionDigital voltmeter is the core and foundation of many digital instruments. The digitization of voltmeter is to convert continuous analog quantity such as DC voltage into discontinuous discrete digital form and display it, which is different from the traditional method of reading with pointer and dial, and avoids reading parallax and visual fatigue. At present, the internal core component of the digital multimeter is the A / D converter. The accuracy of the converter greatly affects the accuracy of the digital multimeter. In this paper, the aid converter uses ADC0809 to convert the input analog signal, the control core at89c51n calculates and processes the conversion result, and finally drives the output device to display the digital voltage signal.Hardware circuit design of digital voltmeterThe hardware circuit design mainly includes: 89C51 single chip microcomputer system, d conversion circuit and display circuit. The measured maximum voltage is 5V and the displayed maximum value is 5.00V. Figure L is the hardware circuit schematic diagram of digital voltmeter.1.1 89C51 single chip microcomputer system and display circuitDue to the small volume, light weight and cheap price of single chip microcomputer, the system adopts 89C51 single chip microcomputer, and its schematic diagram is shown in Figure 1.89C51 has 4KB EEPROM and 128 bytes ram inside, so it is generally expanded according to the storage capacity required by the system, ROM and ram. This circuit / EA is connected to high level, and there is no expansion of off chip ROM and ramP1, P3.0 p3.3 ports of 89C51 are used as four digit LED nixie tube display control. P3.5 port is used as single channel display / cyclic display conversion button, and P3.6 port is used as channel selection when single channel display. Port P0 is used for reading a / D conversion data of 0809, and port P2 is used for a / D conversion control of 0809.1.2 A / D conversion circuitFig. 1 circuit schematic diagram of digital voltmeterThe A / D conversion is completed by the integrated circuit 0809. 0809 has 8 analog signal input ports, and the address line (23 25 pins) can determine which analog signal to perform a / D conversion. Pin 22 is address latch control. When the input is high, it latches the address signal. Pin 6 is the test control. When a 21xs wide high-level pulse is input, the A / D conversion starts. Pin 7 is the A / D conversion end flag. When the A / D conversion ends, pin 7 outputs high level. Pin 9 allows control of a / D conversion data output. When OE pin is at high level, a / D conversion data is output from this port. Pin 10 is the clock input terminal of 0809. The 1MHz clock is obtained by using the six frequency crystal oscillator frequency of pin 30 of the single chip microcomputer and the two frequency division of 14024.2 software design of digital voltmeter systemThe flow chart of main program and a / D conversion measurement program is shown in Figure 2.2.1 initialization procedureWhen the system is powered on, the initialization program clears the 70h 77h memory unit to 0, and the P2 port is set to 0. By default, the system circularly displays the voltage values of 8 channels. After a measurement, the A / D conversion value of each channel will be displayed, and the display time of each channel is 1s. The 70h 77h memory unit stores the sampling value, and the 78h 7bh memory unit stores the display data, which are individual bits, ten bits, hundred bits and channel flag bits in turn.2.2 A / D conversion subroutineThe A / D conversion subroutine is used to control the A / D conversion of 0809 / K analog input voltage, and store the corresponding value in 70h 77h memory unit.2.3 display subroutineThe display subroutine adopts dynamic scanning to realize the numerical display of four digit nixie tube. During display, the measured data shall be converted into BCD code and placed in 78h 7bh memory unit, where 7bh stores the number of channel flags.R3 is used as 8-way cycle control, and R0 is used as display data pointer.3 conclusionThe digital voltmeter can measure 8 voltage values of 0 5. 89C51 is an 8-bit processor. When the input voltage of 0809 is 5.00V, the output data is 255 (FFH). Therefore, the maximum resolution is o.0196v (5 / 255). In order to obtain higher accuracy requirements, 12 bit and 13 bit a / D converters should be used. The digital voltage display may have deviation, which can be solved by correcting the reference voltage of 0809, or correcting the measured value by software programming.The digital voltmeter control system is composed of single chip microcomputer 89C51. It has the characteristics of high precision, fast speed, stable performance, simple circuit and reliable operation.
Design of Alcohol Content Detector Based on Single Chip Microcomputer
Design of Alcohol Content Detector Based on Single Chip Microcomputer
introductionAt present, almost all countries use breath alcohol tester to detect drivers on the spot to determine whether the measured drivers drink. This paper presents an alcohol detection and safety control system. The system is installed on the car. It can judge whether the driver drives after drinking without traffic police and other personnel, so as to ensure the safety of the driver and reduce the workload of traffic police and other personnel. At the same time, it can make independent judgment according to whether the alcohol content exceeds the standard, and can control the ignition switch of the car, so that the drinking driver can not start the car.1. Overall scheme designThe system uses the driver's active exhalation method to judge whether the driver is driving after drinking. The overall scheme design is shown in Figure 1. The system can be placed on the instrument panel of the car. When the driver starts the car, the alarm device will sound to remind the driver to use the alcohol detection and safety control system. At this time, the engine is locked and the car cannot be started. After the alcohol sensor is heated, the green light of the system indicator module lights up to prompt the driver to exhale. In order to prevent the driver from escaping the detection, a microphone is set as the exhalation judgment device. When the exhalation is confirmed, the MCU sends a trigger signal to detect the gas signal detected by the alcohol sensor. Since the alcohol content is proportional to the voltage signal generated by the alcohol sensor, the alcohol content can be judged according to the voltage signal. After the detection signal is amplified and filtered by the amplification and detection circuit, it is converted into a digital signal through the A / D conversion circuit, which is processed and judged by the single chip microcomputer. Assuming that the alcohol content does not exceed the standard, the indicator light is on, the control relay does not work, and the bus can be started; On the contrary, the over standard indicator lights up and the alarm device sounds at the same time, indicating that the vehicle cannot drive. If the driver forcibly starts, the control relay cuts off the power supply of the ignition device, so that the vehicle cannot drive, so as to realize the function of controlling drunk driving.2 hardware designThe hardware design adopts the independent structure of transmitting part and receiving part, which separates the detection and control system.2.1 launching partThe transmitting part is powered by battery, with 89C2051 single chip microcomputer as the control core, equipped with qm-j3 gas sensitive alcohol sensor, expiratory microphone, 8-bit A / D converter ad0809 and transmitting module f04e. The main function is to detect the alcohol content, judge whether it exceeds the standard, and send a signal to the receiving part. The principle block diagram is shown in Figure 2, which is composed of the following modules:2.1.1 alcohol content detection moduleThe module includes alcohol sensor, detection, amplification circuit and a / D conversion circuit. Qm-j3 gas sensor is selected as the alcohol probe, which is an n-type semiconductor with composite metal oxide as the main material. When exhaling, once the element contacts the ethanol vapor, its conductivity increases rapidly with the increase of gas concentration, so that the generated voltage signal also increases. After the voltage signal is converted into digital quantity by detection, amplification circuit and a / D conversion circuit, it is sent to the single chip microcomputer for threshold judgment to detect whether the alcohol content in the driver's exhaled gas exceeds the standard.2.1.2 expiratory judgment moduleIn order to prevent the alcohol sensor from correctly detecting the real alcohol content in the driver's body due to the driver's non exhalation, the module is set to judge whether the driver exhales. When using the microphone to exhale, the microphone must generate a pulse signal. The single chip microcomputer judges the driver's exhalation, and then detects the signal sent by the alcohol probe.2.1.3 indication moduleThe module has three red, green and yellow indicators. The red light is the power indicator, which is on during operation; The green light is the exhalation prompt light. The alcohol probe needs a certain time to heat up in order to achieve the ideal sensitivity.When the heating time is up, the green light is on, indicating that you can exhale; The yellow light indicates that the exhalation is effective. When the yellow light is not on, it indicates that the exhalation is insufficient. Until the yellow light is on, the single chip microcomputer starts to detect the signal sent by the alcohol probe.2.1.4 single chip microcomputer89C2051 single chip microcomputer of 51 series is selected as the processor to detect the expiratory judgment signal and judge the alcohol content in the gas, and generate the corresponding information code to send to the transmitting equipment.2.1.5 transmitting moduleThe mature f04e transmitting module is adopted, which can be directly connected with the single chip microcomputer to modulate the information code given by the processor and send it to the receiving part wirelessly.2.2 receiving partThe receiving part is installed on the vehicle, mainly to judge the received signal code and make corresponding operations. After receiving the error code, return to continue detection; After receiving the code Exceeding the standard, the alarm sound prompts, the ignition device is disconnected, the car headlights are on, and the horn sounds; After receiving the code that does not exceed the standard, a driving prompt sound is sent out, and the ignition device is turned on. The structure block diagram is shown in Figure 3, which can be divided into the following modules:
Production of LED Meteor Shower Lamp (51 Single Chip Microcomputer Program Code)
Production of LED Meteor Shower Lamp (51 Single Chip Microcomputer Program Code)
This paper mainly introduces the manufacturing principle of LED meteor shower lamp, including finished product pictures, circuit schematic diagram and the program code of 51 single chip microcomputer.1、 Picture sharing:2、 PCB file sharing:3、 Schematic sharing:Only 5 lamps are made above. If you need to add lamps, you only need to change the following procedure slightly. If growthThe effect of connecting the light tube into a circle or square is also awesome.The diameter of this meteor lamp is only 1.5cm. It can only make 30cm, 50cm, 80cm, 1000cm, etc.The program code can be modified at will, but it can not be used for commercial purposes./*Meteor shower program codeMCU model: stc11f04 16 IO ports! Principle:Using PWM to simulate meteor shower: the brightness level is divided into 8, the meteor shower effect is achieved by changing the brightness of each group of LEDs.(because the meteor shower is brighter in front and darker in the back, just like a dragon dragging its tail),Complete program source code download:*/#Include reg52. H / / MCU header file#Define uchar unsigned char / / word floating macro definition#Define uint unsigned int / / integer macro definition#Define Shudu 3 / / LED gradient speed adjustmentuchar yin0 =31;// Led change level adjustmentuchar yin1 =63;// Led change level adjustmentuchar yin2 =95;// Led change level adjustmentuchar yin3 =127;// Led change level adjustmentuchar yin4 =159;// Led change level adjustmentuchar yin5 =191;// Led change level adjustmentuchar yin6 =223;// Led change level adjustmentuchar yin7 =255;// Led change level adjustmentsbit led0=P3^5;// 16 IO portssbit led1=P3^6;sbit led2=P3^0;sbit led3=P3^1;sbit led4=P3^2;sbit led5=P3^3;sbit led6=P3^4;sbit led7=P3^7;sbit led8=P1^0;sbit led9=P1^1;sbit led10=P1^2;sbit led11=P1^7;sbit led12=P1^6;sbit led13=P1^5;sbit led14=P1^4;sbit led15=P1^3;uchar d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15;// Variable of each IO port/***************************************************//**********************Delay subroutine*******************//***************************************************/void delay(uint z)Uint x, y; / / local variable definitionFor (x = 0; x 5; X ) / / delayed outer loopFor (y = 0; Y Z; y ); / / delayed inner loop/**********************************************//**********PWM controls the on-off time of red, green and blue lights**********//**********************************************/Void rgbpwm (uchar d0, uchar D1, uchar D2, uchar D3, uchar D4, uchar D5, uchar D6, uchar D7, uchar D8, uchar D9, uchar D10, uchar D11, uchar D12, uchar D13, uchar D14, uchar D15) / /if(d0!=0)led0=0;delay(d0);led0=1;//1if(d1!=0)led1=0;delay(d1);led1=1;//1if(d2!=0)led2=0;delay(d2); //2led2=1;if(d3!=0)led3=0;delay(d3);led3=1;//3if(d4!=0)led4=0;delay(d4);led4=1;//4if(d5!=0)led5=0;delay(d5);led5=1;//5if(d6!=0)led6=0;delay(d6);led6=1;//6if(d7!=0)led7=0;delay(d7);led7=1;//7if(d8!=0)led8=0;delay(d8);led8=1;//8if(d9!=0)led9=0;delay(d9);led9=1;//9if(d10!=0)led10=0;delay(d10); //10led10=1;if(d11!=0)led11=0;delay(d11);led11=1;//11if(d12!=0)led12=0;delay(d12);led12=1;//12if(d13!=0)led13=0;delay(d13); //13led13=1;if(d14!=0)//14led14=0;delay(d14);led14=1;if(d15!=0)//15led15=0;delay(d15);led15=1;/***********************************************//********************Main program*********************//***********************************************/void main()TMOD=0x01;EA=1;ET0=1;TR0=1;TH0=(65536-56)/256;TL0=(65536-56)%256;While (1) / / program main loopRgbpwm (d0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15); / / call the rgbpwm subroutine/*************************************************//*Interrupt service subroutine (control the duty ratio of LED red, green and blue on and off time)*//*************************************************/Void zhong() interrupt 1 / / the interrupt vector bit is 1Uint num; / / timer count variableUint Ji; / / brightness level control variableTh0 = (65536-500) / 256; / / assign value to the upper 8 bits of the timerTl0 = (65536-500)% 256; / / assign a value to the lower 8 bits of the timerNum ; / / automatically increase the timing count by 1If (Num = = Shudu) / / if the speed variable is equal to the timing counter variable, execute the following brace statementNum = 0; / / clear the counter to 0Ji ; / / add 1 to the brightness level control variableIf ((Ji "0) & & (Ji" 10)) / / shift mobile pipelined0=yin7;d1=0;d2=0;d3=0;d4=0;d5=0;d6=0;d7=0;d8=0;d9=0;d10=0;d11=0;d12=0;d13=0;d14=0;d15=0;if((ji》10)&&(ji《20))//23456789d0=yin6;d1=yin7;d2=0;d3=0;d4=0;d5=0;d6=0;d7=0;d8=0;d9=0;d10=0;d11=0;d12=0;d13=0;d14=0;d15=0;if((ji》20)&&(ji《30))//345678910d0=yin5;d1=yin6;d2=yin7;d3=0;d4=0;d5=0;d6=0;d7=0;d8=0;d9=0;d10=0;d11=0;d12=0;d13=0;d14=0;d15=0;if((ji》30)&&(ji《40))//4567891011d0=yin4;d1=yin5;d2=yin6;d3=yin7;d4=0;d5=0;d6=0;d7=0;d8=0;d9=0;d10=0;d11=0;d12=0;d13=0;d14=0;d15=0;if((ji》40)&&(ji《50))//12345678d0=yin3;d1=yin4;d2=yin5;d3=yin6;d4=yin7;d5=0;d6=0;d7=0;d8=0;d9=0;d10=0;d11=0;d12=0;d13=0;d14=0;d15=0;if((ji》50)&&(ji《60))//23456789d0=yin2;d1=yin3;d2=yin4;d3=yin5;d4=yin6;d5=yin7;d6=0;d7=0;d8=0;d9=0;d10=0;d11=0;d12=0;d13=0;d14=0;d15=0;if((ji》60)&&(ji《70))//345678910d0=yin1;d1=yin2;d2=yin3;d3=yin4;d4=yin5;d5=yin6;d6=yin7;d7=0;d8=0;d9=0;d10=0;d11=0;d12=0;d13=0;d14=0;d15=0;if((ji》70)&&(ji《80))//4567891011d0=yin0;d1=yin1;d2=yin2;d3=yin3;d4=yin4;d5=yin5;d6=yin6;d7=yin7;d8=0;d9=0;d10=0;d11=0;d12=0;d13=0;d14=0;d15=0;if((ji》80)&&(ji《90))//12345678d0=0;d1=yin0;d2=yin1;d3=yin2;d4=yin3;d5=yin4;d6=yin5;d7=yin6;d8=yin7;d9=0;d10=0;d11=0;d12=0;d13=0;d14=0;d15=0;if((ji》90)&&(ji《100))//345678910d2=yin0;d3=yin1;d4=yin2;d5=yin3;d6=yin4;d7=yin5;d8=yin6;d9=yin7;d0=0;d1=0;d10=0;d11=0;d12=0;d13=0;d14=0;d15=0;if((ji》100)&&(ji《110))//345678910d3=yin0;d4=yin1;d5=yin2;d6=yin3;d7=yin4;d8=yin5;d9=yin6;d10=yin7;d0=0;d1=0;d2=0;d11=0;d12=0;d13=0;d14=0;d15=0;if((ji》110)&&(ji《120))//4567891011d4=yin0;d5=yin1;d6=yin2;d7=yin3;d8=yin4;d9=yin5;d10=yin6;d11=yin7;d1=0;d2=0;d3=0;d12=0;d0=0;d13=0;d14=0;d15=0;if((ji》120)&&(ji《130))//56789101112d5=yin0;d6=yin1;d7=yin2;d8=yin3;d9=yin4;d10=yin5;d11=yin6;d12=yin7;d0=0;d1=0;d2=0;d3=0;d4=0;d13=0;d14=0;d15=0;if((ji》130)&&(ji《140))//678910111213d6=yin0;d7=yin1;d8=yin2;d9=yin3;d10=yin4;d11=yin5;d12=yin6;d13=yin7;d0=0;d1=0;d2=0;d3=0;d4=0;d5=0;d14=0;d15=0;if((ji》140)&&(ji《150))//d7=yin0;d8=yin1;d9=yin2;d10=yin3;d11=yin4;d12=yin5;d13=yin6;d14=yin7;d0=0;d1=0;d2=0;d3=0;d4=0;d5=0;d6=0;d15=0;if((ji》150)&&(ji《160))//d8=yin0;d9=yin1;d10=yin2;d11=yin3;d12=yin4;d13=yin5;d14=yin6;d15=yin7;d0=0;d1=0;d2=0;d3=0;d4=0;d5=0;d6=0;d7=0;If ((Ji "160) & & (Ji" 450)) / / turn off all LEDs and wait for the next meteord0=0;d1=0;d2=0;d3=0;d4=0;d5=0;d6=0;d7=0;d8=0;d9=0;d10=0;d11=0;d12=0;d13=0;d14=0;d15=0;if(ji》450)TR0=0;ji=0;TR0=1;
Application Scheme of Robot System Based on MCS-96 Single Chip Microcomputer and Data Fusion Technol
Application Scheme of Robot System Based on MCS-96 Single Chip Microcomputer and Data Fusion Technol
The main task of the robot designed in this system is to rely on multi-sensor information in an unknown environment and use D-S data fusion algorithm to provide sufficient and reliable information about the system state related to the environment, so that the robot can independently plan the path, avoid obstacles and finally approach the target.The control system adopts master-slave control system. Laser sensor, ultrasonic sensor, infrared sensor, photosensitive sensor, photoelectric encoder and other types of sensors are selected in the system. They are combined with each other to realize the functions of ranging, obstacle avoidance, target finding and so on.1 multisensor data fusion technology and D-S methodMultisensor data fusion technology combines the development of control theory, signal processing, artificial intelligence, probability and statistics, cooperatively uses multisensor sensing data to extract nearly as much useful information of the detected environment, eliminate the uncertainty of information and improve the reliability of sensors.Multisensor data fusion technology has many advantages: it increases the dimension and confidence of measurement; Improved detection performance; Expand the coverage of space and time; The reliability and maintainability of the system are improved; The system has good fault tolerance and strong operation robustness; Resource sharing in the system can improve the utilization of resources.D-S evidence theory is an information fusion method proposed by Dempster in 1967 and expanded and developed by Shafer. D-S evidence theory can deal with the uncertainty caused by ignorance.The reasoning structure of D-S method is divided into three levels.The first stage is synthesis. It synthesizes reports from several independent sensors into a total input.The second level is inference, which obtains and infers the sensor report, and expands the sensor report into the target report.The third level is update. Because various sensors generally have random errors, the sensor level information must be updated before inference and sensor synthesis.2 selection of sensorsThe intelligent robot designed in this system has the functions of ranging, automatic obstacle avoidance and automatic search for an object with a light source as the target. For each function, several different types of sensors are selected for measurement, and then the D-S fusion algorithm is used to fuse these data. Finally, we get the more comprehensive, accurate and reliable information reflecting the environmental characteristics we need to guide the operation of the robot.The specific sensors of the system are selected as follows:1) Ranging sensorThree types of sensors are selected: laser sensor, ultrasonic sensor and infrared sensor.2) Obstacle avoidance sensorThree types of obstacle avoidance sensors are selected: laser sensor, ultrasonic sensor and infrared sensor.3) Find target sensorTwo types of sensors are selected to find the target sensor: infrared sensor and photosensitive sensor.4) Photoelectric encoderUse photoelectric encoder to detect the speed of motor.Dls-a laser ranging sensor is selected as the laser sensor. The device has many excellent performances: measuring range of 0.2-200m, serial interface (RS232 or RS422), single RS422 line can connect up to 10 modules, wide range of power supply voltage (9-30v), programmable analog output, two programmable digital output terminals, digital output error signal, four light-emitting diodes for displaying status signal, D-type interface and spiral terminal for easy connection, Telescope adapter makes installation very easy, solid aluminum metal shell, IP65 (prevent dust and water vapor immersion), complete software configuration, second-class laser.3 hardware structureIn order to reduce the burden of the master controller, the system adopts the master-slave control system. Three MCS-96 microcontrollers are used to process the data from ranging sensor, ultrasonic sensor and target sensor, and data fusion is carried out; Finally, the processed data is uploaded to PC / 104 386SX system through RS-232 serial port. The PC / 104 host makes the next processing. The system hardware structure block diagram is shown in Figure 1.The PC / 104 host is mainly used to collect the data processed by the three lower computers, then adjust the movement of the trolley forward motor and steering motor according to the situation, and display the trolley speed and other information measured by the photoelectric encoder on the LCD screen. In case of collision, voice can also be used for alarm and other operations. PC / 104 host is selected for the upper computer because: first, the processing speed of 386 system is faster than that of single chip microcomputer; Second, in order to facilitate the expansion of the system in the future.In order to avoid other unpredictable faults and make the machine unable to operate normally, the system is also equipped with a hard reset button.4 software designThe software design process of each lower computer is to first detect the data of various sensors, then fuse the data by D-S method, and finally wait for the instruction of the host to upload the fused data to the host.The software design flow of the host is to receive data from three different lower computers through the serial port loop (the communication handshake addresses of the three lower computers are different). According to the target position measured by the target sensor, the path planning is carried out, and the movement direction of the forward motor and steering motor is adjusted. Then adjust the motor speed according to the target distance measured by the ranging sensor. When the obstacle avoidance sensor finds an obstacle ahead or the car collides with the obstacle, it shall stop running immediately and re plan the path. Read the value of photoelectric encoder and display the trolley speed on LCD. If the car collides with an obstacle or the target light source object cannot be found, an alarm shall be given through the voice chip.The watchdog program is set inside the host and lower computer programs to avoid the program flying.5 SummaryThis system designs an intelligent robot based on multi-sensor data fusion technology. The design uses multi-sensor data fusion technology and master-slave control system, so that the robot can find targets and avoid obstacles more accurately and has good robustness.The author's innovations are as follows: (1) an intelligent robot system design based on multi-sensor data fusion technology is proposed, and the software and hardware work reliably. (2) D-S fusion algorithm is used to provide sufficient and reliable information about the system state related to the environment, so that the robot can independently plan the path, avoid obstacles and finally approach the target. (3) The system adopts master-slave control system, which has good expansibility. (4) Good anti-interference ability.
Design of Flow Control System Based on Single Chip Microcomputer
Design of Flow Control System Based on Single Chip Microcomputer
Process control in industrial production is a major field of flow measurement and instrument application. Flow, temperature, pressure and material level are collectively referred to as the four parameters in process control. People monitor and control the production process through these parameters. The correct measurement and regulation of fluid flow is the basis of ensuring the safe and economic operation of production process, improving product quality, reducing material consumption, improving economic benefits and realizing scientific management. Flow detection and control are widely used in chemical industry, energy, electric power, metallurgy, petroleum and other fields.System working principleThe working principle of the system is that the flow information collected by the flow sensor is transformed into electrical signal through the converter, and the AD converter converts the analog electrical signal into discrete signal and transmits it to the single chip microcomputer. The single chip microcomputer software system processes the collected information according to the preset value and outputs discrete control signals. The DA converter converts the discrete control signal into analog power. The action of the valve is controlled by simulating the electric quantity, so as to adjust the flow and realize the accurate control of the flow.Hardware compositionThe system is mainly composed of water pump, flow sensor, electric valve, MCS-51 single chip microcomputer control system, liquid pipeline, control line, monitoring line, etc.The system structure block diagram is as follows:Flow refers to the quantity of materials passing through a certain section of the pipeline in unit time. The task of the control system is to control the quantity of materials passing through a certain pipeline section, that is, the flow of viscosity reducer. The system is controlled by single chip microcomputer. The flow information is collected by flowmeter and transmitted to single chip microcomputer. The single chip microcomputer analyzes the preset value and system software, sends out the corresponding control signal to drive the regulating valve, so as to determine the proportion and consumption of viscosity reducer and realize the automation of production process.The system hardware structure diagram is shown in the figure:Among them, the electromagnetic flowmeter is used as the flow sensor to collect the flow information, which is amplified by the amplifier and sent to the AD converter. AD converter converts continuous analog quantity into discrete digital quantity that can be accepted by single chip microcomputer. After receiving the flow signal, the single chip microcomputer sends the corresponding execution command to the actuator - stepping motor under the action of the control system software. The stepping motor drives the valve to control the fluid flow. software design Software design ideasThe software design of the control system can be divided into three parts:1. Main program part: this part completes the memory partition, data definition and system initialization, and calls each subroutine to complete the main control functions.2. Flow control program: write the corresponding flow control subroutine through PID control algorithm to control the flow and meet the expected control requirements;3. Each subroutine: each subroutine completes the specific implementation method, mainly including: set value input, nixie tube display, stepper motor control, AD conversion interrupt, t0 timer interrupt, sampling interrupt, etc. The software flow chart is as follows:Main program designThe main program part mainly completes the memory allocation, system initialization and overall system control, and realizes the overall design function of the software by calling each subroutine segment.Initialization: the function of the system initialization program is to initialize 8155 and 89C51, so that the D / a output is 0, the stepper motor is in the shutdown state, set the flag bit and work unit in RAM to the initial state, and the prompt cpuready is written to the buffer. The function of updating the display subroutine is to convert the contents of the display buffer into segment data and output it to 8155. The display data buffers of displays 0 12 are 73h 7FH units respectively. When the system is in shutdown state, display 0 4 displays parameters and display 5 7 displays parameter address, so 73h 77h is used as data buffer and 78h 7Ah is used as address buffer. In operation state, 73h 77h is used as instantaneous flow buffer and 78h 7FH is used as cumulative flow buffer. The process of initialization procedure is shown in the figure below:
Design of DC Motor Stepless Speed Regulation System Using PIC Single Chip Microcomputer
Design of DC Motor Stepless Speed Regulation System Using PIC Single Chip Microcomputer
In modern industrial production, motor is the main driving equipment. At present, KZ-D driving system with thyristor (i.e. silicon controlled) device to supply power to motor has been widely used in DC motor driving system, replacing the bulky F-D system of power generation motor. With the high development of electronic technology, DC motor speed regulation has gradually changed from analog to digital, In particular, the application of single chip microcomputer technology makes the DC motor speed regulation technology enter a new stage. Intelligence and high reliability have become its development trend. The speed regulation system uses PIC16F874 single chip microcomputer as the central processor and makes full use of the characteristics of PIC16F874 single chip microcomputer capture, comparison and a / D conversion module as the trigger circuit. Its advantages are: simple structure, synchronous with the main circuit, stable phase shift, sufficient phase shift range, control angle adjustment up to 10000 steps, and stepless and smooth control of the motor, The pulse front is steep and has sufficient amplitude, the pulse width can be set, and the stability and anti-interference performance are good.1. Speed regulation principle of DC motorThe relationship between the speed n of DC motor and other parameters can be expressed by the following formula:(1)(1) Where: VA - armature voltage, IA - armature current, ra - total resistance of armature circuit, CA - potential constant, Φ - Excitation flux.(2)(2) Where: P-number of poles, n-number of conductors, A-number of armature branches.Ca Φ= K (3)(3) Where: when the motor model is determined, CA Φ Constant, so equation (1) is changed toIn medium and small power DC motors, the armature circuit resistance is very small, and the IARA term in equation (4) can be omitted. Therefore, when the armature voltage is changed, the speed n will change.2 system working principleThe system is mainly composed of main control switch, motor excitation circuit, thyristor speed regulating circuit (including speed measuring circuit), rectifier filter circuit, smoothing reactor and discharge circuit, energy consumption braking circuit. The system is controlled by closed-loop PI regulator. When the main control switch is closed, the single-phase AC is controlled by the thyristor speed regulating circuit, and then through the bridge rectifier, filter and smoothing reactor to obtain small pulse and continuous DC, which is supplied to the motor. At the same time, the AC is rectified by the excitation circuit to excite the motor and start working. Adjust the speed setting potentiometer RP1 in the trigger circuit, so that when the input voltage of an1 decreases, the control angle output by PIC16F874 single chip microcomputer decreases accordingly, the thyristor conduction angle increases, the output voltage of the main circuit increases, the motor speed increases, and the output voltage of the speed measuring circuit also increases. After the action of PI regulator, the motor operates stably within the set speed range.3 circuit design of each part of the system3.1 main circuit designThe parameters of each element in the main circuit are shown in Figure 1:Press the start button SB1, the contactor km coil is energized, the KM normally open contact is closed, the normally closed contact is open, the start button is self-locking, and the main circuit is connected. The thyristor speed regulating circuit controls the AC output by changing the control angle of the bidirectional thyristor, and then obtains the DC after bridge rectification and filtering. At the same time, the motor obtains the excitation after rectification through the excitation circuit and starts to work.Press the stop button SB2, the contactor km coil is powered off, the KM normally open contact is opened, the normally closed contact is closed, the self-locking is released, the main circuit is powered off, and the motor stops working.In order to limit the DC current pulsation, the smoothing reactor is connected in the circuit, and the resistance provides a discharge circuit for the smoothing reactor in case of sudden power failure of the main circuit.In order to speed up braking and parking, energy consumption braking is adopted in the device, and the braking link is composed of resistance R4 and normally closed contact of main circuit contactor. The excitation of the motor is powered by a separate rectifier circuit. In order to prevent the runaway accident caused by the loss of excitation of the motor, the under current relay KA is connected in series in the excitation circuit. The action current can be adjusted by potentiometer RP.3.2 thyristor trigger circuit designThe thyristor trigger circuit and parameters are shown in Figure 2. The voltage from point a and B in the main circuit is transformed to - 20 V through the transformer, and then after bridge rectification, a half wave signal of about 100 Hz is generated at point 2. After dividing the voltage through R6 and R7, it is connected to the NPN triode for amplification. A zero crossing pulse is generated at the triode collector, and the rising edge of the zero crossing pulse is captured by the Ccp1 module, Record the occurrence time, and then capture the falling edge of the zero crossing pulse. The time difference between the two is the zero crossing pulse width, and half of its value is the pulse midpoint. Using this capture method, the actual zero crossing of AC can be accurately obtained. At the same time, the ADC analog-to-analog conversion module is used to convert the value of ra1 / an1 analog voltage of PIC16F874 pin as the set value of thyristor control angle (motor speed setpoint) At the same time, the output value of the speed measuring circuit is input by the PIC16F874 pin rc0 / t1cki and counted by the tmr1 counter to calculate the speed as the speed feedback value. The oscillation frequency of the single chip microcomputer in this system is 4 MHz. According to the characteristics of the command cycle of the PIC16F874 single chip microcomputer, the resolution of the thyristor control angle is that of the single chip microcomputer The reciprocal of one quarter of the swing frequency, i.e. 1US, for the half wave time of power frequency power for 10 ms, the control angle can reach 10000 steps, which can fully realize the stepless smooth control of the motor.3.3 design of speed measuring circuitThe speed measuring circuit is composed of an optical code disk attached to the motor rotor and an electric pulse amplification and shaping circuit. The frequency of the electric pulse is in a fixed proportional relationship with the motor speed. The electric pulse signal output by the optical code disk is amplified and shaped into a standard stack TTL level. It is input from the PIC16F874 single chip microcomputer pin rc0 / t1cki and counted through the tmr1 counter to calculate the speed, and the speed is compared with the preset speed Through the PI operation of this difference, PIC16F874 obtains the control increment, and sends the size of the thyristor control angle in cCP2, so as to change the effective voltage added at both ends of the motor and finally achieve the purpose of controlling the speed.4 system software designThe speed closed-loop control is designed as a typical I system, i.e. PI regulator, which is used to adjust the thyristor control angle time TD. Its control algorithm is as follows:Where a1 = KP, KP - proportional coefficient of the controller, T1 - integral time constant, Ti - sampling period.The software design module of the system mainly includes Ccp1 rising edge capture module, Ccp1 lower rising edge capture module, control angle setting value a / D conversion module, speed measurement circuit pulse timing counting module, PI regulator module, cCP2 comparison output module, etc. the relationship of the program flow chart of each module is shown in Figure 3.Fig. 3 flow chart of Ccp1 and cCP2 module interrupt programSuppose we get that the zero crossing time is t σ, If the thyristor control angle time is TD, send it to cCP2 register ccpr2h: l and the comparison value TF = t σ TD, after the comparison is consistent, the high level will be output on the cCP2 pin to turn on the thyristor, and then the ccpr2h: L value will be modified again according to the required trigger pulse width value to maintain the output high-level trigger pulse for a certain time and then return to the low level, so as to complete a bidirectional thyristor trigger pulse output.Summary: the software and hardware design of the system make full use of the characteristics of PIC16F874 single chip microcomputer capture, comparison and analog-to-digital conversion module, as well as the advantages of high oscillation frequency and fast response of single chip microcomputer, and design the corresponding trigger circuit, so that the analog-to-digital conversion module of PIC16F874 single chip microcomputer can quickly and accurately set the conversion speed; Ccp1 module can accurately capture the zero crossing point of AC; The timing counting module of the speed measuring circuit can accurately count and calculate the feedback speed; the cCP2 module can timely compare the TF value and output the trigger pulse. In the application of small and medium-sized DC motor speed regulation system, it has the characteristics of simple structure, reliable operation, wide regulation range, good current continuity and fast response.
Data and Program Description of Single Chip Microcomputer Serial Port LED Display Circuit
The design of single chip microcomputer to connect LED display is a common thing. There are two common methods. One is to connect parallel port display. This method occupies a lot of single chip microcomputer port resources. Dynamic display can be realized by using 8279 and other chips, and the program is also easy to write. The design of connecting many devices in a single chip microcomputer parallel port is not recommended, There is also a LED display circuit that uses MCU serial port to dynamically scan. This station will introduce it one by one.1. MCU serial port LED display circuitThe serial communication port of 80C51 is a powerful communication port and a very easy-to-use communication port. It is more suitable for the display driver circuit. Next, we will design a 4-bit LED display circuit with two serial communication port lines and two ordinary I / O ports according to this need. Of course, as long as two I / O port lines are added, the 8-bit LED display circuit can be easily realized.The left figure is the electrical schematic diagram. We still use C2051 single chip microcomputer and cheap 74LS164 and 74LS138 as expansion chips. 74LS164 is an 8-bit serial in and parallel out shift register. Its function here is to decode the serial data output from C2051 serial communication port and output it on its parallel port line, so as to drive LED nixie tube. 74LS138 is a 3-8 decoder, which decodes the address signal output by the single chip microcomputer and dynamically drives the corresponding LED. However, the current driving capability of 74LS138 is small. Therefore, we use the non stage driving triode 2sa1015 as the address driving. The segments of the four LEDs are connected together, and their common end is time-sharing gated by 74LS138. In this way, only one LED is on at any time, that is, the dynamic scanning display mode. Its advantages have been described in the previous section. Using the serial port for LED communication, the programming is quite simple. Users only need to send the data to be displayed directly to the serial port transmission buffer and wait for the serial interrupt. See the following program
Characteristics and Function Analysis of Internal Flash Memory of MSP430 Single Chip Microcomputer
1 Introduction to internal flash memory of msp430flash single chip microcomputerThe flash memory of MSP430 is a bit, byte, word addressable and programmable memory. The module is controlled by an integrated controller to program and erase. The controller includes three registers, a timing generator and a voltage generator that provides programming and erasing voltage.The flash memory of MSP430 has the following features:1) Generate internal programming voltage2) It can be programmed with bits, bytes and words, and can operate alone or multiple operations continuously3) Ultra low power operation4) Supports segment erasure and multi segment module erasure2 division of flash memoryMSP430 flash memory is divided into multiple segments. It can be written to a single byte or word, or to multiple consecutive words or bytes, but the minimum erasure unit is segment.Flash memory is divided into two parts: main memory and information memory, which are no different in operation. The difference between the two parts lies in the size of the segment and the physical address.Taking MSP430F149 as an example, the information memory has two 128 byte segments, namely segmenta and segmentb, and the main memory has multiple 512 byte segments. The address of MSP430F149 internal flash is 0x1000h 0xffffh, totaling 60K. The starting address of information segment Sega is 0x1080h, and the starting address of information segment SEGB is 0x1000h.3 operation of flash memoryBy default, it is in read operation mode. In the read operation mode, the flash memory cannot be erased and written, the timing generator and voltage generation are turned off, and the memory operation points to the ROM area.MSP430 flash memory does not require additional external voltage in system programmable ISP (in system programmable). The CPU can program flash directly. The write / erase of flash memory is determined by blkwrt, wrt, meras, erase and other bits.3.1 erasureThe default value of each bit in flash memory is 1. Each bit can be programmed to 0 separately, but it can be restored to 1 only by erasing. The minimum unit of erase operation is segment. Three erase modes can be selected through the erase and meras bit settings.MERASERASEEraser Mode 0oneSegment eraseone0Multi segment erase (segments of all main memory)oneoneOverall erase (when locka = 0, erase all segments of main memory and information memory; segments of main memory can be erased only when locka = 0)The erase operation begins with a null write to any location within the erased address range. The purpose of null writing is to start the timing generator and erase operation. After a null write operation, the busy bit is automatically set and held until the end of the erase cycle. Busy, meras and erase are reset automatically after the erase cycle.3.2 writingThe write mode is set by the wrt and blkwrt bits.Blkwrt (block write mode selection)Wrt (write mode selection bit)Write mode0oneSingle byte, single word writeoneoneBlock writeAll write modes use a series of unique write commands. The speed of block writing is about twice that of single writing, because the voltage generator can be maintained when the block writing is completed. For both write modes, any instruction that can modify the destination operand can be used to modify the address. A flash word cannot be erased and written to the device more than twice.When the write operation is started, busy is set and reset at the end of the write.4 operation programming4.1 flash eraseTo write data to flash, the corresponding segment must be erased first, and the flash memory must be erased in the whole segment, which can be erased one segment at a time or multiple segments at the same time. The sequence of erase operations is as follows:1) Select appropriate clock source and frequency division factor;2) Clear lock bit3) Judge the busy bit. The next step can be executed only when busy = 04) Enable segment operation and set erase and meras bits (erase = 1 if one segment is erased, meras = 1 if multiple segments are erased, erase = 1 if the whole flash is erased)5) Make a null write to any position within the erased address range to start the erase operation6) During the erase cycle, the clock source is always valid without modifying the frequency division factor7) After the operation is completed, set lockAccording to the above operation sequence, the program code is written as follows:void FlashErase(unsigned int adr)uchar *p0;Fctl2 = fwkey fssel_1 FN3 fn4; / / select the clock source and divide the frequencyFctl3 = fwkey; / / clear lockWhile (fctl3 & busy); / / wait if busyFctl1 = fwkey erase; / / enable segment operationP0 = (unsigned char *) ADR; / / value is cast to pointer*P0 = 0; / / write 0 to any address in the segment, that is, write null, and start the erase operationFCTL1 = FWKEY;FCTL3 = FWKEY LOCK;while(FCTL3 & BUSY);4.2 writingThe write data to flash can be a single word, a single byte, or multiple consecutive words or bytes (i.e. block operation). The sequence of programming write operations is as follows:1) Select appropriate clock source and frequency division factor;2) Clear lock bit3) Judge the busy bit. The next operation can be performed only when busy = 04) Enable the write function and set wrt and blkwrt (wrt = 1 if a single word or byte is written, wrt = 1 if a block is written, or multiple words and multiple bytes are written continuously, blkwrt = 1);5) Judge the busy bit. The next operation can be performed only when busy = 06) Write data7) Judge busy, clear wrt and set lock after completionAccording to the above operation sequence, the program code is written as follows://write single byte//ADR is the address to be programmed, there is no parity address requirement, and datab is the byte data to be programmedvoid FlashWB(unsigned char Adr,unsigned char DataB)FCTL2 = FWKEY FSSEL_1 FN3 FN4;//MCLK16*FN4 8*FN3FCTL3 = FWKEY;FCTL1 = FWKEY WRT;while(FCTL3 & BUSY);*((unsigned int *) ADR) = datab; / / the value is forcibly converted into a pointer to the memory unit represented by the address data ADR//Assign the data word dataw to the memory unitFCTL1 = FWKEY;FCTL3 = FWKEY LOCK;while(FCTL3 & BUSY);//write single word//ADR is the address to be programmed, which should be an even address, and dataw is the word data to be programmedvoid FlashWW(unsigned int Adr,unsigned int DataW)FCTL2 = FWKEY FSSEL_1 FN3 FN4;//MCLK16*FN4 8*FN3FCTL3 = FWKEY;FCTL1 = FWKEY WRT;while(FCTL3 & BUSY);*((unsigned int *) ADR) = dataw; / / the value is converted into a pointer to the memory unit represented by the address data ADR//Assign the data word dataw to the memory unitFCTL1 = FWKEY;FCTL3 = FWKEY LOCK;while(FCTL3 & BUSY);/*************************************************//Write a specified number of bytes of data to the flash information area//unsigned char *pc_ Byte information area data pointer//Unsigned char * datain: read data and store data array, 8 bits long//Unsigned char count: the number of read operations, ranging from 0 to 127**************************************************/void FlashWrite(uchar *pc_byte,uchar *Datain,uint count)FCTL2 = FWKEY FSSEL_1 FN3 FN4;//MCLK16*FN4 8*FN3FCTL3 = FWKEY;FCTL1 = FWKEY WRT;While (fctl3 & busy); / / wait if busywhile(count--)while(FCTL3 & BUSY);*pc_byte = *Datain;FCTL1 = FWKEY;FCTL3 = FWKEY LOCK;while(FCTL3 & BUSY);Note: when writing words and bytes, it is used to distinguish the types of data pointers pointing to the information area. When writing words, it is * ((unsigned int *) ADR) and when writing bytes, it is * ((unsigned char *) ADR).4.3 readingAccording to the viewed books and network data, there is no sequential requirement for the reading operation of internal flash. Generally, the default operation mode of flash is read mode. The program code for reading flash is as follows:/*************************************************//Read out the specified number of bytes of data to the flash information area//unsigned char *pc_ Byte information area data pointer//Unsigned char * dataout: read data and store data array, 8 bits long//Unsigned char count: the number of read operations, ranging from 0 to 127**************************************************/void FlashRead(uchar *pc_byte,uchar *Dataout,uint count)while(count--)*Dataout = *pc_byte;Dataout;pc_byte;When searching for information on the Internet, I seem to have seen a netizen's blog say that the internal flash address is automatically added with 1. According to his understanding, PC in the function_ Byte statements are useless, but they are not. During debugging, I found that 1 and PC can not be added automatically_ Byte statements are still necessary. By calling the above function, you can flashread ((uchar *) 0x1000, a, 4) in this way; That is, starting from the address 0x1080, 4 bytes of data are read continuously and sent to array a.5 SummaryThe operation of MSP430 on-chip flash is completed by corresponding bits in three control words. Only the correct combination of control bits can realize the corresponding functions.At the same time, pay attention to the flexible use of arrays, pointers and pointers to arrays in programming, which can achieve the purpose of flexible programming. However, several program segments given in this paper can basically realize the operations of erasing and writing MSP430 flash.
Implementation of Analog-to-digital Converter of STC Single Chip Microcomputer
Principle of analog-to-digital converterAnalog to digital converter (ADC), referred to as a / D for short, is a bridge linking the analog world and the digital world. It is used to convert continuous analog signals into discrete signals in digital form. Typically, an ADC converts an analog signal into a digital discrete signal expressed in proportion to the voltage value. For ADCs provided by different manufacturers, their output digital signals may use different coding formatsNote: some analog-to-digital converters are not pure electronic equipment, such as rotary encoder, but can also be regarded as analog-to-digital convertersSome parameters of ADCResolution, response type, error and sampling rate1) ResolutionIn analog-to-digital converter, resolution refers to the number of discrete digital signal values that can be output for the allowable input analog signal range. These output signal values are generally represented by binary numbers, as shown in Figure 22.1. Therefore, the resolution is often in bits, and the number of these discrete values is a power of 2. For example, an analog-to-digital converter with 8-bit resolution can encode the analog signal into 256 different discrete values (discrete gradient), which can range from 0 to 255 (i.e. unsigned integer) or from - 128 to 127 (i.e. signed integer). As for which coding format to use, it depends on the selected ADC device.The resolution can also be described by electrical properties. For example, using volts (V), the difference of the minimum input voltage required to produce a change in the output discrete signal is called the least significant bit (LSB voltage). In this way, the resolution (q) of the analog-to-digital converter Equal to the LSB voltage. The voltage resolution of the analog-to-digital converter is determined by the following equation. In the sub formula, vrefhi and vreflow are the upper and lower limits of the voltage allowed to be input to the ADC during the conversion process; n is the analog-to-digital converterQ=(   VRefHi   -   VRefLOw)/2NIf the change of the input voltage is less than the Q value, the ADC cannot distinguish the change of the voltage. In this way, there will be quantization error. The larger the n value, that is, the more bits of the ADC output digital quantity, the smaller the Q, the smaller the distinguishable voltage change, the stronger the resolution, and the smaller the error caused by quantization2) Response typeThe response type of most analog-to-digital converters is linear. Here, linearity refers to the linear ratio between the value of the output signal and the value of the input signal. The response type of some early conversions is logarithmic. Within the range of digital quantities, ADC devices have good linearity in the middle part and poor linearity at both ends3) ErrorThe error of analog-to-digital converter comes from several sources. Quantization error and nonlinear error are the internal errors in any analog-to-digital conversion3) Sampling rateAn analog signal is continuous in the time domain and can be converted into a series of digital signals that are continuous in time. Therefore, R defines a parameter to represent the speed at which each value on the analog signal is obtained and expressed as a digital signal. This parameter is usually called the sampling rate or sampling rate of ADCThe type of analog-to-digital converter (I learned about it later and analyzed it in the figure above)Flash ADCSuccessive approximation register ADCIntegral ADCDigital transition ADCStructure of ADC in STC single chip microcomputerThe ADC of STC MCU consists of multi-channel selection switch, comparator, successive comparison register, 10 bit DAC and conversion result register   ADC res and   ADC resi and ADC control register adc_; contrBy setting the   Speed1 and   SPEEDO bit, the maximum sampling rate of the ADC module can reach 300kHz, that is, 300000 samples / S (30ksps, 30K sample per second).The ADC is a typical SAR structure, and this result is a typical closed-loop feedback system. An 8-channel analog multiplexing switch is provided at the front end of the ADC in the ADC control register   Under the control of chs2cs bit in ADC contr, the analog signal of ADC = adc7 is multiplexed to the comparatorThe ADC of this structure includes a comparator and a DAC. Through the successive comparison logic, each input voltage is sequentially compared with the built-in DAC output from the most significant bit MSB. After multiple comparisons, the converted digital quantity is close to the value of the digital quantity corresponding to the input analog signal. The final digital quantity is saved in the ADC conversion result register   ADC _resand   ADC _resl. At the same time, ADC control register   Conversion end flag in adc_contr   Adc_; flag is set to 1 for program query or interrupt request to CPUCalculation method of ADC installation and replacement resultsP1 analog function control registerThe input port of 8 analog signals of STC MCU is set on 8 pins of P1 port, i.e. P1.0 p.7. After power on reset, P1 port is set as weak pull-up I0 port. The user can set any of the 8 pins as ADC analog input through software. The pin not set as ADC analog input can be used as ordinary I / O.7. ADC control register1) ADC_ POWERADC power control bit. When this bit is 0, turn off the ADC power supply; When this bit is 1, turn on the ADC power2)SPEED1   And speed0   Digital to analog speed conversion control bit3)ADC_ FLAGADC conversion end flag bit. When the ADC conversion is completed, the hardware will set the position 1, and the software needs to clear 04)ADC_ STARTADC   Conversion start bit, 1 indicates that ADC starts conversion5) Chs0 CSH1 Chs2 analog input channel bitControls which pin is used as an analog input  。8. Interrupt related registersIE address 0xa8   Of which B5  , Is EADC, when this bit is 1   Yes, ADC allowed   interruptIP priority controller 0xb8  , B5 bit   PADC  , Is 1   Is the highest interrupt level, 0   Lowest interrupt level.
Interface Design Between ATmega8 Single Chip Microcomputer and Clock Device Ds3231
The structure and working principle of low-power clock device ds3231 introduced by Dallas company in the United States are introduced. Ds3231 can time year, month, day, hour, minute and second, and has many functions such as temperature compensation, leap year compensation and so on. The software and hardware interface design of AVR single chip microcomputer ATmega8 and ds3231 is given.The measurement and control system or intelligent display screen composed of single chip microcomputer often needs real-time calendar or clock signal. In order to save CPU resources, this paper introduces the application of serial clock device ds3231 and its interface with AVR MCU ATmega8. The system has the characteristics of strong anti-interference ability, accurate timing and no error with seasonal changes.1.3231 composition and working principleAs shown in Figure 1, the main components of ds3231 have 8 modules, which are divided into 4 functional groups: TCXO, power control, button reset and RTC.Ds3231 is a low-cost, high-precision I2C real-time clock (RTC) device with integrated temperature compensated crystal oscillator (TCXO). The device includes a battery input, which can still maintain accurate timing when the main power supply is disconnected. The integrated crystal oscillator can improve the long-term accuracy of the device. The register of ds3231 can store information such as seconds, minutes, hours, weeks, dates, months, years and alarm clock settings. For months with less than 31 days, the month end date can be automatically adjusted, including leap year compensation. Ds3231 provides two programmable calendar alarm clocks and one programmable square wave output. Address and data are transmitted through I2C bidirectional serial bus.Clock and calendar RTCClock and calendar information can be obtained by reading the appropriate register bytes. Set or initialize clock and calendar data by writing appropriate register bytes. The contents of clock and calendar registers are in binary decimal coding (BCD) format. Ds3231 operates in 12 hour or 24-hour mode. Bit 6 of the hour register is defined as the 12 or 24-hour mode selection bit. When this bit is high, select the 12 hour mode. In the 12 hour mode, the 5th bit is the AM / PM indication bit, and when the logic is high, it is PM.TCXO at 32 kHzTCXO includes temperature sensor, oscillator and control logic. The controller reads the output of the on-chip temperature sensor, uses the look-up table method to determine the required capacitance, and adds the aging correction of the age register. Then set the capacitance selection register. A new value including a change in the age register is loaded only when a temperature change or a user initiated temperature conversion is completed. The VCC will read the temperature value when it is powered on for the first time, and then read it every 64 s.Power controlThe power control function is provided by the temperature compensated voltage reference (VPF) and the comparator circuit monitoring the VCC level. When VCC is higher than VPF, ds3231 is powered by VCC. When VCC is lower than VPF but higher than Vbat, ds3231 is powered by VCC; When VCC is lower than VPF and lower than Vbat, ds3231 is powered by Vbat. To protect the battery, the oscillator does not start when Vbat is first added to the device unless VCC is loaded or a valid I2C address is written to the device. Typical oscillator start-up time is less than 1 s. After the VCC is powered on or about 2 s after the effective I2C address is written, the device will measure the temperature once and calibrate the oscillator with the calculated correction value. Once the oscillator is running, it will keep working as long as the power supply (VCC or Vbat) is effective. The device measures the temperature every 64 s and calibrates the oscillator frequency.Button resetThe ds3231 has a button switch function connected to the rst output pin. If ds3231 is not in the reset cycle, it will continuously monitor the falling edge of RST signal. If an edge transition is detected, ds3231 completes the switch de chattering by pulling down rst. After the internal timer timing ends, ds3231 continues to monitor the rst signal. If the signal remains low, the ds3231 continuously monitors the signal line to detect the rising edge. Once the button release is detected, ds3231 forces RST to low level and maintains trst. Rst can also be used to indicate power failure alarm conditions. When the VCC is lower than VPF, an internal power failure alarm signal is generated and the rst pin is forcibly pulled down. When VCC returns to exceed VPF level. Rst remains low for about 250 ms (TREC) to stabilize the power supply. If the oscillator does not work when VCC is loaded, TREC will be skipped and RST will immediately change to high level.alarm clockDs3231 contains two timing / date alarm clocks. Alarm clock 1 can be set by writing to registers 07h 0ah. Alarm clock 2 can be set by writing to registers 0Bh 0dh. The alarm clock can be programmed (through the alarm enable bit and intcn bit of the control register), so as to trigger int / SQW output under the condition of alarm clock matching. Bit 7 of each timing / date alarm register is the mask bit. When the mask bit of each alarm clock is logic 0, an alarm will be given only when the value in the timing register matches the corresponding value stored in the timing / date alarm clock register. The alarm clock can also be programmed to repeat alarms per second, minute, hour, week or date. When the RTC register value matches the set value of the alarm register, the corresponding alarm flag bit a1f or a2f is set to logic 1. If the corresponding alarm interrupt enable bit a1ie or a2ie is also set to logic 1, and the intcn position is logic 1, the alarm condition will trigger int / SQW signal. RTC detects matches every second the time and date registers are updated.2 data exchange and format of ds3231Ds3231 exchanges data with the outside world through the bidirectional data line SDA and clock line SCL of I2C bus. Ds3231 acts as a slave on I2C bus. The I2C host can access ds3231 only after executing the start command and verifying the device address, and then the register of ds3231 can be accessed until a stop command is executed. Ds3231 has two operation modes: write operation and read operation. The address of ds3231 is fixed at 1101 000.3. Hardware interface between ds3231 and AVR MCUAtmega Series MCU chip integrates 2-wire serial interface module, which ATMEL calls twi interface. In fact, twi and Philips I2C bus are the same thing. The twi interface implemented by AVR hardware is byte oriented and interrupt based. It has better real-time performance and code efficiency than software analog I2C bus. The pin input part also has burr suppression unit, which can remove high-frequency interference. Figure 3 is the hardware interface circuit schematic diagram of ds3231 and AVR MCU ATmega8.In the software design, the AVR single chip microcomputer ATmega8 and the real-time clock device ds3231 should be initialized first to give the ds3231 an accurate date and time. Regardless of the master mode or the controlled mode, the twen position of the twi control register twcr should be set to 1 to enable the twi module. After the twin bit is set, the I / O pins PC5 and PC4 are converted into SCL and SDA. The operation of the twi control register twcr can generate start and stop signals on the bus. All operations on the twi module are register read and write operations, and AVR libc does not provide a special API.
keine Daten
Schnell verbindung



Über uns

Kontaktieren Sie uns


Das moderne Haus

Landschafts haus

Vintage Haus

Guangzhou DaLong CNC Machinery Technology Co.Ltd spart keine Kosten, wenn es darum geht, sicherzustellen, dass wir über die neueste und beste Ausrüstung verfügen.

keine Daten

Unternehmens profil

Unternehmens geschichte


Copyright © 2021-2035 Guangzhou DaLong CNC Machinery Technology Co.Ltd | Sitemap

Wholesale Machinery supply Melayu  |  Milling machine manufacturer العربية  | EDM Machine factory OEM