1 Introduction
Signal generators are widely used in teaching, experiment, measurement and control, etc. The frequency range of their output signals covers all frequency bands, from very low frequency to very high frequency. The operation mode has also changed from manual knob to program control. The waveforms generated have evolved from traditional sine (cosine) waves and pulse waveforms to various arbitrary waveforms. In the past, signal generators often occupied a single chassis, but in some current applications, it is just an expansion card inserted in the computer. Some signal generators are designed as independent small modules and connected to the computer through serial buses such as RS-232C, RS-422, RS-485, etc.
In fact, in many fixed control applications, the signal generator is only required to generate a single waveform, or a few countable waveforms. If only a single sine (cosine) wave or pulse waveform is required, a traditional oscillator circuit can be used. When the signal frequency is selected, the problem is still relatively simple. However, if the generated signal waveform is more complex, the circuit design also becomes very complicated. In addition, the traditional oscillator circuit has a large temperature drift and requires a long warm-up time. In order to achieve a higher frequency accuracy, the various parameters of the circuit need to be carefully adjusted.
The use of digital frequency synthesis technology has greatly simplified the design of signal generators. However, in some specific cases, only a few separate waveforms are needed. In this case, we can use a single-chip microcomputer and a DAC chip to generate the required waveforms with a very simple circuit.
2. Circuit design and programming considerations
The circuit diagram of the simple signal generator of the single-chip microcomputer is shown in Figure 1. It consists of only one AT89C2051 single-chip microcomputer, one DAC0832 and a low-pass filter composed of an operational amplifier. The AT89C2051 has a 2KB FLASH memory inside, which can save the running program and waveform parameters, and 128 bytes of RAM can be used to store waveform parameters. Due to the use of digital synthesis technology, various simple or complex waveforms can be generated.
The working process is as follows: (1) Determine the signal waveform to be generated; after power-on and stable operation, the microcontroller first reads the P3.0 and P3.1 pin signals to determine the address to which the program should jump. Each jump address has an output waveform. (2) Send the sample data stored in FLASH to DAC0832 for conversion into analog voltage .
First, the waveform parameters should be converted into sample data. If there are N sample data per cycle, the calculation method for the Kth sample data is:
DK=127(1+SIN(2πK/N) K=0,1,2,……N-1
Since in the actual process of generating waveforms, data is obtained and sent out one by one by the running program, it is a cyclic process when generating periodic waves. Therefore, the time overhead of program operations such as data acquisition, data sending, and looping must be considered. For the MCS51 series of microcontrollers, when the crystal frequency is 12M Hz , the execution time of each instruction is 1 to 2μs. In order to make the waveform smooth enough, the number of points per cycle should be as large as possible, which requires the microcontroller to send sample data as quickly as possible. Due to the limitation of the sending cycle, the output signal frequency will decrease when the number of sample points is increased. At the same time, it takes a long time to fetch data from the program memory space. When the number of sample data is small, the sample data can be moved to RAM first. When the program is executed, the data is directly fetched from RAM and sent to DAC, which can increase the rate of sending sample data.
The following uses the generation of a single 4800Hz sine wave as an example to illustrate the programming process. The calculation of parameter N is described below.
ORG 0000H
MOV R0,#0
MOV R1,#4
MOV R2,#124
MOV DPTR,#200H
MOV A,#0
MOVD: MOVC A,@A+DPTR ;Move sample data from FLASH
MOV @R1,A ;to internal RAM,
INC R0 ;can reduce the sending time
INC R1
MOV A,R0
DJNZ R2,MOVD
MOV R0,#04
DOUT: MOV A,@R0 ;send data to DAC in turn
MOV P1,A
INC R0
CJNE R0,#128,DOUT
MOV P1,#128 ;send sample data again from the starting point
MOV R0,#04 ;
SJMP DOUT ;sending cycle ends
;
ORG 0200H ;sample data table
DB 0147
DB 165
……
In the above program, the loop program starting with the DOUT label sends sample data. The instructions of this loop program have been carefully selected. N sample data share 4 instructions and the execution time is 5μs. However, for a signal frequency of 4800 Hz, the signal period is 208.3333μs, and the number of sample data N is calculated to be 208.3333/5=41.6667. Since the number of sample data cannot be a decimal, you can consider rounding up to get the closest signal frequency. Therefore, the number of samples is 42, but the signal period becomes 210μs, and the signal frequency is 4762Hz. The frequency error is very large and does not meet the use requirements.
To this end, multi-cycle synthesis technology can be used. The method of multi-cycle synthesis is to consider M cycles together when calculating sample data. That is, N sample data represents the waveform of M signal cycles, so that the number of samples in each cycle is closest to the required value. The calculation formula is as follows:
DK=127(1+SIN(2лMK/N) K=0,1,2,3……N-1
Therefore, the values of N and M need to be reasonably determined.
The value of M can be determined as follows: take the decimal part of the number of sample data in a single cycle, and divide it by 1, and the result is M. For f0=4800Hz, it can be seen that M is exactly equal to 3.
Let's calculate N. It is known that each sample data takes 5 μs, the number of sample cycles is 3, and the signal frequency is 4800 Hz, then
N=3/4800*1000000/5=125
From this we can know the calculation formula of sample data:
DK=127(1+SIN(6л/125)) K=0,1,2……124
In practice, this signal source is used to generate four waveforms: 4800Hz sine wave, 400Hz sine wave, 480Hz sine wave and 1000Hz square wave. The calculation of waveform parameters of 400Hz, 480Hz sine wave and 1000Hz square wave is omitted here. Actual measurement shows that the frequency error of the four signals is less than 0.5Hz.
If the signal frequency is relatively low and there are many sample data, there is no need to move the sample data to RAM first, but directly obtain the sample data from FLASH and send it to DAC. For sine waves, when there are more than 20 sample data per cycle, there will be a better waveform. For rectangular waves, only 2 sample data are needed per cycle.
3. Summary
Although the above circuit is simple, it has a relatively accurate waveform. Since the waveform parameters are completely preset by the software, in addition to generating sine waves and square waves, it can also generate complex waveforms such as trapezoidal waves or sin(x)/x. The circuit can be designed as an embedded structure, so that it can be applied in some industrial production sites.
References
1 Yu Yongquan. Principle and Application of ATMEL89 Series (MCS-51 Compatible) FLASH Microcontroller. Publishing House of Electronics Industry. 1997
2 Jiang Huanwen, Sun Xu. Electronic Measurement. China Metrology Publishing House. 1988
Previous article:Problems and solutions in using external interrupts of single chip microcomputers
Next article:Introduction to MCU Software Addressing Technology
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EEWORLD University Hall--Overview of Hall Position Sensor Applications
- Qorvo has produced the ACTIVECiPS series of modular power PMICs. Will you use them?
- EEWORLD University ---- VLSI CADI - Theory
- CircuitPython 5.0.0 released
- dspPI controller program problem
- MSP430F5529 Beginner's Guide
- Canaan's K510 development board is now on the forum. Let's warm it up first and post it later.
- EEWORLD University Hall----Live Replay: Fujitsu FRAM's authenticity verification solution without encryption algorithm (spectrum) is a security innovation and the world's first new verification method
- Last week: 100 sets of Pingtouge RISC-V development boards, invite you to play ~ Come quickly ~ Share with friends and win red envelopes
- HP laser printer original toner cartridges are useless if you don't open them after using them up.