From e8b41de152414085eedfaa56380ee3095be4324d Mon Sep 17 00:00:00 2001 From: bsongis Date: Wed, 18 Jul 2012 07:34:52 +0000 Subject: [PATCH] [ersky9x] PPM-in problem --- src/board_ersky9x.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/board_ersky9x.cpp b/src/board_ersky9x.cpp index 0461f5dde..3d2be8d29 100644 --- a/src/board_ersky9x.cpp +++ b/src/board_ersky9x.cpp @@ -372,36 +372,35 @@ void start_timer4() // (The timer is free-running and is thus not reset to zero at each capture interval.) // Timer 4 generates the 2MHz clock to clock Timer 3 -uint16_t Temp_captures[8] ; - extern "C" void TC3_IRQHandler() //capture ppm in at 2MHz { uint16_t capture ; static uint16_t lastCapt ; - uint16_t val ; capture = TC1->TC_CHANNEL[0].TC_RA ; (void) TC1->TC_CHANNEL[0].TC_SR ; // Acknowledgethe interrupt - val = (capture - lastCapt) / 2 ; - lastCapt = capture; + uint16_t val = (capture - lastCapt) / 2; - // We prcoess g_ppmInsright here to make servo movement as smooth as possible + // G: We process g_ppmIns immediately here, to make servo movement as smooth as possible // while under trainee control - if (ppmInState && ppmInState<=8) { - if(val>800 && val<2200) { - Temp_captures[ppmInState - 1] = capture ; - g_ppmIns[ppmInState++ - 1] = (int16_t)(val - PPM_CENTER)*(g_eeGeneral.PPM_Multiplier+10)/10; //+-500 != 512, but close enough. - } - else { - ppmInState = 0; // not triggered - } - } - else { - if (val>4000 && val < 16000) { - ppmInState = 1; // triggered + if (val>4000 && val < 16000) // G: Prioritize reset pulse. (Needed when less than 8 incoming pulses) + ppmInState = 1; // triggered + else + { + if (ppmInState && ppmInState<=8) + { + if (val>800 && val<2200) // if valid pulse-width range + { + g_ppmIns[ppmInState++ - 1] = + (int16_t)(val - 1500)*(g_eeGeneral.PPM_Multiplier+10)/10; //+-500 != 512, but close enough. + } + else + ppmInState = 0; // not triggered } } + + lastCapt = capture; } void start_ppm_capture()