arduino 驱动电调
2019-04-13 14:17发布
生成海报


#include
#define PPMPIN 7
byte ppm=1; //0-9
byte count=0;
void setup() {
// put your setup code here, to run once:
pinMode(PPMPIN,OUTPUT);
Serial.begin(9600);
Timer1.initialize(100);// 设置定时器中断时间,单位微秒,此处为1秒
Timer1.attachInterrupt( timerIsr ); // 打开定时器中断
}
void loop() {
// put your main code here, to run repeatedly:
while(Serial.available()){
char c= Serial.read();
if(c>='0' && c<='9'){
ppm=((byte)c) - 38;
Serial.println(ppm);
}
}
}
//定时器中断处理函数
void timerIsr()
{
if(count>200)count=0;
if(count<=ppm){
digitalWrite(PPMPIN,HIGH);
}else{
digitalWrite(PPMPIN,LOW);
}
count++;
}
View Code
采用TimeOne组件,这个通过T/C定时触发中断处理, 设置100微秒,每次中断累加1,直到200,这样产生的50HZ的PWM,控制比较参数ppm可以调节脉款
电调低油门是0.7ms高油门是1.7ms
可以设置ppm1,ppm2,ppm3等多个输出,
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