avr控制电机运行_AVR | 使用电机驱动器运行电机

avr控制电机运行

The coding used here will be similar to the last coding in which we used to run two motors along with their individual switch.

此处使用的编码将类似于上次编码,在该编码中,我们曾经同时运行两个电动机及其各自的开关

The concept used here will be also similar to the last program that we created.

这里使用的概念也将类似于我们创建的上一个程序

I’ll try to again explain you all the things shortly.

我将尽力再次向您解释所有事情。

Program:

程序:

#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;
		}
	}
	return 0;
}

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 。

  • 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 | Using a Motor Driver to run Motors

    Explanation:

    说明:

    • Device Required:

      所需设备:

      1. Two Resistors of 10k ohm
      2. Ground Terminals
      3. Power Terminals
      4. Two push buttons
      5. Atmega16
      6. Two simple Active DC motors (double click on them and change the value from 12v to 3v)
      7. L293D motor Driver
    • Arrange the components as shown in the figure above.

      如上图所示排列组件。

    • This time connect the output pins of ATmega16 to the input pins of the Motor Driver as shown.

      如图所示,这一次将ATmega16的输出引脚连接到电机驱动器的输入引脚。

    • Then connect the output pins of the motor driver to Both the Motors as shown in figure.

      如图所示,然后将电动机驱动器的输出引脚连接到“两个电动机”。

    • Connect both the GND pins of the motor driver to the ground terminal.

      将电动机驱动器的两个GND引脚连接到接地端子。

    • Connect VSS, EN1, EN2 pins to the Power terminal as shown.

      如图所示,将VSS,EN1,EN2引脚连接到电源端子。

    • Double click on this power terminal and assign it a value of +5v.

      双击该电源端子并为其分配+ 5v的值。

    • The VS terminal of motor driver always remains on high potential more than normal. Therefore we have assigned it a value of +12v.(Double click on it and assign the value of +12v).

      电机驱动器的VS端子始终保持比正常更高的高电势。 因此,我们为其分配了+ 12v的值。(双击它并分配+ 12v的值)。

    • 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.

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

    Here, you will notice that your motors will be revolving faster than the last program you created. This is all due to the motor Driver (L293D) that we have created here and this explains the Basic principal/use of the Motor Driver.

    在这里,您会注意到您的电动机旋转速度比您创建的上一个程序快。 这全都归功于我们在此处创建的电机驱动器(L293D),这解释了电机驱动器的基本原理/用法。

    翻译自: https://www.includehelp.com/embedded-system/using-a-motor-driver-to-run-motors-in-avr.aspx

    avr控制电机运行

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值