单片机解码PPM信号
上述代码每个通道都要占用一个中断口。但是一般的Arduino只有数字口2、3具有中断功能,也就是说只能接两个通道。如果想使用更多的通道,就需要用mega了,mega有5个外部中断源。其实,还有一种简单办法可以用一个中断接收所有通道。这就是绕过接收机的解码电路,使用arduino直接对PPM信号解码。这种方式麻烦的地方是需要拆开接收机,把解码前的PPM信号引出来。
本文引用地址://m.amcfsurvey.com/article/201611/322110.htm![](http://m.amcfsurvey.com/editerupload/fetch/20161101/322110_2_0.jpg)
参考:http://diydrones.com/profiles/blogs/705844:BlogPost:38393
打开接收机后,寻找PPM信号接口有几种办法:
1.
查芯片资料,如Futaba接收机使用BU4015BF移位寄存器芯片,管脚1或9焊一根线引出即可。
2.
使用示波器
3.
使用arduino,写入测量脉宽的程序,在电路板上找吧,直到出现一些随机数估计就是了。
找到以后使用下面代码进行解码。此段代码使用查询方式,效率较低。更有效率的办法是使用两个中断。一个中断检测同步信号,另一个中断处理PPM信号。
ARDUINO 代码复制打印
-
//http://diydrones.com/profiles/blogs/705844:BlogPost:38393
-
#define channumber4//How many channels have your radio?
-
intvalue[channumber];
-
-
voidsetup()
-
{
-
Serial.begin(57600);//Serial Begin -
pinMode(3,INPUT);//Pin 3 as input -
}
-
voidloop()
-
{
-
while(pulseIn(3,LOW)<5000){}//Wait for the beginning of the frame -
for(intx=0; x<=channumber-1; x++)//Loop to store all the channel position -
{ -
value[x]=pulseIn(3,LOW); -
} -
for(intx=0; x<=channumber-1; x++)//Loop to print and clear all the channel readings -
{ -
Serial.print(value[x]);//Print the value -
Serial.print(" "); -
value[x]=0;//Clear the value afeter is printed -
} -
Serial.println("");//Start a new line -
}
评论