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);