Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update drv_pwm.c #153

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions src/drv_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is here from beginning, but if youre updating this part of code might as well make chan as int.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing between if and (

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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for braces for single line if () conditions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought BF wants it that way because here: https://github.com/multiwii/baseflight/blob/master/src/mw.c#L108

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left overs of original code.
coding styles doc says otherwise.
that's usually authoritative reference.
On Jul 31, 2014 5:54 PM, "Crashpilot1000" [email protected] wrote:

In src/drv_pwm.c:

  • last = now;
  • now = capture;

- diff = now - last;

I thought BF wants it that way because here:
https://github.com/multiwii/baseflight/blob/master/src/mw.c#L108


Reply to this email directly or view it on GitHub
https://github.com/multiwii/baseflight/pull/153/files#r15631816.

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
Expand Down