From 5931a5dbbcdf629607a1e4ede2b7472656062419 Mon Sep 17 00:00:00 2001 From: Fisch Date: Sun, 28 Aug 2022 15:42:10 +0200 Subject: [PATCH] add throttle adc filter --- controller_teensy/src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/controller_teensy/src/main.cpp b/controller_teensy/src/main.cpp index 40458f6..dcf07d3 100644 --- a/controller_teensy/src/main.cpp +++ b/controller_teensy/src/main.cpp @@ -52,6 +52,7 @@ int16_t brake_pos=0; unsigned long last_adcread=0; #define ADCREADPERIOD 10 uint16_t throttle_raw=0; +#define THROTTLE_ADC_FILTER 0.1 //higher value = faster response uint16_t brake_raw=0; #define ADC_OUTOFRANGE_TIME 100 unsigned long throttle_ok_time=0; @@ -446,7 +447,10 @@ void writeLogComment(HardwareSerial &SerialRef, unsigned long time, String msg) void readADC() { - throttle_raw = analogRead(PIN_THROTTLE); + + uint16_t new_throttle_raw = analogRead(PIN_THROTTLE); + throttle_raw = new_throttle_raw*THROTTLE_ADC_FILTER + throttle_raw*(1-THROTTLE_ADC_FILTER); //apply filter + //maps throttle curve to be linear throttle_pos=max(0,min(1000,linearizeThrottle(throttle_raw))); //map and constrain brake_raw = analogRead(PIN_BRAKE);