6 years, 6 months ago.

Read and Generate PPM

Hi, I have a problem with my project, where I read a PPM signal from receiver FS-iA6B and then generate new signal. I want to update the input signal according to ultrasonic sensor and output it to quadcopter fly controller. Hoverwer, It seems that when I have the InpurruptIn in a class, then It doesnt work. I tried it have the "fall" method in main and it worked well. But I want to have it nice :)

The classes are here: https://os.mbed.com/users/edy05/code/PPM2/ The PPMOut works well (not my job), but the PPMIn which I created doesn't work (in class).

Maybe are the interrupts fighting between each other, I don't know. Usually, I have to press reset button on my LPC1768 a few times to at least print values from PPMOut, sometimes it print also the PPM In values, sometimes do nothing. Please help.

This is my main.cpp

include the mbed library with this snippet

#include "mbed.h"
#include "PPMOut.h"
#include "PPMIn.h"
//#include "PPMIn.h"
//#include "ultrasonic.h"
//#include "MyPID.h"


#define AUX1 4
#define PIEZZO_START 0.1
#define PIEZZO_STOP 0.0
#define PPMOUT_CHANNELS 6
#define PPMIN_CHANNELS 8

Serial pc(USBTX, USBRX); // tx, rx
PpmOut ppmOut(p26, PPMOUT_CHANNELS);
PpmIn ppmIn(p21);


uint16_t ppmOutChannelsValue[PPMOUT_CHANNELS];
uint16_t ppmInChannelsValue[PPMIN_CHANNELS];

//FUNCTIONS
void print_ppmOut(void);
void print_ppmIn(void);

int main(){
        
    while(1){
        print_ppmIn();
        print_ppmOut();
        
        if(ppmIn.rise_captured()){
            pc.printf("Rise captured \n\r");
        }
                        
    }
        
}


void print_ppmOut(){
    ppmOut.getAllChannels(ppmOutChannelsValue);
            
    for(uint8_t channel= 0; channel < PPMOUT_CHANNELS; channel++){
        pc.printf("PPM Out Channel %d: %d \n\r", channel, ppmOutChannelsValue[channel]);
    }
}

void print_ppmIn(){
    ppmIn.getAllChannels(ppmInChannelsValue);
    for(uint8_t channel= 0; channel < PPMIN_CHANNELS; channel++){
        pc.printf("PPM In Channel %d: %d \n\r", channel, ppmInChannelsValue[channel]);
    }
    pc.printf("\n\r");
}

1 Answer

6 years, 6 months ago.

How often do your interrupts fire? It would be interesting to see if you can get rid of the problem by busy-looping and just reading the state of a pin, instead of relying on interrupts. You can run this code in a high priority thread.

Best way to find out what is really happening is to attach a debugger and look at what happens when the application crashes.

Accepted Answer

I tried to use Keli and debug the program, but even I updated firmware to version which support CMSIS-DAP I couldn't make it work - CMSIS-DAP did not shown in manager devices on my windows pc.

I figured it out this way - I have only 1 class which read PPM signal using interrupt and generate 4x PwmOut. Its much more reliable and accurate, than reading and generating PPM signal and doing it in 2 classes.

I also tried generate PPM signal in class with Thread using RtosTimer, but than I found that RtosTimer is only for task with rate 1ms and more. I needed to dynamically attach some function which changes state of pin in rate of us. But its true, that I could do it without without the function and Timeout interrupt and just do it all in one thread. Thanks for help.

posted by Eduard Medla 27 Sep 2017

OK, great that you got it working :-)

posted by Jan Jongboom 28 Sep 2017