Summary of avr microcontroller work experience

The AVR MCU is an enhanced RISC (Reduced Instruction Set CPU) RISC instruction set high-speed 8-bit MCU developed by ATMEL in 1997. Can be widely used in computer peripheral equipment, industrial real-time control, instrumentation, communication equipment, household appliances and other fields. The AVR microcontroller is a RISC microcontroller introduced by Atmel Corporation in 1997. RISC (Reduced Instruction System Computer) is relative to CISC (Complex Instruction System Computer). RISC is not simply to reduce instructions, but to increase the speed of the computer by making the structure of the computer simpler and more reasonable.

The main features of AVR microcontroller ATmega16:

1) AVR core microcontroller with RISC structure.

131 machine instructions, most of which are instructions that are executed for a single system clock cycle;

32 8-bit general purpose working registers;

Fully Static Operation.

Operating at 16 MHz with 16 MIPS performance. (Note: The ATmega16L series has a maximum operating frequency of 8 MHz);

The internal hardware multiplier is equipped with 2 clock cycles.

Summary of avr microcontroller work experience

2) On-chip comes with large capacity, non-volatile program and data memory

16KB Online Programmable (ISP) In-System Programming Flash program memory (10 000 times), using Boot load technology to support IAP (In-Application Programming).

1KB on-chip SRAM data memory, which can realize program encryption of level 3 lock;

512-byte on-chip ISP's EEPROM data memory (shoes count 100,000);

3) On-chip JTAG interface

Supports boundary scan function conforming to JTAG standard (compatible with IEEE 1149.1 standard) for chip detection;

Support for extended on-chip debugging;

Download programming for on-chip Flash, EEPROM, Fuse and Encryption Lock bits via the JTAG interface;

4) Peripheral interface

2 8-bit timer/counters with separate and configurable prescalers;

1 16-bit timer/counter with programmable prescaler, compare, capture function;

A real-time clock RTC with a separate oscillator in the chip;

4 PWM channels;

8 10-bit ADCs;

Byte-oriented two-wire interface TWI (Two-Wire Serial Interface, fully compatible with IIC bus hardware interface);

1 programmable, enhanced full-duplex, serial interface USART supporting synchronous/asynchronous communication;

1 SPI (Serial Peripheral Interface Bus) serial interface (supports ISP program download) that can work in master/slave mode;

On-chip integrated analog comparator;

The chip contains a programmable watchdog timer WDT with independent on-chip oscillation period;

5) Other features

A power-on reset circuit and a programmable brown-out detection reset circuit BOD (Brown-out Detection);

The on-chip contains a 1/2/4/8 MHz calibrated, calibratable RC oscillator that can be used as a system clock;

21 internal and external interrupt sources;

6 sleep modes (idle mode, ADC noise suppression mode, power saving mode, power down mode, Standby mode, and

Extended Standby mode), support for power saving mode work;

32 programmable I/O ports. Package options are: 40-pin PDIP package, 44-pin TQFP package, and 44-pin MLF package;

Operating voltage: ATmega16L is 2.7~5.5V, ATmega16 is 4.5~5.5V;

Running speed: ATmega16L is 0~8MHz, ATmega16 is 0~16MHz;

Power consumption indicator: ATmega16L operates at 1MHz, 3V, 25 degrees Celsius: typical power consumption is 1.1mA, idle mode is 0.35mA, power-down mode is "1uA;

The internal structure block diagram of AVR MCU:

Summary of avr microcontroller work experience

Summary of avr microcontroller work experience

Compared with the traditional type, AVR has to be able to achieve some basic functions, and it has greatly improved and improved in many aspects such as structural system, functional components, performance and reliability.

But using better devices only creates a good foundation and possibility for designing a good system. If you follow and follow the traditional hardware and software design ideas and methods, you can't use AVR, or even Can not really understand the characteristics and strengths of AVR.

A device with better features requires a person with higher technology and ability to use and control it. Just like a good F1 car, only the drivers with superb technology can fully appreciate the characteristics of the car and maximize the performance of the car.

AVR has the characteristics of quick start-up and easy development. However, it is necessary to fully understand and exploit the advantages of AVR. It also requires continuous learning and practice improvement of the application engineer's own hardware and software design and development capabilities.

"The layman looks at the excitement, the insider looks at the doorway." For engineers who have a certain basic and single-chip system design and development, you may wish to try AVR first.

Development environment and tools: PC+ download line + actual system board

Development software on the PC:

AVR Studio (Free) assembly + assembly debugging + high-level language debugging + software simulation

ICC, CVAVR, BASCOM-AVR high-level language program development + program download. One of them buys genuine full-featured, as the main development environment, and other uses the DEMO version as an aid and reference.

AVR ISP download line:

STK200 and STK200+ and STK300 ISP programmer. Through the printer port of the PC, the system running code (HEX, BIN) and data are written into the Flash and EEProm of the AVR chip by ISP technology, and the configuration fuse bit and encryption bit of the AVR are programmed. Supports most AVR chips, as well as ATMEL's 51 compatible chips 89S8252, 89S52 and so on. The support program for the download line is included in ICC, CVAVR, BASCOM-AVR, and BASCOM-8051. Free dedicated downloader: SLISP, PonyProg2000, etc.

Try not to use the emulator:

When developing and debugging system programs, many people rely entirely on the emulator, and once they leave the emulator, they feel that they can't get started. In fact, because AVR's Flash memory can easily use ISP technology to erase multiple times online, it is recommended to try not to use (depend on) the simulator to develop and debug the program.

In the actual development process, the debugging of the program can start from the following aspects:

