High-precision frequency regulator based on Atmega16L microcontroller

Publisher:丝路老君Latest update time:2011-12-31 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction
In modern industrial production and high-precision testing, we need a fairly accurate frequency to help determine the performance indicators of the equipment. And we hope to be able to fine-tune the frequency. The frequency obtained by the voltage-controlled oscillator is not accurate enough, and the frequency fine-tuning steps are cumbersome and time-consuming, so some test items limit the use of the voltage-controlled oscillator.
Mega series microcontrollers were launched by Atmel since 2002. This AVR enhanced microcontroller has many advantages such as fast speed, strong anti-interference ability, and low price. In order to speed up the software compilation of AVR microcontrollers, Atmel and third parties provide a variety of development tools, which makes program development convenient and effective. The internal FLASH structure of the microcontroller is flexible and difficult to decrypt after being locked, which can maximize the protection of intellectual property rights. AVR microcontrollers can be widely used in communications, field testing, automotive electronics, medical equipment and other fields, and are suitable for various low-voltage and low-power occasions.

This paper proposes a method that can provide a frequency signal accurate to 1Hz based on the AVR microcontroller and uses AD9850, which can generate not only sine waves but also square waves, thus solving the problem for enterprises requiring high frequency accuracy. It uses Atmel's AVR microcontroller Atmega16L as its core, and can easily and accurately control the output frequency. Since the AVR microcontroller is online programmable, it greatly simplifies the design steps and speeds up the design process. At the same time, it will not burn or waste the chip, saving costs.

Figure 1 shows the overall design block diagram of the frequency regulator. The user sets the frequency value through the 4×4 keyboard, and the AVR microcontroller uses the I/O port to scan and read the frequency value. Then the AVR microcontroller controls the AD9850 to adjust to the frequency required by the user. The output of the AD9850 can be connected to a voltage comparator to shape it into a square wave, or it can be passed through a low-pass filter to limit the bandwidth and output a sine waveform. The AVR microcontroller also controls the LCD display module to display the current frequency in real time.

Figure 1. Overall block diagram of the frequency regulator

2 Control Core and Frequency Generation Technology
2.1 Control Core
This design uses Atmel's AVR microcontroller Atmega16L as the control core. The single-cycle instructions of the AVR microcontroller can ensure high execution efficiency and low cost, and it is a high-performance device in the reduced instruction set CPU. The AVR microcontroller can provide up to 16 MIPS execution time, has 128K bytes of programmable Flash memory, and has 4096 bytes of static RAM. The AVR microcontroller has a built-in watchdog timer, which can prevent the program from running away under strong electromagnetic interference conditions. The Atmega16L used in this design also has the following features:
· It contains a hardware multiplier to speed up the multiplication operation; the number of I/O port pins is up to 32;
· It supports online programmable functions, and there is no need to frequently plug and unplug the chip from the circuit board; it has a programmable UART port that supports synchronous transmission;
· It supports a three-wire transmission SPI port; it has a convenient I2C bus port and is directly connected to the Philips chip;
· It supports the JTAG boundary scan circuit; it has a BOD low voltage detection function;
· It has 8 10-bit A/D converters inside; it has 4 PMWs that can work together or individually;
· It has a real-time clock circuit inside; the operating frequency can reach up to 16MHz.

2.2 AD9850 frequency generation technology
AD9850 is a low-power direct digital frequency synthesizer chip launched by AD, which can generate wide frequency signals from DC to 62.5MHz. From the time it was put on the market to today, it has been used in radar systems and low-power frequency sources. Its good frequency synthesis function is suitable for application in high-precision testing. This design uses AD9850 as a waveform generator, which has the advantages of small size and low power consumption.

In the control process, the AVR microcontroller calculates the frequency control word for the AD9850 and writes the frequency control word into it. Combined with the "+1Hz" key and "-1Hz" key on the keypad, this design allows the frequency to be adjusted accurately to a step size of 1Hz. It can generate square waves and sine waves. When the user requires the generation of a sine wave, we designed a low-pass filter to filter out the high-frequency components of the signal. The low-pass filter can also be implemented using a fifth-order elliptical filter. Figure 2 shows the AD9850 circuit design diagram of this system. PC2-PC5 can also be used as I2C bus ports at the same time.

Figure 2 AD9850 circuit design

