標(biāo)題:
Aduino之PWM控制實(shí)例 可以進(jìn)行DC Motor的控制速度
[打印本頁(yè)]
作者:
liucheng1973
時(shí)間:
2018-6-26 13:38
標(biāo)題:
Aduino之PWM控制實(shí)例 可以進(jìn)行DC Motor的控制速度
這個(gè)是用串口輸入數(shù)據(jù)進(jìn)行PWM控制的程序,實(shí)際用來(lái)可以進(jìn)行DC Motor的控制速度。
源程序如下:
#include <avr/wdt.h>
int duty = 0;
byte lo , hi;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.setTimeout(500); //setTimeout
pinMode(9,OUTPUT);
digitalWrite(2,LOW);
TCCR1A = 0;
TCCR1B = 0;
TCCR1A = _BV(WGM11) | _BV(WGM10) | _BV(COM1A1) | _BV(COM1B1);
// TCCR1A = _BV(WGM11) | _BV(WGM10);
TCCR1B = _BV(CS10) | _BV(WGM12);
OCR1A = 0;
OCR1B = 1000;
wdt_enable(WDTO_1S);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0)
{
lo = Serial.read(); //hi = 0x04, lo =0x00
// Serial.write(Serial.available());
if( Serial.readBytesUntil(240,&hi,1) != 0)
{
if( hi < 4)
{
duty = (hi << 8) + lo ;
OCR1A = duty;
// Serial.write(lo);
// Serial.write(hi);
}
else if(hi == 0x70)
Serial.write(lo);
}
// Serial.write(Serial.available());
}
wdt_reset();
}
void software_Reset()
{
asm volatile(" jmp 0");
}
復(fù)制代碼
所有資料51hei提供下載:
motorSetTimeout.zip
(819 Bytes, 下載次數(shù): 11)
2018-6-26 13:38 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
lm18007726198
時(shí)間:
2018-6-27 12:05
請(qǐng)問(wèn)怎樣接線
作者:
liucheng1973
時(shí)間:
2018-6-27 13:42
就用串口接收PC端發(fā)送Pluse數(shù)據(jù),由Aduino Pin 9輸出控制Mos管對(duì)DC motor電源進(jìn)行控制
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1