From cd2d15df6a597e7dde2593f323d725c0512dcca3 Mon Sep 17 00:00:00 2001 From: Pavel Semerad Date: Sun, 13 May 2012 22:48:38 +0200 Subject: [PATCH] repair ABS to use cycle length same as before PPM frame length changes --- .depend | 2 +- ChangeLog | 1 + calc.c | 17 +++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.depend b/.depend index ae481f5..72acebe 100644 --- a/.depend +++ b/.depend @@ -14,7 +14,7 @@ eeprom.o: eeprom.c eeprom.h config.h gt3b.h stm8.h \ config.o: config.c config.h gt3b.h stm8.h task.h \ eeprom.h input.h calc.o: calc.c calc.h gt3b.h stm8.h task.h menu.h ppm.h \ - config.h eeprom.h input.h + config.h eeprom.h input.h timer.h menu_common.o: menu_common.c menu.h gt3b.h stm8.h \ task.h config.h eeprom.h ppm.h input.h lcd.h buzzer.h menu.o: menu.c menu.h gt3b.h stm8.h task.h config.h \ diff --git a/ChangeLog b/ChangeLog index a7d6309..3563e7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ *0.6.1 () + repaired ABS to use cycle length same as before PPM frame length changes *0.6.0 (28 Apr 2012) increased model memories by using FLASH also diff --git a/calc.c b/calc.c index 10316ad..a851bf9 100644 --- a/calc.c +++ b/calc.c @@ -23,6 +23,7 @@ #include "ppm.h" #include "config.h" #include "input.h" +#include "timer.h" @@ -379,16 +380,16 @@ static void calc_loop(void) { val = expo(val, (u8)(val < 0 ? cm.expo_forward : cm.expo_back)); if (cm.abs_type) { // apply selected ABS - static u8 abs_cnt; + static u8 abs_time; static _Bool abs_state; // when 1, lower brake value + // cycle time in 1ms steps: 120/80/60ms + u8 cycle_time = (u8)(cm.abs_type == 1 ? 120 : + cm.abs_type == 2 ? 80 : 60); if (val > ABS_THRESHOLD) { - // count ABS - abs_cnt++; - if (cm.abs_type == 1 && abs_cnt >= 6 - || cm.abs_type == 2 && abs_cnt >= 4 - || cm.abs_type == 3 && abs_cnt >=3) { - abs_cnt = 0; + // check time with 40ms reserve and change abs_state + if ((u8)(ppm_timer - abs_time) <= 40) { + abs_time = (u8)(ppm_timer + cycle_time); abs_state ^= 1; } // apply ABS @@ -397,7 +398,7 @@ static void calc_loop(void) { } else { // no ABS - abs_cnt = 0; + abs_time = (u8)(ppm_timer + cycle_time); abs_state = 0; } }