From c0ed21a818e22070507386a503939fc1d775f92f Mon Sep 17 00:00:00 2001 From: Ben Hitchcock Date: Sat, 29 Nov 2014 22:54:27 +0800 Subject: [PATCH] First attempt at getting CC3D PPM to work when oneshot is enabled. I don't think that this will work, as we are manipulating the timer value to trick it into overflowing. Better would be to force an overflow a different way, that would preserve the current timer value. This would then give the proper value to the CC3D PPM routine, provided it was then divided by 8. --- src/main/drivers/pwm_rx.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/drivers/pwm_rx.c b/src/main/drivers/pwm_rx.c index 2ecd4aa6..f4d06edb 100644 --- a/src/main/drivers/pwm_rx.c +++ b/src/main/drivers/pwm_rx.c @@ -24,6 +24,8 @@ #include "build_config.h" #include "common/utils.h" +#include "config/config.h" + #include "system.h" #include "nvic.h" @@ -80,6 +82,7 @@ static uint16_t captures[PWM_PORTS_OR_PPM_CAPTURE_COUNT]; static uint8_t ppmFrameCount = 0; static uint8_t lastPPMFrameCount = 0; +static uint8_t ppmCountDivisor = 1; typedef struct ppmDevice { uint8_t pulseIndex; @@ -157,6 +160,9 @@ static void ppmEdgeCallback(timerCCHandlerRec_t* cbRec, captureCompare_t capture /* Convert to 32-bit timer result */ ppmDev.currentTime += ppmDev.largeCounter; + // Divide by 8 if Oneshot125 is active and this is a CC3D board + ppmDev.currentTime = ppmDev.currentTime / ppmCountDivisor; + /* Capture computation */ ppmDev.deltaTime = ppmDev.currentTime - ppmDev.previousTime; @@ -325,6 +331,11 @@ void ppmInConfig(const timerHardware_t *timerHardwarePtr) timerConfigure(timerHardwarePtr, (uint16_t)PPM_TIMER_PERIOD, PWM_TIMER_MHZ); + if((timerHardwarePtr->tim == TIM4) && (feature(FEATURE_ONESHOT125))){ + ppmCountDivisor = 8; + } + + timerChCCHandlerInit(&self->edgeCb, ppmEdgeCallback); timerChOvrHandlerInit(&self->overflowCb, ppmOverflowCallback); timerChConfigCallbacks(timerHardwarePtr, &self->edgeCb, &self->overflowCb);