Home  Semiconductor Information

Jan 25 2018

A Signal Generator Project Based on Single Chip Microcomputer 89C51

Warm hints: The word in this article is about 2800 and reading time is about 14 minutes.

Summary

In this article, it will mainly introduce a low frequency function signal generator project based on single chip microcomputer 89C51 . By adopting the technology of digital waveform synthesis and through the combination of hardware circuits and software programs, the signal generator can output custom waveform, such as sine wave, square wave, triangle wave,  trapezoid wave and other arbitrary waveform. The frequency and amplitude of waveform can be changed arbitrarily in a certain range. The change of waveform and frequency is controlled by software, and the change of amplitude is realized by hardware. The principle of waveform generation, the design principle of hardware circuit and software will also be introduced in this article.This system can produce the waveform of 798.6HZ. It has the advantages of small size, low price, stable performance and complete function.

Article core

 a low frequency function signal generator project

Overview

An instrument for generating an electrical test signal for the required parameters

English Name

Signal generator

Catagory

Electronic project/semiconductor/signal generator

Waveform typeTriangular;sawtooth  or rectangular wave, etc.

signal sources

An instrument for generating test signals




Catalogs


CatalogsI.AbstractV.The Design of System Software
II.Signal Generator BasicsVI.Installation, Debugging and Measurement Data Analysis
III.Tasks and RequirementsVII.Summary
IV.Signal Generator Circuit Design and AnalysisVIII.Signal Generator Attachment




Introduction

I.Abstract

By adopting the technology of digital waveform synthesis and through the combination of hardware circuits and software programs, the signal generator can output custom waveform, such as sine wave, square wave, triangle wave,  trapezoid wave and other arbitrary waveform. The frequency and amplitude of waveform can be changed arbitrarily in a certain range. The change of waveform and frequency is controlled by software, and the change of amplitude is realized by hardware. The principle of waveform generation, the design principle of hardware circuit and software will also be introduced in this article.This system can produce the waveform of 798.6HZ. It has the advantages of small size, low price, stable performance and complete function.

Keywords: signal generator project; Single Chip Microcomputer; low frequency signal generator; single chip microcomputer(SCM); D / A conversion; 

II.Signal Generator Basics

A signal generator is a device that provides a variety of frequency, waveform, and output level electrical signals. When measuring the amplitude characteristics, frequency characteristics, transmission characteristics and other electrical parameters of various telecommunication systems or telecommunication equipments, and measuring the characteristics and parameters of components, they are used as signal sources or excitation sources for testing. It also known as signal source or oscillator, is widely used in the field of production and science and technology. All kinds of waveform curves can be expressed by the trigonometric function equation. A circuit that produces a variety of waveforms, such as triangular waves, sawtooth waves, rectangular waves (including square waves), and sinusoidal waves, is called a function signal generator.

Chinese Name

信号发生器

Overview

An instrument for generating an electrical test signal for the required parameters

English Name

Signal generator

Waveform type

Triangular;sawtooth  or rectangular wave, etc.



signal sources

An instrument for generating test signals



Detail

III.Tasks and Requirements

The task is to design a signal generator controlled by a single chip microcomputer. Using MCU system  to control and generate various kinds of waveforms, which include square wave, triangle wave, sawtooth wave, sinusoidal wave, etc. The frequency and amplitude of the waveform generated by the signal generator can be adjusted, and the waveform of the signal can be arbitrarily changed by software.

3.1 Basic requirements

  • 1.Produce more than three kinds of waveforms, such as sinusoidal wave, triangle wave, rectangle wave, etc.

  • 2. The maximum frequency is no less than 500 Hz, and the frequency can be adjusted according to a certain law, such as the change according to the period of 1T,2T,3T,4T or 1T,2T,4T,8T.

  • 3. The amplitude is adjustable and the peak value varies from 0 to 5 V.

Extension requirements: generate more frequencies and waveforms.

Before we start, you can first watch the video to learn more about signal generator, which will help you in the following design: 

This video is about the function Generator Tutorial and Signal Generator / Function Generator basic

3.2 Scheme

  • General Scheme

The scheme is to use AT89C51 single-chip microcomputer and DAC0832 digital-to-analog converter to generate the waveform, and a low-pass filter is added to generate purer waveform.  Its characteristics are that it can generate arbitrary waveform, the frequency is easy to adjust, and the frequency can reach 500 Hz or more.High performance, good stability in low frequency range, easy operation, small volume and less power consumption.

This scheme can not only meet the basic requirements of curriculum design, but also give full play to its advantages, such as simple circuit, easy control and cost-effective.

  • Range Changing Scheme

