我目前正在从头编写飞行控制器,目前我正在使用该模块来解码传入的PPM信号。请记住,这是一个ISR,我的功能仅限于从接收器读取通道值。它工作完全没问题,但我想要一些反馈和改进(如果可能的话)。ISR如下:- void measureChannel(){
- int elapsedtime = t.read_us();
- //if any pulse shorter than 1000us, discard as garbage
- if(elapsedTime < 900){
- t.reset();
- return;
- }
- else{
- //if start/stop sequence, then set currentChannel = 1 and begin to read
- if(elapsedTime > 2100) {
- currentChannel = 1;
- t.reset();
- return;
- }
- //read channel value
- else if(elapsedTime >= 1000 && elapsedTime <= 2000){
- if(currentChannel == 1){
- channelVal[0] = elapsedTime;
- currentChannel = 2;
- t.reset();
- return;
- }
- else if(currentChannel == 2){
- channelVal[1] = elapsedTime;
- currentChannel = 3;
- t.reset();
- return;
- }
- else if(currentChannel == 3){
- channelVal[2] = elapsedTime;
- currentChannel = 4;
- t.reset();
- return;
- }
- else if(currentChannel == 4){
- channelVal[3] = elapsedTime;
- currentChannel = 5;
- t.reset();
- return;
- }
- else if(currentChannel == 5){
- channelVal[4] = elapsedTime;
- currentChannel = 6;
- t.reset();
- return;
- }
- else if(currentChannel == 6){
- channelVal[5] = elapsedTime;
- currentChannel = 0;
- t.reset();
- return;
- }
- }
- }
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>