From 544bb174c9eda27ba895722965ab59b603d0b772 Mon Sep 17 00:00:00 2001 From: Crashpilot1000 Date: Thu, 31 Jul 2014 10:18:53 +0200 Subject: [PATCH 1/4] Update drv_pwm.c Detection & fix for the "8 channels in 18ms Frsky problem" see http://diydrones.com/profiles/blogs/why-frsky-cppm-signal-is-so-disappointing . Note: failsafeCheck not altered! --- src/drv_pwm.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/drv_pwm.c b/src/drv_pwm.c index 2410c179..c4fe84b8 100755 --- a/src/drv_pwm.c +++ b/src/drv_pwm.c @@ -281,19 +281,42 @@ static void failsafeCheck(uint8_t channel, uint16_t pulse) } } +// Contains detection & fix for the "8 channels in 18ms Frsky problem" see: +// http://diydrones.com/profiles/blogs/why-frsky-cppm-signal-is-so-disappointing +// http://forums.openpilot.org/topic/16146-cc3d-with-frsky-8-channels-in-cppm-mode/ +// Tested on: Frsky D8R-II and Frsky D4FR static void ppmCallback(uint8_t port, uint16_t capture) { (void)port; - uint16_t diff; - static uint16_t now; + uint16_t newval = capture; static uint16_t last = 0; + static uint16_t frametime = 0; static uint8_t chan = 0; + static uint8_t frsky_errcnt = 0; + static bool frsky_18patch = false; + uint16_t diff = newval - last; + bool sync = diff > 2700; // rcgroups.com/forums/showpost.php?p=21996147&postcount=3960 "So, if you use 2.5ms or higher as being the reset for the PPM stream start, you will be fine. I use 2.7ms just to be safe." + last = newval; + + if(frsky_18patch) { + sync |= chan == 8; // FrSky 18ms Fix, force sync after 8 channels + } else { + frametime += diff; + } - last = now; - now = capture; - diff = now - last; - - if (diff > 2700) { // Per http://www.rcgroups.com/forums/showpost.php?p=21996147&postcount=3960 "So, if you use 2.5ms or higher as being the reset for the PPM stream start, you will be fine. I use 2.7ms just to be safe." + if (sync) { + if(!frsky_18patch) { + if(frametime < 18300 && chan == 8) { + frsky_errcnt++; + } else { + frsky_errcnt = 0; + } + if(frsky_errcnt == 30) { + frsky_18patch = true; // Condition must be true 30 times in a row before we enable the FrSky fix + } else { + frametime = 0; + } + } chan = 0; } else { if (diff > PULSE_MIN && diff < PULSE_MAX && chan < MAX_INPUTS) { // 750 to 2250 ms is our 'valid' channel range From 91761fcb76a4dcd4b042f28a6571c3f116d01113 Mon Sep 17 00:00:00 2001 From: Crashpilot1000 Date: Thu, 31 Jul 2014 22:41:39 +0200 Subject: [PATCH 2/4] Update drv_pwm.c Reformated the code, tested it again - works. The failsafeCheck is not changed and probably needs further attention from the BF folks. --- src/drv_pwm.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/drv_pwm.c b/src/drv_pwm.c index c4fe84b8..f224783e 100755 --- a/src/drv_pwm.c +++ b/src/drv_pwm.c @@ -291,31 +291,29 @@ static void ppmCallback(uint8_t port, uint16_t capture) uint16_t newval = capture; static uint16_t last = 0; static uint16_t frametime = 0; - static uint8_t chan = 0; + static int8_t chan = 0; static uint8_t frsky_errcnt = 0; static bool frsky_18patch = false; uint16_t diff = newval - last; bool sync = diff > 2700; // rcgroups.com/forums/showpost.php?p=21996147&postcount=3960 "So, if you use 2.5ms or higher as being the reset for the PPM stream start, you will be fine. I use 2.7ms just to be safe." last = newval; - if(frsky_18patch) { + if (frsky_18patch) sync |= chan == 8; // FrSky 18ms Fix, force sync after 8 channels - } else { + else frametime += diff; - } if (sync) { - if(!frsky_18patch) { - if(frametime < 18300 && chan == 8) { + if (!frsky_18patch) { + if (frametime < 18300 && chan == 8) frsky_errcnt++; - } else { + else frsky_errcnt = 0; - } - if(frsky_errcnt == 30) { + + if (frsky_errcnt == 30) frsky_18patch = true; // Condition must be true 30 times in a row before we enable the FrSky fix - } else { + else frametime = 0; - } } chan = 0; } else { From 5a9468c8b3c2eafa07b7fe7affc9ceabf56017bb Mon Sep 17 00:00:00 2001 From: Crashpilot1000 Date: Fri, 1 Aug 2014 05:13:48 +0200 Subject: [PATCH 3/4] Update drv_pwm.c Shorter and working. --- src/drv_pwm.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/drv_pwm.c b/src/drv_pwm.c index f224783e..761a6930 100755 --- a/src/drv_pwm.c +++ b/src/drv_pwm.c @@ -292,28 +292,23 @@ static void ppmCallback(uint8_t port, uint16_t capture) static uint16_t last = 0; static uint16_t frametime = 0; static int8_t chan = 0; - static uint8_t frsky_errcnt = 0; - static bool frsky_18patch = false; + static uint8_t frsky_problemcnt = 0; uint16_t diff = newval - last; bool sync = diff > 2700; // rcgroups.com/forums/showpost.php?p=21996147&postcount=3960 "So, if you use 2.5ms or higher as being the reset for the PPM stream start, you will be fine. I use 2.7ms just to be safe." last = newval; - if (frsky_18patch) + if (frsky_problemcnt == 30) sync |= chan == 8; // FrSky 18ms Fix, force sync after 8 channels else frametime += diff; if (sync) { - if (!frsky_18patch) { + if (frsky_problemcnt != 30) { if (frametime < 18300 && chan == 8) - frsky_errcnt++; + frsky_problemcnt++; else - frsky_errcnt = 0; - - if (frsky_errcnt == 30) - frsky_18patch = true; // Condition must be true 30 times in a row before we enable the FrSky fix - else - frametime = 0; + frsky_problemcnt = 0; + frametime = 0; } chan = 0; } else { From 7654af3bf3e5c4ba6c48431a185e090fc6a2fb21 Mon Sep 17 00:00:00 2001 From: Crashpilot1000 Date: Sat, 2 Aug 2014 15:03:12 +0200 Subject: [PATCH 4/4] Update drv_pwm.c Besides the Frsky 18ms fix it also verifies the channelnumbers, that will most probably also fix some hiccups some ppl see. I can not verify this because I don't see those hiccups with my gear. BF failsafeCheck logic unchanged may need attention. --- src/drv_pwm.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/drv_pwm.c b/src/drv_pwm.c index 761a6930..92287302 100755 --- a/src/drv_pwm.c +++ b/src/drv_pwm.c @@ -292,6 +292,7 @@ static void ppmCallback(uint8_t port, uint16_t capture) static uint16_t last = 0; static uint16_t frametime = 0; static int8_t chan = 0; + static int8_t chan_order = 0; static uint8_t frsky_problemcnt = 0; uint16_t diff = newval - last; bool sync = diff > 2700; // rcgroups.com/forums/showpost.php?p=21996147&postcount=3960 "So, if you use 2.5ms or higher as being the reset for the PPM stream start, you will be fine. I use 2.7ms just to be safe." @@ -311,10 +312,14 @@ static void ppmCallback(uint8_t port, uint16_t capture) frametime = 0; } chan = 0; + chan_order = 0; } else { - if (diff > PULSE_MIN && diff < PULSE_MAX && chan < MAX_INPUTS) { // 750 to 2250 ms is our 'valid' channel range - captures[chan] = diff; - failsafeCheck(chan, diff); + if (diff > PULSE_MIN && diff < PULSE_MAX && chan == chan_order) { // Only capture if channel order is correct and Range: 750 to 2250 ms + if (chan < MAX_INPUTS) { // Needed and incoming channelnumbers can be different. + captures[chan] = diff; + failsafeCheck(chan, diff); + } + chan_order++; } chan++; }