The minimum system of the single chip microcomputer realizes the control and control of the speed of the motor

The design uses a special chip to form the PWM signal generation system and elaborates on the principle and generation method of the PWM signal and how to adjust the duty cycle of the PWM signal by software programming to control the input signal waveform. In addition, the infrared pair tube is used to measure the rotational speed of the DC motor. After the shaping circuit, the measured value is sent to the single-chip microcomputer, and finally the feedback value is input to the single-chip microcomputer for PID operation, thereby realizing the control of the DC motor speed. In terms of software, the article describes in detail the writing ideas and specific program implementation of the PID program initialization program.

1 MCU minimum system: The minimum system of MCU consists of 51 MCU, crystal oscillator circuit, reset circuit and power supply. Everyone is familiar with it and will not go into details here.

2 Four-digit digital tube display: In the application system, the design requirements are different, and the number of LED displays used is different. Therefore, LED displays with different digits, sizes and models are available for selection. In this design, select 4 One-piece digital LED display, referred to as "4-LED". The first three digits of the system display the integer digits of the voltage, and the last digit displays the decimal places of the speed. The 4-LED display pin is shown in Figure 2. It is a 4-pole LED digital display tube with common cathode connection. Among them, a, b, c, e, f, g are the common output of each segment of the 4-bit LED. 2, 3, 4 are the digits of each digit, dp is the decimal point, the internal structure of the 4-integrated LED digital display tube is composed of 4 separate LEDs, and each LED segment output pin After being internally connected in parallel, they are led out to the outside of the device.

3 Motor drive circuit: The motor drive power is driven by ULN2003. ULN2003 is a high-voltage, high-current Darlington display consisting of seven silicon NPN Darlington tubes. The characteristics of this circuit: each pair of Darlington in ULN2003 is connected in series with a 2.7K base resistor. It can be directly connected to TTL and CMOS circuits at 5V operating voltage, and can directly handle the standard logic buffers that need to be processed directly. The data is input to a 5VTTL level and the output can be up to 500mA/50V. The pin diagram of ULN2003, where IN1~IN7 are the input control terminals; OUT1~OUT7 are the output terminals; 8 pins are the ground terminals of the chip; 9 pins are the common terminals, which are the common ends of the internal 7 freewheeling diode negative electrodes. The positive electrodes of the diodes are respectively connected to the collectors of the Darlington tubes. When used for inductive load, the pin is connected to the positive pole of the load power supply to achieve freewheeling. If the foot is grounded, it is actually the collector of the Darlington tube that is connected to ground.

When P1.0 is high, its internal transistor is turned on, causing the motor to rotate. When P1.0 is low, the internal triode is turned off, the circuit is disconnected, and the motor stops rotating. Therefore, in the program, the P1.0 port can be used to output PWM waves to control the motor speed.

4 Infrared speed measuring circuit: When the transmitting tube works, it emits infrared rays. When the receiving tube receives the infrared signal, its resistance becomes smaller (this design is equivalent to changing from infinity to about 1k). Use its resistance change to change the partial pressure of the receiving tube. The baffle is made by cutting four holes on the disc. When the baffle rotates with the motor, the level of the two ends of the receiving tube changes to generate a pulse.

5 shaping circuit: The shaping circuit of this design is a Schmitt trigger connected by 555 timer.

6 source program:

#include "reg52.h"

#define uchar unsigned char

#define uint unsigned int