Amplify the output voltage through an operational amplifier.The advantage is that the amplitude can be continuously adjustable. 


3.3 Operational principle

A digital signal can be converted into an analog signal by a digital-to-analog converter. Therefore, by generating digital signals and converting them into analog signals, we can obtain the required waveform. 89C51 MCU itself is a complete microcomputer, having all each part of the microcomputer: central processor CPU, random access memory (RAM), read-only memory (RAM), I / O interface circuit, timer / counter, serial communication interface and so on. As long as 89C51 is reconfigured with keyboard, digital-to-analog conversion, waveform output, amplifier circuit and so on, the needed waveform generator can be constructed. The system block diagram of the signal generator is shown in the following figure: 

The system block diagram of the signal generator--A Signal Generator Project Based on Single Chip Microcomputer 89C51

89C51 is the core part of the whole waveform generator. It generates a variety of signals and receives data through the programming and execution of the program. Data is received from the keyboard and then conversion of various functions and adjustment of signal amplitude are carried out. When the digital signal circuit arrives at the conversion circuit, it is converted into the analog signal, which is the required output waveform.

The waveform ROM table is to separate the signal into 64 points at equal intervals and stored in the single chip computer RON. The concrete ROM table is generated by MATLAB, such as sinusoidal table. The program generated by MATLAB is as follows:

x=0:2*pi/64:2*pi; y=round(sin(x)*127)+128


IV.Signal Generator Circuit Design and Analysis

4.1 The Main Circuit

In the design, we mainly adopt STC89C51 microcontroller, which has the following advantages: 

  • 1)Has perfect external extension bus, through which the peripheral unit can be expanded conveniently. 

  • 2)The MCU has 4K-byte FLASH ROM program memory space and 256-byte RAM data storage space, which can fully meet the requirements of the program. Because the chip can be electrically erased, it can be reused. If you want to change the content of the program, you can take down the chip and program it again. 

  • 3)The MCU is compatible with the instruction set and output pin of the industrial standard MCS-51 machine.

The interrupt system is set up so that the processor has the ability to handle external asynchronous events. When the CPU is processing something and an emergency occurred outside, it will request the CPU to suspend the current work and start to deal with the emergency.

In the waveform generator, two switches are directly connected to the pins of the external interrupt 0 and the external interrupt 1, wherein the S1 switch is used to change the waveform and S2 switch to change the frequency. In the main function of the program, we write a dead loop that will always output a default waveform. When S1 or S2 is pressed and lifted, the program will temporarily jump out of the dead loop and enter the interrupt system, thus changing the waveform and frequency.

Clock circuit. Because the delay time at each point of triangle wave, sinusoidal wave, square wave and other waves is several microseconds at a higher frequency, so delay time must be added to the instruction time to obtain the waveform of the specified frequency. The circuit uses 11.0592MHz crystal oscillator.

Signal Generator Clock circuit--A Signal Generator Project Based on Single Chip Microcomputer 89C51

4.2 Digital-to-analog conversion circuit

Because the single-chip produces the digital signal, in order to get the needed waveform, it is necessary to convert the digital signal into the analog signal. Therefore, here we choose the digital-to-analog converter DAC0832 which is with low cost, simple interface, easy conversion control and 8-bit resolution. DAC0832 is mainly composed of 8-bit input registers, 8-bit DAC registers, 8-bit DPA converter and the input control circuit. But actually, the output of the DAC0832 is not really continuously adjustable, it increases or decreases in absolute resolution, which is a quasi analog output. DAC0832 is a current-mode output. When applied, an op amplifier is plugged in to make it a voltage-mode output.

According to the different control mode of DAC0832 data latch and DAC register, DAC0832 has three working modes: Straight-through mode, single-buffer mode and double-buffer mode. In this article, we choose straight-through mode. 

The data port of DAC0832 is connected with the P0 port of the MCU.

CSDA:  Chip select signal input line (Strobe data latch), active low;

WR: Data Latch Strobe Input Lines, Negative pulse (pulse width greater than 500ns) validity. LE1 is generated by the logical combination of ILE, CS and WR1. When the LE1 is high, the input data is latched when the data latch state transforms. 

Digital-to-analog conversion circuit--A Signal Generator Project Based on Single Chip Microcomputer 89C51

4.3 Operational amplifier circuit and low pass filter circuit

Operational amplifier circuit and low pass filter circuit--A Signal Generator Project Based on Single Chip Microcomputer 89C51

The LM324's pin 5 is connected to the DAC0832's (IOUT2C) pin 12 and the LM324's pin 6 is connected to the DAC0832's (IOUT1C) pin 11. The LM324's pin 7 is connected to the DAC0832's (REF) pin 9.

