Adds an LED_pulse feature using ISR to devices/grid_maze.py#150
Adds an LED_pulse feature using ISR to devices/grid_maze.py#150mathias-sm wants to merge 1 commit intopyControl:masterfrom
devices/grid_maze.py#150Conversation
|
Update: it turns out that the race condition between the pulse timer and other I now think that the cleanest version of this would be to have a single buffer for the |
|
Hi @mathias-sm, Thanks for your work on this.
If I understand correctly you are proposing the following change to how setting the value of digital outputs works on the gridmaze hardware:
I think this is a good plan because it will reduce the overheads associated with writing bits (as it removes the need for an I2C read) and will faciliate controlling outputs in interrupt callbacks. If you have time to have a go implementing this that would be great. |
Hi everyone,
Thanks for maintaining this great ecosystem!
For an experiment we're running these days, I needed a feature to dim LEDs in a
grid_mazesetup. I'm doing this with PWM using a MicroPython timer and a callback that turns the LED on and off at the requiredduty_cycle(fraction of the time on), at the requiredfreqency. The code is heavily inspired fromcode/source/pyControl/hardware.py
Lines 420 to 450 in a54bdca
LED_onandLED_offare allocating new memory withto_bytecode/devices/grid_maze.py
Line 162 in a54bdca
Instead, I pre-allocate buffers for on and off, and write those in a tight loop: this works, is as computationally light as I could think of, but makes pulsing incompatible with turning on/off other LEDs or delivering rewards. Feel free to merge, or otherwise leave here should anyone else need this feature! Happy to take the maintainers' input of course.
This is currently being tested in an experiment, so far we have not had any trouble but I will keep upstreaming fixes if need be. Thanks to @ThomasAkam for his input; some of this code was developed together with Arya Bhomick.
Cheers,
Mathias.