Open guilhermebene opened 2 years ago
There are some Python solutions here.
Thank you @peterhinch, you did an interesting implementation there, but I was hoping to achieve even better performance by working with C++. Do you think it would be possible to improve performance compared to your last implementations from #6894 ?
Hi, take a look at this PR #8016 it adds a user C module with a pio program, the same thing that you're trying to do, please ignore all the irreverent parts, lib etc..it's very likely that you're missing something because I tested this module and it can be imported just fine. Note USER_C_MODULES
is set in an mpconfigboard.cmake file not on the command line, but it works just the same if set on the command line.
@guilhermebene C will always beat Python, even with the Viper emitter.
I managed to solve this problem in the meantime, but actually got a new one. This encoder.cpp
I am trying to use has an init()
function that calls an irq_set_exclusive_handler()
(defined in pico-sdk) to set an interruption callback, but it seems it ends up blocking and freezes MicroPython. @iabdalkader I see that you are also using PIOs in your PR, do you see a specific reason for that? The original function is here.
I'm not sure, maybe the IRQ is needed by micropython, or there's already an exclusive handler, if it's used by pico libs or micropython try adding a shared handler, if it's not used your handler might be doing something invalid like blocking.
I tried a shared handler, but it did not work though.
See rp2_pio.c
1) There's already an exclusive handler installed for pio0
and pio1
, I think you should remove them first because irq_set_exclusive_handler()
may assert an error if you don't
2) More importantly, you should handle/ack/clear the irq in your irq handler, see how that is done in rp2_pio.c
in pio_irq0()
I am trying to compile micropython for my Raspberry Pico with an "user defined module" based on pimoroni's implementation of an Encoder class that uses the Pico's PIOs to interface with motor encoders.
I have followed the tutorials explaining how to compile an user defined module for the Pico and everything seems to work just fine, I get the expected messages while compiling with
make USER_C_MODULES=../../../modules/micropython.cmake all
:My files to interface the Encoder class and MicroPython are (I am omitting the cpp to avoid flooding this issue even further):
However, I cannot import my module by just using
import Encoder
. I suspect my makefiles and cmakes are ok because I succeed to compile and link but I am not so sure about it.