The function of the first stage operational amplifier is to convert the current signal from DAC0832 to voltage signal V1, and the function of the second stage operational amplifier is to convert V1 through the reverse amplifier circuit.

It is required that the output voltage be adjustable at 0-5V, while the V1 voltage is about 5V, so R1 selects 5K resistor and R2 selects 10K potentiometer. The maximum output voltage is 5*(10/2)=10 and the minimum voltage is 0, which can achieve 0-5 V as required.

A low-pass filter is connected to the output of the second operational amplifier. Without the low-pass filter, the waveform can still be generated, but there are a lot of burrs in the generated signal. A low-pass filter can not only act as a filter, but also acts as a smoother in this circuit. The cutoff frequency of the low-pass filter is F=1/(2*pi*R3*C6). Here, we choose 100 ohms resistance as R3 and 104 capacitance as C6, and the cutoff frequency is F=16KHZ. The experimental results show that the output waveform is good at this time.

4.4 Serial communication circuit

UART (Universal Asynchronous Transceiver) is a kind of serial interface, which is usually included in general microprocessor. Asynchronous serial interface provides a simple way for two devices to communicate without sharing the same clock signal. If add an appropriate level converter MAX232, the serial port can be used in RS232, RS485 and other networks to achieve communication, or to connect with the computer's COM port. The serial port can be implemented only with two signal lines (RX and TX), and as long as both devices have the same bit format and baud rate, then they don't need any other information about each other. The data can be transferred successfully.

Serial communication circuit--A Signal Generator Project Based on Single Chip Microcomputer 89C51

V.The Design of System Software

Software design will divided into several modules programming according to the function: main program module, external interrupt 0 module, external interrupt 1 module.

  • Main program module

The main program first does some initialization work, and then enter the corresponding while loop according to the waveform sign a,b,c,d and e. The advantage of this writing is that the output waveform frequency can be more than 790 HZ. In the while loop, the single chip microcomputer constantly looks up the table according to the address flag bit, then assigns the value to the data port of the DAC0832, and then add 1 to the address flag bit, determine whether the address flag bit is equal to 64. If it is, then set 0 and make further execution. If not, then directly keep on the execution. And then the corresponding delay is carried out according to the frequency mark bit. The Main program flow chart is as following:

Main program flow chart--A Signal Generator Project Based on Single Chip Microcomputer 89C51

  • Interrupt service program

In this program, two external interrupts play the role of control waveform and frequency respectively. It is also add dithering elimination in the program. 

Interrupt service program--A Signal Generator Project Based on Single Chip Microcomputer 89C51

VI.Installation, Debugging and Measurement Data Analysis

6.1 Debugging process

  • 1. No power, use multimeter according to circuit diagram to carefully check whether the connection of each line is normal.

  • 2. First of all, debugging the MCU. DA and operational amplifier chip is not connected. Program under Serial Port with STC_ISP_V483 Software. See if it can be normally programmed.

  • 3., When you can normally program, program the 51 MCU to input 0 to I/0 ports, delay, and then output 1, and so on. Use multimeter to measure the voltage of each I/O port, and see whether it is high or low for a while.

  • 4. Install DA and operational amplifier chip, give a test program of output sine wave of single chip microcomputer, see if output is normal by oscilloscope.

  • 5.Write a complete program to the MCU. Respectively press S1, see whether the waveform changes. Press S2, see whether the frequency changes.

6.2 Frequency measurement data and System simulation waveforms

Period

T

2T

3T

4T

5T

6T

7T

8T

Theoretical value

798.6

399.3

266.2

199.7

159.7

133.1

114.1

99.8

Actual value

798.6

399.6

266.5

199.9

159.9

133.3

114.2

99.9

System simulation waveforms is as following:

Square waveSawtooth wave (STW)Sinusoidal wave

6.3 Effect analysis and Measuring apparatus

From the theoretical and practical values of Frequency measurement data , it can be seen that the frequency error is very small at T,2T,3T,4T,5T,6T,7T,8T. The final waveform output effect is also very good. The measuring apparatus is as following:

  • Oscilloscope (OSC)

  • DC regulated power supply 

  • Multimeter

VII.Summary

The design of signal generator based on single chip microcomputer involves a typical control process in the design of the signal generator. A single chip microcomputer controls an analog-to-digital converter (DAC0832) to generate the required current. Then the current output of the operational amplifier LM324 can be linearly converted into the voltage output, and then the voltage can be amplified by the operational amplifier to obtain a signal of sufficient amplitude. Through controlled by the program, a series of regular waveforms can be generated. Such a signal generator has a wide range of applications in the field of control.