Today's high-level language compilers (such as C compilers) can produce highly efficient machine code, so it is recommended that you write system programs in high-level languages ​​whenever possible.

Use Atmel's AVR Studio software simulation environment and other software simulation environment (BASCOM-AVR).

Write system programs in high-level languages ​​whenever possible.

Use the LCD or asynchronous serial port on the target board. See the attached article "How to Develop AVR without an Emulator".

Increased rationality:

Try to use the AVR on-chip resources as reasonably and fully as possible, such as EEPROM, A/D, and internal RC oscillator sources.

Try to use connected peripheral devices, large-capacity memory, LCD controller, printer, 7279, etc. without 8279 (LED digital tube + keyboard). In addition to the need to expand RAM (such as voice and image), the use of parallel expansion (573 + decoding circuit) is generally not recommended, reducing hardware and wiring and the probability of occurrence of errors on the PCB, while also improving system reliability. . Parallel expansion to serial expansion is a trend. There are a large number of new peripheral devices that use high speed, such as A/D, D/A, RTC, memory, and so on.

Try to use and reserve the ISP program download interface on the target board, or use IAP technology.

Advantages: ISP interface and I / O compatibility is better than JETAG.

Disadvantages: Cannot debug online

Pay attention to and master the use of AVR configuration fuses:

System crystal selection

Use of .BOD

Start delay

.Mega8 PC6 pin, RESET and general purpose I/O conversion

.JETAG interface and general purpose I/O conversion

Start vector conversion, BOOT-LOAT area size setting

Considerations for improving hardware reliability:

. Try to use an on-chip crystal, a low-frequency system clock, and a small output.

. Select the appropriate start delay parameter

. Use BOD, on-chip watchdog

. Reasonable sleep mode

. Do not set the output low level without I/O port

. Use the internal EEPOM and register MCUCSR to determine the reset flag for different processing

Improve the ability and level of software design:

Try to use a high-level language design to write system programs. There are many people who think that using the assembly program is relatively streamlined, and using high-level language development wastes a lot of program space. In fact, this is a misunderstanding. For an experienced assembler who is very familiar with a microcontroller, he can write code that is more streamlined than a high-level language. And if you are a developer who is not very familiar with the assembly, or suddenly replaces a new one, can you guarantee that you can write more concise code than the high-level language?

The superiority of high-level languages ​​is incomparable in assembly language:

. Easy to transplant the program

. Ruggedness of the program

. Mathematical operation support

. Clear and structured programming, maintainability of the program.

. Can be collaboratively developed software with a short development cycle.

Nowadays, high-level language compilers (such as C compilers) can generate machine code with high code efficiency. Therefore, it is recommended that programs that can be implemented in high-level languages ​​be written in high-level languages ​​as much as possible, in the case of strict requirements on speed and timing. Can be solved by a mixed programming method.

A more in-depth and comprehensive grasp of the various serial communication protocol procedures:

At present, a large number of serial interface peripheral chips and various communication interfaces, such as RS232, two-wire (I2C), three-wire (SPI), single, USB, CAN, TCP/IP, etc., are used. Developers and programmers should be aware of low-level protocols, familiar with how and how low-level protocols are implemented, how to define reliable upper-layer application protocols, and low-level protocol-driven (upper-layer software implementation) between upper-layer application protocols.

The hardware engineer's software writing ability should be improved, using standard programming methods, perfect software overall framework design, good data structure and program structure system. (Computer software professional programmers are unfamiliar with hardware, most of them write software under the support of operating system, and do not understand the driver layer and interface of low-level interfaces and protocols, and often cannot write good single-chip system programs.)

Communication interface should be written as much as possible

Use interrupt + buffer,

Layered + structured design,

Try not to use round-robin (to reduce the efficiency of AVR). See the URAT (RS232) driver + middle layer software example.

Adopt a good system design pattern:

Try not to use the traditional front-end (interrupt) system design mode, the tasks interact and interfere with each other, and can not operate regularly. For example, design an 8-bit LED digital tube driven by dynamic scanning mode and 4*4 of dynamic scanning.

The TimeTip+ state machine design + CASE structure is adopted to realize the multi-task parallel operation system design method. Or time-triggered system design. (See: "Time-triggered embedded system design mode" China Electric Power Press 2004.6)

Transplant small, such as UCOS-II. There are some free AVR-based simple operating systems online.

Improve the programming ability and software application level of C language:

Familiar with and use high-level applications such as data structures, pointer applications, and memory management in C.

Familiarize yourself with the features of the advanced language development platform you use. These platforms are for a certain class of processors and contain many special incompatible statements and extended structures, statements, functions, and so on. Although it is easy to use, it should be used reasonably due to its opacity and time uncertainty. Such as C in the getchar (), putchar () and so on.

AVR has multiple development platforms, each with its own characteristics and deficiencies. The ability to use these platforms in a comprehensive way and complement each other can improve development efficiency. For example, through ICC, CVAVR program generator CodeWizard to learn and understand the hardware settings of AVR, simplify calculations, and quickly generate basic program modules, such as "a URAT (RS232) low-level driver + middle-tier software example."

Battery Cable

Over time, battery cables have to be replaced due to corrosion or damage. A bad battery cable can cause intermittent starting issues or lack of power to the vehicle, including arcing or power drains.A battery cable consists of multiple stands of wire encased in synthetic material with different types of battery terminals on each end for a reliable connection. Corrosion is the number one cause of battery cable failure, stopping the flow of electricity.

Battery cable, power cable, battery cable assembly, battery wiring

ETOP WIREHARNESS LIMITED , https://www.oemwireharness.com