新闻中心

EEPW首页>嵌入式系统>设计应用> 单片机解码PPM信号

单片机解码PPM信号

作者: 时间:2016-11-27 来源:网络 收藏


上述代码每个通道都要占用一个中断口。但是一般的Arduino只有数字口2、3具有中断功能,也就是说只能接两个通道。如果想使用更多的通道,就需要用mega了,mega有5个外部中断源。其实,还有一种简单办法可以用一个中断接收所有通道。这就是绕过接收机的解码电路,使用arduino直接对PPM信号解码。这种方式麻烦的地方是需要拆开接收机,把解码前的PPM信号引出来。

本文引用地址://m.amcfsurvey.com/article/201611/322110.htm


参考:http://diydrones.com/profiles/blogs/705844:BlogPost:38393
打开接收机后,寻找PPM信号接口有几种办法:

1. 查芯片资料,如Futaba接收机使用BU4015BF移位寄存器芯片,管脚1或9焊一根线引出即可。
2. 使用示波器
3. 使用arduino,写入测量脉宽的程序,在电路板上找吧,直到出现一些随机数估计就是了。
找到以后使用下面代码进行解码。此段代码使用查询方式,效率较低。更有效率的办法是使用两个中断。一个中断检测同步信号,另一个中断处理PPM信号。




ARDUINO 代码复制打印

        
  1. //http://diydrones.com/profiles/blogs/705844:BlogPost:38393
  2. #define channumber4//How many channels have your radio?
  3. intvalue[channumber];
  4. voidsetup()
  5. {
  6. Serial.begin(57600);//Serial Begin
  7. pinMode(3,INPUT);//Pin 3 as input
  8. }
  9. voidloop()
  10. {
  11. while(pulseIn(3,LOW)<5000){}//Wait for the beginning of the frame
  12. for(intx=0; x<=channumber-1; x++)//Loop to store all the channel position
  13. {
  14. value[x]=pulseIn(3,LOW);
  15. }
  16. for(intx=0; x<=channumber-1; x++)//Loop to print and clear all the channel readings
  17. {
  18. Serial.print(value[x]);//Print the value
  19. Serial.print(" ");
  20. value[x]=0;//Clear the value afeter is printed
  21. }
  22. Serial.println("");//Start a new line
  23. }


上一页 1 2 下一页

关键词:单片机解码PPM信

评论


技术专区

关闭