From 962f57a85ffadb7b165dff1139d12a1f310577b3 Mon Sep 17 00:00:00 2001 From: Candas1 Date: Sun, 15 Nov 2020 20:04:40 +0100 Subject: [PATCH] Improve PPM --- Inc/config.h | 2 +- Src/control.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Inc/config.h b/Inc/config.h index a287a96..6327998 100644 --- a/Inc/config.h +++ b/Inc/config.h @@ -338,7 +338,7 @@ * https://gist.github.com/peterpoetzi/1b63a4a844162196613871767189bd05 */ #define CONTROL_PPM_LEFT // use PPM-Sum as input on the LEFT cable . disable CONTROL_SERIAL_USART2! - // #define CONTROL_PPM_RIGHT // use PPM-Sum as input on the RIGHT cable. disable CONTROL_SERIAL_USART3! + //#define CONTROL_PPM_RIGHT // use PPM-Sum as input on the RIGHT cable. disable CONTROL_SERIAL_USART3! #ifdef CONTROL_PPM_RIGHT #define DEBUG_SERIAL_USART2 // left sensor cable debug #else diff --git a/Src/control.c b/Src/control.c index 8f0c541..a6c53be 100644 --- a/Src/control.c +++ b/Src/control.c @@ -34,13 +34,14 @@ void PPM_ISR_Callback(void) { if (rc_delay > 3000) { if (ppm_valid && ppm_count == PPM_NUM_CHANNELS) { ppm_timeout = 0; + timeoutCnt = 0; // added this memcpy(ppm_captured_value, ppm_captured_value_buffer, sizeof(ppm_captured_value)); } ppm_valid = true; ppm_count = 0; } else if (ppm_count < PPM_NUM_CHANNELS && IN_RANGE(rc_delay, 900, 2100)){ - timeoutCnt = 0; + //timeoutCnt = 0; ppm_captured_value_buffer[ppm_count++] = CLAMP(rc_delay, 1000, 2000) - 1000; } else { ppm_valid = false; @@ -77,9 +78,18 @@ void PPM_Init(void) { TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; HAL_TIM_Base_Init(&TimHandle); + #if defined(CONTROL_PPM_LEFT) /* EXTI interrupt init*/ HAL_NVIC_SetPriority(EXTI3_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI3_IRQn); + #endif + + #if defined(CONTROL_PPM_RIGHT) + /* EXTI interrupt init*/ + HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); + #endif + HAL_TIM_Base_Start(&TimHandle); } #endif