417 views|1 replies

15

Posts

5

Resources
The OP
 

【51 articles】(7-1)C51 single chip microcomputer realizes key-controlled MAX517 four waveform outputs and displays [Copy link]

This post was last edited by QuaX_Chow on 2024-8-21 22:12

Please read the statement and notes of this series first:

The project source code and simulation file entry is at the end of the article. If it is not displayed, it is still under review.

Task requirements: Use C51 to realize four-button control of MAX517 to generate square wave, triangle wave, sawtooth wave and sine wave respectively. The waveform is displayed through the oscilloscope in Proteus. Connect four button switches to P2.0~P2.3, corresponding to the four waveforms respectively; the clock signal is generated by, and there is no output when no button is pressed at the beginning

To achieve the above functions, we need to split the task into the following parts:

  1. MAX517 Communications
  2. Interrupt key judgment

1. Proteus part

The waveform display uses the "OSCILLOSCOPE" four-channel oscilloscope in virtual instrument mode:

The constructed simulation circuit is as follows:

If you accidentally close the waveform display window during simulation, just click "Debug"-"Digital Oscilloscope" in the menu bar in the simulation state to display the oscilloscope interface.

2. Code part

(1) MAX517 communication

Before we drive the MAX517, we first need to sort out the timing of this chip

Driving MAX517 requires a two-wire serial interface, compatible with IIC

See the figure below:

One clock line and one data line. The declaration is as follows:

sbit SCL = P1^0;//MAX517串行时钟
sbit SDA = P1^1;//MAX517串行数据

The start state is marked by the clock line high and the data line falling edge. The end state is marked by the clock line high and the data line rising edge.

When programming, we need to use GPIO for simulation according to the chip timing.

Take SC as an example to write a function:

void start(void)//起始条件子程序
{
	SDA= 1;
	SCL = 1;
	_nop_();
	SDA =0;
	_nop_();
}

The complete transmission process is as follows:

To control the analog output of MAX517, you need to write a function with a complete process according to the steps in the figure above: start-send address-response-command-response-data-response-end:

void DACOut (uchar ch)//串行D/A转换子程序
{
	start();//发送启动信号
	send(0x58);//发送地址字节
	ack();
	send(0x00);//发送命令字节
	ack();
	send(ch);//发送数据字节
	ack();
	stop();//结束一次转换
}

If we need to output a specified voltage, we only need DACOut(required value);

The formula is as follows:

V_{OUT}=V_{REF}\times \frac{ch}{256}

But what we need to output is a waveform, not a stable level, so we need to keep changing the output analog value ch.

Taking the output of sine wave as an example, create an array to store the value of ch , and only need to increment the element when outputting:

uchar sindata[64]=
	{	0x80,0x8c,0x98,0xa5,0xb0,0xbc,0xc7,0xd1,
		0xda,0xe2,0xea,0xf0,0xf6,0xfa,0xfd,0xff,
		0xff,0xff,0xfd,0xfa,0xf6,0xf0,0xea,0xe3,
		0xda,0xd1,0xc7,0xbc,0xb1,0xa5,0x99,0x8c,
		0x80,0x73,0x67,0x5b,0x4f,0x43,0x39,0x2e,
		0x25,0x1d,0x15,0xf,0x9,0x5,0x2,0x0,0x0,
		0x0,0x2,0x5,0x9,0xe,0x15,0x1c,0x25,0x2e,
		0x38,0x43,0x4e,0x5a,0x66,0x73};

The implementation ideas of square wave, sawtooth wave and triangle wave are similar. You can increase, decrease and delay in the loop. For specific methods, please refer to the source code at the end of the article.

(2) Interrupt key judgment

To realize the function of switching the output waveform immediately, we need to use external interrupt 0. The interrupt service function is as follows:

void intp0() interrupt 0
{
	if(P2_0 == 0) key = 0;//三角波
	if(P2_1 == 0) key = 1;//方波
	if(P2_2 == 0) key = 2;//正弦
	if(P2_3 == 0) key = 3;//锯齿波
}


The four waveform output effects are as follows:

Mission accomplished


2024/8/21

Source code and simulation files

#This article was first published on EEWORLD, copyright belongs to the author

This post is from 51mcu

Latest reply

MAX517 can also be used as a multi-slave device, but the hardware connection of pins 5 and 6 needs to be modified.   Details Published on 2024-8-27 14:25

赞赏

1

查看全部赞赏

Personal signature

有无生境自得其功

 

1

Posts

0

Resources
2
 

MAX517 can also be used as a multi-slave device, but the hardware connection of pins 5 and 6 needs to be modified.

This post is from 51mcu
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
MATLAB APP Designer serial port debugging tool writing

This post was last edited by lb8820265 on 2019-5-9 23:11 Previously, we introduced two ways to use VC6 to make serial ...

About the original picture and packaging

Does anyone have the original picture and package of STM32F103 series?

How to use CPLD to collect asynchronous signals

Scenario: Use CPLD to decode a serial data channel. The data has no accompanying clock and has a fixed frequency but a d ...

Measuring poles and zeros from a Bode plot

This post was last edited by Jack315 on 2021-1-25 00:52 The transfer function of a single zero is: 522846 The Bode plot ...

Encoder counting principle and motor speed measurement principle - multi-picture analysis

This post was last edited by DDZZ669 on 2021-2-14 23:30 Encoder is a sensor used to measure mechanical rotation or displ ...

35 "Ten Thousand Miles" Raspberry Pi Car——ROS Learning (Realizing Hello World)

The best way to learn ROS is to use it. The ROS official website has a Chinese version of the tutorial . After install ...

36 "Ten Thousand Miles" Raspberry Pi Car——ROS Learning (VSCode to Implement Hello World)

It is very convenient to run ROS projects in VSCode. In this section, we use ROS to write and run the "Hello world" pro ...

[The strongest open source] Hand-rubbed 120W switching power supply

I recently took the time to make a switching power supply 645265 645262 645263 645264 645261 645260

Record a blue screen pit

I mentioned a while ago that my company's computers would occasionally blue screen. Now I think about it, the blue scree ...

ESP8266 01+DHT11 acquisition

Could anyone give me some advice? When I collect DHT11 data through one of GPIO 0 and 2, the 8266 01 keeps restarting. O ...

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list