avr单片机测量电机转速_AVR | 控制简易直流电动机的转速

avr单片机测量电机转速

The simple concept that will be used here is similar like the cases that come in probability when two coins are tossed simultaneously, there our sample space would be HH, HT, TH, and TT.

这里将使用的简单概念类似于类似情况,即当同时抛掷两个硬币时,我们的样本空间将为HH,HT,TH和TT

Now in the case of DC motors consider 1 when our motor runs, and 0 if the motor doesn’t run. So here our sample space would be 11, 10, 01, and 00. Here all the four cases that we have to implement in our program that we will create.

现在对于直流电动机, 当我们的电动机运行时考虑1如果电动机不运行则 考虑 0 。 因此,这里的样本空间将为11、10、01和00 。 在这里,我们必须在将要创建的程序中实现的所有四种情况。

控制简单直流电机转速的程序 (Program to control revolution of simple DC motor)

#include <avr/io.h>

int main(void)
{

	DDRA=0x00;
	DDRD=0x33;
	
	while(1)
	{
		if((PINA&0x03)==0x03)
		{
			PORTD=0x11;
		}
		else if((PINA&0x03)==0x02)
		{
			PORTD=0x01;
		}
		else if((PINA&0x03)==0x01)
		{
			PORTD=0x10;
		}
		else if((PINA&0x03)==0x00)
		{
			PORTD=0x00;
		}
	}
}

Explanation:

说明:

  • Here, DDRA=0x00 represents the inputs that are to be given by both the buttons which are connected in the PORT A.

    在此, DDRA = 0x00表示由PORT A中连接的两个按钮提供的输入。

  • DDRD=0x03 represents the terminals in which our Motors are connected. Motor 1 is connected in terminal PD0 and PD1 while our motor 2 is connected in PD4 and PD5.

    DDRD = 0x03代表连接电机的端子。 电机1连接在端子PD0和PD1中,而我们的电机2连接在PD4和PD5中 。

PD7	PD6	PD5	PD4	PD3	PD2	PD1	PD1	
0	0	1	1	0	0	1	1

  • In the bottom line 0011 means 3 in hexadecimal so it is written as DDRD=0x33

    在最底行0011表示十六进制的3,因此它被写为DDRD = 0x33

  • Inside the while loop we will use if/else statements to write all our four conditions 11, 10, 01, 00.

    在while循环内,我们将使用if / else语句来编写所有四个条件11、10、01、00。

  • The first if statement states our condition 11, this is the condition when our both the buttons will be pressed and our both the motor will rotate here.

    第一个if语句说明我们的条件11,这是当我们两个按钮都将被按下并且我们两个电动机都将在此处旋转时的条件。

  • Inside the, if statement PINA & 0x03 is basically a statement which tells us the condition of number of button Pressed.

    在if语句内部, PINA&0x03基本上是一个告诉我们按下按钮数量状态的语句。

  • If both the buttons are pressed (0x03) then PORTD==0x11 i.e. both the motors will run simultaneously.

    如果同时按下两个按钮(0x03),则PORTD == 0x11,即两个电动机将同时运行。

  • If only second button is pressed (0x02) then PORTD==0x01 i.e. only first motor will start to rotate.

    如果仅按下第二个按钮(0x02),则PORTD == 0x01,即只有第一个电动机将开始旋转。

  • If only first button is pressed (0x01) then PORTD=0x10 i.e. only second motor will start to run.

    如果仅按下第一个按钮(0x01),则PORTD = 0x10,即仅第二个电动机将开始运行。

  • That last condition states that if no button is pressed (0x00) i.e. PORTD==0x00, here no motor will run.

    最后一个条件表明,如果未按下任何按钮(0x00),即PORTD == 0x00 ,则此处将没有电动机运行。

  • Simulation:

    模拟:

    AVR | Control the revolution of Simple DC motor

    Explanation:

    说明:

    • Device Required:

      所需设备:

      • Two Resistors of 10k ohm
      • Ground Terminal
      • Power Terminal
      • Two push buttons
      • Atmega16
      • Two simple Active DC motors (double click on them and change the value from 12v to 3v)
    • Arrange the components as shown in the figure above.

      如上图所示排列组件。

    • Change the motor voltage value as mentioned above.

      如上所述更改电动机电压值。

    • Debug the HEX file in the ATmega16.

      在ATmega16中调试HEX文件。

    • Click on the play button and your simulation will start.

      单击播放按钮,您的模拟将开始。

    TRICK:

    招:

    If after creating 2-3 programs if you have noticed that you face problem is writing code for the pins , than I would suggest you to first create the design of the simulation in the PROTEUS software then with reference to that write the Pin configurations in Program.

    如果在创建2-3个程序之后,如果您发现面临的问题是为引脚编写代码,那么我建议您首先在PROTEUS软件中创建仿真设计,然后参考在程序中编写引脚配置。

    翻译自: https://www.includehelp.com/embedded-system/control-the-revolution-of-simple-dc-motors.aspx

    avr单片机测量电机转速

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值