Closed Hurricos closed 9 months ago
On the Nano, D7 does not support interrupt generation on level change; this leaves only polling strategies.
ChatGPT has screwed me here. D7 supports interrupt generation without issue, c.f. https://dronebotworkshop.com/interrupts/ -- this pin is on port D.
Implemented by calling a new ISR from a pin-change interrupt in PR #3; closing.
Context:
Measuring vehicle speed is generally useful for implementing vehicle-speed-dependent behavior.
Assumptions:
The VSS signal is, as far as the Nano's digital input is concerned, a square wave.
In
muddersMIMA_firmware/cpu_map.h
, we have PIN_VSS as pin 7 (D7).The VSS triggers 4550 times per mile.
There are multiple strategies to produce a frequency value from a square wave input.
1) Pin change interrupts: LiControl's parsing strategy for NEP, done by linking the PIN_NEP (D8) to an ISR
2) Polling pin value
On the Nano, D7 does not support interrupt generation on level change; this leaves only polling strategies.
We cannot create a hardware timer to call a polling function, because we currently use all three timers - timer 0 for millis(), timer 1 for PWM on pin 9 (
PIN_CMDPWR_MCM
), and timer 2 for PWM on pin 3 (PIN_MAMODE1_MCM
).Outside of a separate timer, we could poll VSS once per event loop, but that defaults to 10ms -- workable (if inaccurate) for low speeds, but at higher speeds, this polling rate is too slow. We can speed up the polling rate, but we still have the issue of accuracy. We could improve this by keeping a rolling-average of detected pulse widths using a ring-buffer, but this gives us some lag in speed measurement.
Personally, I'm tempted to replace the busy-wait part of the control loop with a VSS monitoring segment.