3 Input devices and output devices
3.1 Keyboard input device and corresponding software
This design uses a 4×4 keyboard as a frequency input device. Since there are only 16 keys, and it is necessary to represent a wide range of frequencies from 1Hz to 10MHz, the AVR microcontroller scanning method is used in the software design. All 8 I/O pins of port A are used as scanning keyboards. In addition to the 10 numbers 0-9, the keyboard also defines the "backspace" key, "delete all" key, "enter" key, "+1Hz" key and "-1Hz" key, which greatly facilitates users to modify and fine-tune the frequency at any time. When reading the frequency value entered by the user, a software program with delayed anti-shake and anti-interference is used. The initial value of the scan variable is set to 0xFE, and the scanning is realized by changing the low level 0 in sequence. The C code scanned by the keyboard of this microcontroller is as follows:
sccode=0xFE;/*every scan initiative value,11111110*/
while(sccode!=0xEF)/*sccode is not 11101111,follow;or return 0*/
{
PORTA=sccode;/*send scan code 11111110 to portA*/
PORTA=sccode;/*send scan code 11111110 to portA */
if((PINA&0xF0)!=0xF0)/*read portA,if high 4 bits are not 1111,key pressed in this line*/
{
recode=(PINA&0xF0)|0x0F;/*portA high 4 bits reserved,low 4 bits are 1111*/
while((PINA&0xF0)!=0xF0)
{};
/*read portA,if portA high 4 bits are not 1111,key pressed,
if key pressed,we must wait,wait for key released*/
return((~sccode)+(~recode));/*return row+column*/
}
else
{
sccode=(sccode<<1)|0x01;
/*scan code left shift 1 bit, add 1 to right,11111101*/
}
}
The scan result finally returned includes the row value and column value where the key is located. The judgment steps are: first record the high 4 bits of port A in the scan variable recode, and set the low 4 bits to 1111. Read the high 4 bits of port A again to determine whether the key is released. When the user has not released the key, there is a low level 0 in the high 4 bits, and at this time it can only wait in a loop. Only when the user releases the key, the high 4 bits and the low 4 bits are bitwise reversed and combined to form the final scan result returned. If no key is detected, the scan variable sccode is shifted left by 1 bit and the next scan is continued.

3.2 LCD Module
After the user has input the frequency and fine-tuned "+1Hz" and "-1Hz" for many times, he or she focuses on observing the impact of the signal output on the next level circuit, and often forgets the current system output frequency. This results in not knowing whether to adjust it higher or lower when fine-tuning is required in precise testing. In order to inform the user of the current frequency of the system, we have expanded the LCD module and realized the real-time display of the current frequency on the LCD module. The LCD module occupies PD0-PD7 of the microcontroller Atmega16L as the data interface and uses PB0-PB4 of the microcontroller as the control port. Figure 3 shows the circuit diagram of the LCD module and the controller circuit design. The PB0 pin selects the data memory or instruction memory of the LCD module, the PB1 pin indicates whether the operation is to read or write the LCD module, and PB2 constitutes the rising edge and falling edge to complete the read and write timing. PB3 is responsible for selecting the left half of the LCD module, and PB4 is responsible for selecting the right half. Usually, PB3 and PB4 are both set to 1. It should be noted that after the data or instructions are ready, PB2 should be changed in level, otherwise the reading and writing will be wrong.

This design uses the large-capacity program memory of the single-chip Atmega16L to store the font dot matrix of English letters and several Chinese characters as an array in the program memory of the single-chip. When a certain character needs to be displayed, the array is directly called, thereby simplifying the design and realizing the display of English, Chinese characters and graphics. This design has a friendly display interface and strong controllability.

Figure 3 LCD display module and controller circuit design

4 Conclusion
In order to facilitate modern industrial production and accurate frequency testing, we designed a high-precision frequency regulator based on AVR microcontroller. In this design, the "+1Hz" key and "-1Hz" key on the keypad can be used to conveniently adjust the frequency to 1Hz. This frequency regulator is small in size and powerful in function. It uses Atmel's AVR microcontroller Atmega16L as the control core, and users can adjust the system output frequency at any time. A 4×4 keyboard is used to input the user-set frequency value, which occupies a small space and is highly efficient. The program allows the AVR microcontroller to scan and obtain the frequency, eliminating the need for a dedicated keyboard interface chip 8279. The LCD display module can display the current frequency in real time, with a friendly display interface and strong controllability. This system can generate square waves and sine waves.

The hardware and software of this design have been applied in a frequency test production line. Industrial production and test use show that this design simplifies the frequency adjustment process, is easy for users to use, and has the characteristics of power saving, low cost, strong anti-interference ability, high frequency control accuracy and high speed.

References
[1] Atmel Corporation. 8-bit AVR Microcontroller with 16K Bytes In-System Programmable Flash Atmega16L data sheet. Atmel Corporation, 2003: 3-18.
[2] Atmel Data Sheets. http://www.atmel.com/dyn/products/devices.asp?family_id=607%20
[3] Atmel Application Note. http://www.atmel.com/dyn/products/app_note s.asp?family_id=607


Reference address:High-precision frequency regulator based on Atmega16L microcontroller

Previous article:Temperature Measurement Design of PIC Microcontroller Based on TMP04
Next article:Design of multi-task embedded Internet system based on ATmega128 single chip microcomputer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


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

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