当前位置:网站首页>The simplest DIY actuator controller based on 51 single chip microcomputer
The simplest DIY actuator controller based on 51 single chip microcomputer
2022-06-23 11:00:00 【daodanjishui】
51 SCM Internet of things smart car series article catalog
Chapter one : The most simple DIY Of 51 Bluetooth remote control car design
Second articles : The most simple DIY Serial port Bluetooth hardware implementation scheme
Third articles : The most simple DIY bluetooth PS2 The remote control controls the Bluetooth smart car
Fourth articles : The most simple DIY be based on 51 Servo controller based on single chip microcomputer
List of articles
Preface
daodanjishui The simplest of the core original technologies of the Internet of things DIY be based on 51 Servo controller based on single chip microcomputer .
There are various open source intelligent steering gear controllers on the market , But there are complex and simple , If you want to get started quickly, it is based on 51 The servo controller of single chip microcomputer is matched with the intelligent car , This plan will give you a quick and efficient plan .
One 、 The most simple DIY be based on 51 What is the actuator controller of single chip microcomputer ?
In the first part, the design of Bluetooth remote control intelligent car is completed , Readers are curious about why there are in the source code PWM Control code ? But I was too lazy to delete it when I was writing a blog , Take up one more IO Mouth won't make a mistake . Now it's my fourth blog post :DIY be based on 51 Servo controller based on single chip microcomputer Buried the foreshadowing .
Although there are many open source steering gear controller solutions on the market , But it is all controlled by register configuration PWM Wave output code is very few , Now write it down in words , This code was developed by guotianxiang 51 SCM books copied from . I didn't create it , Later, there will be an original 51 PTZ design launched .
This time I use 51 SCM development board to do the steering gear control , It mainly uses the buttons above .
51 The SCM development board is as follows :
Two 、 analysis
1. Prepare the hardware
1.1 Buy sg90 The steering gear (180 Steering gear ) As shown in the figure below :
Complete the wiring between MCU and steering gear :
sbit pwm =P2^7 ; //PWM Signal output , Connect the data cable of the steering gear
1.2 Get ready 51 Single chip microcomputer
Buy single chip microcomputer by yourself
2. Parsing code
This 51 The code of single chip microcomputer is also quite simple , Although it is written in register , But it is also a very classic one PWM Wave generation procedure ! The code is as follows , comparison arduino Control procedure of , This code is much more valuable ! Later I will launch STM32 Version of the steering gear control program , In fact, it is also completed by using the idea of this program for reference .
#include "reg52.h"
unsigned char count; //0.5ms Number identification
sbit pwm =P2^7 ; //PWM Signal output , Connect the data cable of the steering gear
sbit jia =P3^7; // Angle increase button
sbit jan =P3^6; // Angle decrease button , Low level trigger
unsigned char jd; // Angle identification 1.0ms->45 1.5->90 2.0->135 2.5->180
void delay(unsigned char i)// Ordinary delay function
{
unsigned char j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void Time0_Init() // Timer 0 initialization
{
TMOD = 0x01; // Timer 0 Work in the way 1,16 Bit increment count timer ,16 All of them 1, The maximum count value is 65535, It overflowed
IE = 0x82;//EA=1 Global interrupts allow ,ET0=1, Timer interrupt allows
TH0 = 0xfe;//(65536-N)/256=0xef=254 Introduction N=512,N Is the number that needs to be counted , The machine cycle is 1.09us, therefore
//512*1.09us=0.5ms, At this time, the steering gear is 0 degree ,1ms yes 45 degree ,2.5ms yes 180 degree , Other analogies
TL0 = 0x33; //11.0592MHz Single chip microcomputer of crystal oscillator , Lead to 0.5ms The counter overflows once , Generate timer interrupt
TR0=1; // Turn on timer
}
void Time0_Int() interrupt 1 // Timer 0 Interrupt service routine
{
TH0 = 0xfe; // Reload the initial value
TL0 = 0x33;
if(count< jd) // Judge whether the counting times are less than the identification
pwm=1; // Output high level PWM
else
pwm=0; // Low level PWM
count=(count+1); // Count times continue to increase
count=count%40; // Count times must be less than 40, because 0.5ms*40=20ms, This is the steering gear PWM A fixed period of
}
void keyscan() // Key scan
{
if(jia==0) // Press the Add button
{
delay(10); // Eliminate jitter
if(jia==0) // Press the Add button
{
jd++; // Logo added , Altogether 5 files ,jd=1 Corresponding 0 degree ,jd=2 Corresponding 0,45 degree ,jd=3 Corresponding 90,4 Corresponding 135,5 Corresponding 180 degree
count=0; // Count clear 0, When count Add to 2 When , Overflow twice , Time is 0.5*2=1ms, Turn the corresponding steering gear to 45 degree
if(jd==6)
jd=5; // Identification clear 0
while(jia==0); // Wait for the key to release
}
}
if(jan==0) // Press the decrease button
{
delay(10);
if(jan==0)
{
jd--; // Empathy
count=0;
if(jd==0)
jd=1; // Reset
while(jan==0);
}
}
}
void main()
{
jd=1;
count=0;
Time0_Init();
while(1)
{
keyscan(); // Dead cycle , Key detection
}
}
3. Principle analysis of steering gear
According to how it works , The specific control method of the steering gear needs a 20ms Left and right time base pulses , The high level part of the pulse is generally 0.5ms2.5ms Angle control pulse part in range . The pulse width ranges from 0.5ms2.5ms, The position of the corresponding rudder is 0~180 degree , It changes linearly . General steering gear pulse width 20ms, Correspondence between high level width and angle
0.5ms————0 degree ;
1.0ms————45 degree ;
1.5ms————90 degree ;
2.0ms————135 degree ;
2.5ms————180 degree ;
According to the above principle , We know that as long as a single-chip computer produces 20ms Pulse signal of , By changing the high level time from 0.5ms To 2.5ms change , The steering gear can be turned to the corresponding angle . Finally, the function of the program is to press the Add button , Steering gear from 0 C to 180 , Press 5 Time ; Steering gear from 180 To 0 Also need to press 5 Time reduction button .
3、 ... and 、 Simulation and debugging
1. Get the hardware ready , Access to electricity .
The hardware connection is relatively simple .
2. Control the steering gear
Press the Add button , Steering gear from 0 C to 180 , Press 5 Time ; Steering gear from 180 To 0 Also need to press 5 Time reduction button .
summary
Just learned 51 SCM readers had better get started with this code , Yes 51 There is a deep understanding of the use of SCM registers , It will lay a solid foundation for the future manipulator control and intelligent car speed regulation .
Download project code :https://www.cirmall.com/circuit/20977/
Point, I'll jump
边栏推荐
- Noi OJ 1.2 integer data type storage space size
- 长安LUMIN是否有能力成为微电市场的破局产品
- Go zero micro Service Practice Series (VI. cache consistency assurance)
- “互联网+”大赛命题火热对接中 | 一图读懂百度38道命题
- NOI OJ 1.3 05:计算分数的浮点数值 C语言
- 力扣 1319. 连通网络的操作次数
- Noi OJ 1.3 04: C language with remainder Division
- New technology aesthetics and original biological networking operating system reshape the whole house intelligence
- NFS挂载时一直没有同步文件
- MAUI使用Masa blazor组件库
猜你喜欢

Maui uses Masa blazor component library

六张图详解LinkedList 源码解析

After repeated pressure, Apple may significantly increase the price of iphone14

Picture storage -- Reference

智慧园区效果不满意?请收下ThingJS这份秘籍

Cool photo album code, happy birthday to the object!

社招腾讯高P(高级产品经理)的面试手册

MAUI使用Masa blazor组件库

New technology aesthetics and original biological networking operating system reshape the whole house intelligence

Flutter series: wrap in flutter
随机推荐
Noi OJ 1.3 09: circle related computing C language
list的深度剖析及模拟实现
深潜Kotlin协程(十四):共享状态的问题
Description of directory files of TLBB series of Tianlong Babu - netbill server [ultra detailed]
NOI OJ 1.2 10:Hello, World! Size of C language
JVM easy start-02
Unity technical manual - lifecycle lifetimebyemitterspeed - color in the cycle coloroverlifetime- speed color colorbyspeed
最简单DIY基于STM32的远程控制电脑系统②(无线遥杆+按键控制)
NOI OJ 1.2 整型与布尔型的转换 C语言
Share a mobile game script source code
[Architect (Part 40)] connecting mongodb database developed by server
Mysql-03. Experience of SQL optimization in work
torch权重转mindspore
Simplest DIY mpu6050 gyroscope attitude control actuator program based on stm32f407 Explorer development board
Noi OJ 1.2 integer data type storage space size
最简单DIY基于51单片机、PCA9685、IIC、云台的舵机集群控制程序
Analysis of LinkedList source code
Noi OJ 1.3 11: C language for calculating the remainder of the division of floating-point numbers
Noi OJ 1.4 05: integer size comparison C language
Noi OJ 1.3 14: elephant drinking water C language