I wrote a function in assembly with the @asm_thumb decorator which allows me to trigger the ADC register for a single conversion, store its value in a register (lets say r0), trigger some IOs, trigger again the ADC and store this second value in r1. Then the function return the difference between r1 and r0 and store the value in the memory adress of a predefined variable.
I chose assembly since I needed to do these operations as fast as possible (and it was new to me, so also a bit for the fun).
Right now the function works well in a while loop on the CPU but therefore cannot use it for other (more interesting?) tasks.
So I thought that I could set up a state machine, with only one irq and use my assembly function as the irq_handler.
Code: Select all
@micropython.asm_thumb #My function in inline assembly
def my_assembly_fun(r0):
...do stuff with ADC and PIO register...
return r0
def irq_handler(x): #The function that will be called when the irq is triggered
my_assembly_fun()
@rp2.asm_pio() #The PIO function that only call an IRQ and wait 31 cycles
def pio_function():
wrap_target()
irq(0) [31]
wrap()
rp2.PIO(0).irq(lambda gpio:irq_handler(gpio)) #Setting the function for the handling of the IRQ
sm = rp2.StateMachine(0, pio_function, freq=100000) #The initialization of the statemachine
What would you advice to do?
For what I understood (hopefully wrong), with in the PIO assembly language I cannot "peek" or "poke" registers and therefore trigger and sample my ADC register.
Thanks for your help,
Fede