VIII.Signal Generator Attachment

8.1 The whole circuit diagram

whole circuit--A Signal Generator Project Based on Single Chip Microcomputer 89C51

8.2 Source program

#include<reg51.h>

#define uchar unsigned char

#define uint unsigned int

sbit csda=P2^2;

sbit wr=P2^1;

sbit s1=P3^2;

sbit s2=P3^3;

uchar k=0,p=0,delay=0;

uchar bxxz=0;pinglv=0;

uchar a=1,b=0,c=0,d=0,e=0;

uchar code sin[64]={

135,145,158,167,176,188,199,209,218,226,234,240,245,249,252,254,254,253,251,247,243,237,230,222,213,204,193,182,170,158,

146,133,121,108,96,84,72,61,50,41,32,24,17,11,7,3,1,0,0,2,5,9,14,20,28,36,45,55,66,78,90,102,114,128

};

uchar code juxing[64]={

255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,

255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

};

uchar code juchi[64]={

0,4,8,12,16,20,24,28,32,36,40,45,49,53,57,61,65,69,73,77,81,85,89,93,97,101,105,109,113,117,121,125,130,134,138,142,

146,150,154,158,162,166,170,174,178,182,186,190,194,198,202,206,210,215,219,223,227,231,235,239,243,247,251,255

};

uchar code tixing[64]={

0,13,26,39,52,65,78,91,104,117,130,143,156,169,182,195,208,221,234,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,

247,247,247,247,247,247,247,242,229,216,203,190,177,164,151,138,125,112,99,86,73,60,47,34,21,8

};

uchar code sanjiao[64]={

0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,

248,240,232,224,216,208,200,192,184,176,168,160,152,144,136,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,0

};

void delay1()

{

int a,b;

for(a=1;a>0;a--)

for(b=122;b>0;b--);

}

void int0() interrupt 0

{

EX0=0;

delay1();

if(s1==0){

bxxz++;

if(bxxz==5)

bxxz=0;

switch(bxxz)

{

case 0 :

{a=1,b=0,c=0,d=0,e=0;}

break;

case 1 :

{a=0,b=1,c=0,d=0,e=0;}

break;

case 2 :

{a=1,b=0,c=1,d=0,e=0;}

break;

case 3 :

{a=0,b=0,c=0,d=1,e=0;}

break;

case 4 :

{a=0,b=0,c=0,d=0,e=1;}

break;

}

delay1();

while(!s1);

}

while(!s1);

EX0=1;

}

void int1() interrupt 2

{

EX1=0;

delay1();

if(s2==0){

p++;

if(p==8)

   p=0;

switch(p)

{

case 1 :

pinglv=3;

break;

case 2 :

pinglv=6;

break;

case 3 :

pinglv=9;

break;

case 4 :

pinglv=12;

break;

case 5 :

pinglv=15;

break;

case 6 :

pinglv=18;

break;

case 7 :

pinglv=21;

break;

default :

pinglv=0;

break;

}

delay1();

while(!s2);

}

while(!s2);

EX1=1;

}

void main()

{

csda=0;

wr=0;

EA=1;

IT0=1;

EX0=1;

IT1=1;

EX1=1;

while(1)

{

while(a)

{

 delay=pinglv;

P0=sin[k];

k++;

if(k==64)

k=0;

while(delay)            

    delay--;

}

while(b)

{

 delay=pinglv;

P0=juxing[k];

k++;

if(k==64)

k=0;

while(delay)           

    delay--;

}

while(c)

{

 delay=pinglv;

P0=juchi[k];

k++;

if(k==64)

k=0;

while(delay)            

    delay--;

}

while(d)

{

 delay=pinglv;

P0=tixing[k];

k++;

if(k==64)

k=0;

while(delay)            

    delay--;

}

while(e)

{

 delay=pinglv;

P0=sanjiao[k];

k++;

if(k==64)

k=0;

while(delay)            

    delay--;

}

}

}



Book Recommendation

  • Know your signal generators, (A Howard W. Sams photofact publication)

--Robert Gordon Middleton (Author)

  • How to use AF & RF signal generators Hardcover – 1977

--George deLucenay Leon  (Author)



Relevant information about "A Signal Generator Project Based on Single Chip Microcomputer 89C51"

About the article "A Signal Generator Project Based on Single Chip Microcomputer 89C51", If you have better ideas, don't hesitate to  write your thoughts in the following comment area. You also can find more articles about electronic semiconductor through Google search engine, or refer to the following related articles.



0 comment

Leave a Reply

Your email address will not be published.

 
 
   
Rating: