1.直流电机介绍
直流电机是一种将电能转换为机械能的装置。一般的直流电机有两个电机,当电机正接时电机正转,反之亦然
?2.电机驱动电路

?第一种只能单向转向,第二种是可以正反转(常用第二种)
3.PWM介绍
1.PWM既是脉冲宽度调试,在具有惯性的系统中,可以通过一系列脉冲宽度进行调式,来等效的获取需要的模拟参量,常用于电机控速,开关电源等领域?
2.PWM重要参数:
频率=1/Ts? ? ? 占空比=Ton/Tsn? ? ?精度=占空比变化步距

?4.定时器产生PWNM的方法

?main.c
#include <REGX52.H>
#include "Delay.h"
#include "Key.h"
#include "Nixie.h"
#include "Timer0.h"
sbit Motor=P1^0;
sbit LDE=P2^7;
unsigned char Counter,Compare; //计数值和比较值,用于输出PWM
unsigned char KeyNum,Speed;
void main()
{
Timer0_Init();
while(1)
{
KeyNum=Key();
if(KeyNum==1)
{
Speed++;
Speed%=4;
if(Speed==0){Compare=0;} //设置比较值,改变PWM占空比
if(Speed==1){Compare=50;}
if(Speed==2){Compare=75;}
if(Speed==3){Compare=100;}
}
Nixie(4,Speed);
}
}
void Timer0_Routine() interrupt 1
{
TL0 = 0x9C; //设置定时初值
TH0 = 0xFF; //设置定时初值
Counter++;
Counter%=100; //计数值变化范围限制在0~99
if(Counter<Compare) //计数值小于比较值
{
LDE=0;
Motor=1; //输出1
}
else //计数值大于比较值
{
LDE=1;
Motor=0; //输出0
}
}
|