Design of Simple Signal Source Based on Single Chip Microcomputer

Publisher:SparkCrafterLatest update time:2018-04-11 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    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.

    18.gif

    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


Reference address:Design of Simple Signal Source Based on Single Chip Microcomputer

Previous article:Problems and solutions in using external interrupts of single chip microcomputers
Next article:Introduction to MCU Software Addressing Technology

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号