当前位置:网站首页>MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program

MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program

2022-04-23 14:25:00 Jiang Yuzhi

The design requirements

  1. With MCS-51 Series single chip microcomputer is the control device , use C Language for program development , Combined with peripheral electronic circuits , Design a function signal generator system ;

  2. Can produce a sine wave 、 square wave 、 Triangular wave and sawtooth wave 4 Kinds of waveform ;

  3. Extended keyboard input circuit , Used to switch the waveform type 、 Set the frequency size and step value ;

  4. LCD1602 The display circuit displays the current waveform type in real time 、 Frequency value and other information ;

  5. Adjustment range of waveform frequency value :10~100Hz;

  6. Frequency step value adjustment range :0.1~10Hz;

System Overview
This article is based on 51 Function signal generator system designed by single chip microcomputer , Can produce a sine wave 、 square wave 、 Triangular wave and sawtooth wave 4 Kinds of waveform , And the waveform frequency is adjustable , The adjustment range is 10~100Hz.

System consists of 5V Power supply module 、AT89C51 Minimum system of single chip microcomputer 、DAC0832 A / D conversion circuit 、LM358 Amplification circuit 、LCD1602 LCD circuit 、 Key circuit and LED The indicator circuit consists of .

The system framework is as follows :
 Insert picture description here
Working principle is : Digital signal generated by single chip microcomputer , the DAC0832 Convert to analog signal , Re pass LM358 After the operation circuit is amplified , Output 4 A waveform with adjustable frequency .

The type and frequency value of the waveform are determined by LCD Liquid crystal display (LCD) , The switching of waveform and the adjustment of frequency are controlled by keys . meanwhile ,4 A different color LED As indicator lights of different waveforms .

Simulation circuit diagram
 Insert picture description here
 Insert picture description here
Schematic diagram
 Insert picture description here
Analysis of simulation results
Open the function signal generator simulation file , Double click the MCU to load Signal.hex file ( be located C In the program folder ), Run the simulation , give the result as follows .

LCD1602 The first line of LCD shows Wave:Sine, The second line shows Freq:10.0Hz. Indicates that the current initialization waveform is 10Hz The sine wave of , At the same time, the green corresponding to the sine wave LED The light is on .

Besides , The system will pop up the oscilloscope window automatically , Display the waveform . In this system , The signal output terminal is connected to the... Of the oscilloscope A passageway .
 Insert picture description here  Insert picture description here
Simulation runtime , If the oscilloscope window is accidentally closed or does not pop up , Right click the oscilloscope , Click... In the drop-down menu Digtal Oscilloscope Can be restored .

In the system , Four keys are used to control the switching of waveform types 、 Increase or decrease of frequency value and increase or decrease of frequency step value .

Click on “ Switch ” key , Sine wave can be realized 、 square wave 、 Triangular wave and sawtooth wave 4 Switching back and forth between waveforms ;

In waveform frequency display mode ,“ increase ” and “ Reduce ” Key is used to increase or decrease the frequency of the current waveform , The default frequency step value of the system is 0.1, Press once “ increase ” or “ Reduce ” key , The change of frequency is 0.1Hz.

for example , We switch the waveform to square wave , Set its frequency to 14.5Hz, give the result as follows . here , Red corresponding to square wave LED The light is on .
 Insert picture description here  Insert picture description here
When pressed “ Stepping ” Post key , The system enters the step adjustment mode , As shown in the figure below .LCD Show Step value:0.1, Indicates that the current step value is 0.1Hz. here ,“ increase ” and “ Reduce ” key , Used to change the size of the step value .
 Insert picture description here
for example , We set the frequency step value to 3Hz, The results are shown below . After setting , Press again “ Stepping ” key , The system exits the step adjustment mode , Return to frequency display mode . At this time , Press down “ increase ” or “ Reduce ” key , The change amplitude of the frequency value is 3Hz. Insert picture description here
below , We set the system output frequency to 50Hz Triangular wave sum 80Hz The square wave , give the result as follows .
 Insert picture description here  Insert picture description here

 Insert picture description here  Insert picture description here
in summary , The operation effect of the function signal generator simulation circuit meets the design requirements , Verify success .

part C Code

void keyscan()					// Key scan function 
{
    
	if(s1==0)					// Whether the frequency plus key is pressed 
	{
    	 
		EA=0;					// Turn off interrupt 
		delay(2);				// Delay chattering 
		if(s1==0)				// Judge again 
		{
    
			while(!s1);			// Release the button 
			pinlv+=bujin;		// The frequency increases in steps 
			if(pinlv>1000)		// The frequency value is maximum 100Hz
			{
    
				pinlv=100;
			}
			display();
/* The minimum frequency value is 10Hz,pinlv The value of is 100( Because you want to display one decimal place ),150000/100=1500, This 1500 That's what the timer needs to count , The unit is us,65536-1500 What you get is the initial value of the timer ,  Regardless of the initial value , Look at the timing first ,1500us, The period of a waveform is determined by 64 Composed of two timing , therefore , A waveform period is 64*1500us=96000, That is to say 96ms, Appointment etc   On 100ms, That is to say 10Hz The frequency of */
			m=65536-(150000/pinlv);	  // Calculate the frequency 
			a=m/256;				  // Assign the initial value of the timer to the variable 
			b=m%256;
			EA=1;					  // Turn on the interrupt master switch 
		}
	}
	if(s2==0)					  // Whether the frequency reduction key is pressed 
	{
    	 
		
		delay(5);
		if(s2==0)
		{
    
			EA=0;	
			while(!s2);
			pinlv-=bujin;
			if(pinlv<100)
			{
    
				pinlv=1000;
			}
			display();
			m=65536-(150000/pinlv);
			a=m/256;
			b=m%256;	
			EA=1;
		}
	}
	if(s3==0)					   // Whether the waveform switching key is pressed 
	{
    	 
		delay(5);
		if(s3==0)
		{
    
			EA=0;
			while(!s3);
			boxing++;
			if(boxing>=4)
			{
    
				boxing=0;
			}
			display();
			EA=1;
		}
	}	
}

Resource content
(1) be based on 51 MCU function signal generator design paper complete version ;
(2)Keil C Program ;
(3)Proteus Simulation ;
(4) Schematic file ;
(5)Visio Flow chart file ;
(6) List of components ;
(7) Reference material ;

Resource screenshot
 Insert picture description here
 Insert picture description here
 Insert picture description here  Insert picture description here  Insert picture description here
 Insert picture description here
Say the important thing again !!!

Because the design of function signal generator is my original design , Get a full set of information ,

WeChat search for my official account : Jiaoyuan Xiaozhi

版权声明
本文为[Jiang Yuzhi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231412471782.html