Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5355

General • Re: Ensuring PWM/GPIO outputs are low after critical events

$
0
0
MicroPython has a 'sys.atexit()' which allows a function to be specified which will be called when a program terminates which I believe includes Ctrl-C interruptions - https://docs.micropython.org/en/latest/library/sys.html#sys.atexit

Unfortunately that's not enabled by default in the MicroPython port for RP2040, and I'm not sure if it does what would be desired once it is.

More unfortunately, when I try to enable it it and build the firmware, it errors and fails to build, so can't even test it.

It might be possible to hack the firmware so it calls something which will clear all GPIO, peripherals and State Machines, when a Ctrl-C is detected but I am not sure what there would be for handling errant and misbehaving code, vehicle pile-ups, etc. Using the watchdog would be one approach and you could use a second Pico to hold the 'wannabe killer Pico' in reset or turn motor power off as an independent hardware watchdog. Simply gating the motor drive signals through the second Pico may be the easy option; I can't see that sub-microsecond latency through a PIO input-output loop would be that detrimental and seems easy to implement.

Beyond that some sort of physical power cut-out with the disconnect on a length of rope is perhaps the best way to halt something heading off into the distance.

Statistics: Posted by hippy — Thu Feb 29, 2024 2:45 pm



Viewing all articles
Browse latest Browse all 5355

Trending Articles