doppelhub / MuddersMIMA

Mudders Take on Manual IMA Control in the G1 Honda Insight
GNU General Public License v3.0
2 stars 4 forks source link

feat: speed: Measure vehicle speed using pin-change IRQ on VSS #3

Open Hurricos opened 9 months ago

Hurricos commented 9 months ago

feat: speed: Measure vehicle speed using pin-change IRQ on VSS

This commit implements vehicle speed measurement using a pin-change interrupt on the vehicle speed sensor (VSS) line connected to pin D7

The VSS emits ~4250 pulses per mile[^1] under normal conditions. As with NEP, attach a pin-change interrupt; if when the interrupt activates, the pin is high, recalculate the vehicle speed by checking the time since the last revolution.

Also, reflect the new measurement details in debugUSB_printOEMsignals (the OEM signal echoing mode).

Notes:

[^1]: https://www.insightcentral.net/threads/vss-vehicle-speed-sensor-output.13597/post-191883 describes it initially as 4550 pulses, but some experimentation and comparison to a stock speedo led to the 4250 number now used.

Signed-off-by: Martin Kennedy hurricos@gmail.com

Addenda

Note that this PR sits atop the fix-rpm PR; we'll rebase when that (as a bug-level issue) gets merged.

doppelhub commented 9 months ago

A note in data I collected previously says "VSS is ~4000 pulses/mile (89 Hz@80mph)". Does that agree with your observations?

Hurricos commented 9 months ago

A note in data I collected previously says "VSS is ~4000 pulses/mile (89 Hz@80mph)". Does that agree with your observations?

I played around, and the number that got closest was 4250.

Hurricos commented 9 months ago

The force-push from 42c3cb7 to 61b4032 adjusts the VSS divisor to 4250 per our conversation.

Hurricos commented 3 months ago

Commit 8d8cacb831535a1b62334b0d903e94a04742f212 is a force-push rebasing vehicle-speed onto current main.

Hurricos commented 3 months ago

Please define magic number (4250) and then reduce instructions in ISR. Existing: latestVehicleMPH = ONE_HOUR_IN_MICROSECONDS / periodBetweenTicks_us / 4250;

proposed: latestVehicleMPH = (ONE_HOUR_IN_MICROSECONDS / PULSES_PER_MILE ) / periodBetweenTicks_us;

Done in commit ca3ae67c0649a2d801044a7f7878a54e5af6b55d.