Uchar code table[10]={0x3f,0x06,0x5b,

0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; // Common Yin digital display code (0-9)

Sbit xiaoshudian=P0^7;

Sbit wei1=P2^4; //Digital tube position selection

Sbit wei2=P2^5;

Sbit wei3=P2^6;

Sbit wei4=P2^7;

Sbit beep=P2^3; //buzzer control terminal

Sbit motor = P1^0; //Motor control

Sbit s1_jiasu = P1^4; //Speed ​​button

Sbit s2_jiansu= P1^5; //Deceleration button

Sbit s3_jiting=P1^6; //stop/start button

Uint pulse_count; //Number of pulses received by INT0

Uint num=0; //num is equivalent to the accuracy of the duty cycle adjustment

Uchar speed[3]; //four-bit speed value storage

Float bianhuasudu; // current speed (theoretical calculation)

Float reallyspeed; // actually measured speed

Float vv_min=0.0; vv_max=250.0;

Float vi_Ref=60.0; // given value

Float vi_PreError, vi_PreDerror;

Uint pwm=100; //equivalent to the duty cycle flag variable

Int sample_time=0; //sample flag

Float v_kp=1.2, v_ki=0.6, v_kd=0.2; //proportional, integral, differential constant

Void delay (uint z)

{

Uint x,y;

For(x=z;x>0;x--)

For (y=20;y>0;y--);

}

Void time_init()

{

ET1=1; //Allow timer T1 interrupt

ET0=1; //Allow timer T0 interrupt

TMOD = 0x15; //Timer 0 count, mode 1; Timer 1 timing, mode 1

TH1 = (65536-100)/256; //Timer 1 value, responsible for PID interrupt, 0.1ms timing

TL1 = (65536-100)%6;

TR0 = 1; //open timer

TR1 = 1;

IP=0X08; //Timer 1 is high priority

EA=1; //open total interruption

}

Void keyscan()

{

Float j;

If(s1_jiasu==0) //Acceleration

{

Delay(20);

If(s1_jiasu==0)

vi_Ref+=10;

j=vi_Ref;

}

While(s1_jiasu==0);

If(s2_jiansu==0) //Deceleration

{

Delay(20);

If(s2_jiansu==0)

vi_Ref-=10;

j=vi_Ref;

}

While(s2_jiansu==0);

If(s3_jiting==0)

{

Delay(20);

Motor=0;

P1=0X00;

P3=0X00;

P0=0x00;

}

While(s3_jiting==0);

}

Float v_PIDCalc(float vi_Ref,float vi_SpeedBack)

{

Register float error1,d_error,dd_error;

Error1=vi_Ref-vi_SpeedBack; //calculation of deviation

D_error=error1-vi_PreError; //error deviation

Dd_error=d_error-vi_PreDerror; //error rate of change

vi_PreError=error1; //store current deviation

vi_PreDerror=d_error;

Bianhuasudu=(v_kp*d_error+v_ki*vi_PreError+v_kd*dd_error);

Return (bianhuasudu);

}

Void v_Display()

{

Uint sudu;

Sudu=(int)(reallyspeed*10); //multiply by 10 to force conversion to integer

Speed[3]=sudu/1000; //100 digits

Speed[2]=(sudu00)/100; //ten place

Speed[1]=(sudu0)/10; //one bit

Speed[0]=sudu; //one after the decimal point

Wei1=0; //The first bit is open

P0=table[speed[3]];

Delay(5);

Wei1=1; //The first bit is closed

Wei2=0;

P0=table[speed[2]];

Delay(5);

Wei2=1;

Wei3=0;

P0=table[speed[1]];

Xiaoshudian=1;

Delay(5);

Wei3=1;

Wei4=0;

P0=table[speed[0]];

Delay(5);

Wei4=1;

}

Void BEEP()

{

If((reallyspeed)>=vi_Ref+5||(reallyspeed

{

Beep=~beep;

Delay(4);

}

}

Void main()

{

Time_init();

Motor=0;

While(1)

{

v_Display();

BEEP();

}

If(s3_jiting==0) //Scan button 3 to enhance emergency stop effect

{

Delay(20);

Motor=0;

P1=0X00;

P3=0X00;

P0=0x00;

}

While(s3_jiting==0);

}

Void timer0() interrupt 1

{

}

Void timer1() interrupt 3

{

TH1 = (65536-100)/256; //1ms timing

TL1 = (65536-100)%6;

Sample_time++;

If(sample_time==5000) //Sampling time 0.1ms*5000=0.5s

{

TR0=0; //turn off timer 0

Sample_time=0;

Pulse_count=TH0*255+TL0; //Save the current number of pulses

Keyscan (); / / scan button

Reallyspeed=pulse_count/(4*0.6); //calculation speed

Pwm=pwm+v_PIDCalc(vi_Ref, reallyyspeed);

If(pwm

If(pwm>100)pwm=100;

TH0=TL0=0;

TR0=1; //ON timer 0

}

Num++;

If(num==pwm) //The num value here is the duty cycle

{

Motor=0;

}

If(num==100) //100 is equivalent to the accuracy of the duty cycle adjustment

{

Num=0;

Motor=1;

}

}

Water Supply Pipe

PE (polyethylene) material is widely used in the field of water supply pipe manufacturing because of its high strength, corrosion resistance, non-toxic and other characteristics.

Because it does not rust, it is an ideal alternative to ordinary iron pipes. PE water supply pipe Implementation product national standard: GB/T 13663.1-2017, GB/T 13663.2-2018 polyethylene (PE) Pipeline System for Water Supply part 2: Pipe.

Crosslinked PE Pipe(Crosslinked Pe Pipe) using the first domestic co-extrusion irradiation technology, making the visible light barrier layer and ultraviolet absorption layer co-extrusion in the tube.
Our cross Linked Polyethylene Water Pipe can avoid sunlight transmission to make the water rich oxidation, and avoid bacteria, algae growth and other serious impact on water quality, pipeline transport and other serious of problems.

The Pex Cross Linked Polyethylene can avoid the aging phenomenon caused by exposure to ultraviolet rays in the atmosphere, which in turn improve the service life of the pipe.

Water Supply Pipe,Water Line Pipe,Pvc Pipe For Water Supply,Water Heater Flex Hose

CAS Applied Chemistry Materials Co.,Ltd. , https://www.casac1997.com