So I got the Pulser class working fine, but it pulses too slow. So I made an in-line assembly function to pulse a pin just once for 2.5us
and I want to call this function in a timer callback, so I did the following:
Code: Select all
@micropython.asm_thumb
def flash_int():
movwt(r1, stm.GPIOC)
# get the bit mask for PAC6
movw(r2, 1 << 6)
# Turn on
strh(r2, [r1, stm.GPIO_BSRRL])
# delay for a bit
movwt(r4, 50) #50 = 2.5us
label(delay_on)
sub(r4, r4, 1)
cmp(r4, 0)
bgt(delay_on)
#turn off
strh(r2, [r1, stm.GPIO_BSRRH])
tim4 = Timer(4, freq=200)
tim4.callback(flash_int)
This does not work at all, it should produce a 2.5us pulse every 200hz.
The code in an assembly loop works though, it produces a 200khz square wave as expected:
Code: Select all
def flash_loop(r0):
# get the GPIOA address in r1
movwt(r1, stm.GPIOC)
# get the bit mask for PC6
movw(r2, 1 << 6)
b(loop_entry)
label(loop1)
# turn LED on
strh(r2, [r1, stm.GPIO_BSRRL])
# delay for a bit
movwt(r4, 50)
label(delay_on)
sub(r4, r4, 1)
cmp(r4, 0)
bgt(delay_on)
# turn LED off
strh(r2, [r1, stm.GPIO_BSRRH])
# delay for a bit
movwt(r4, 50)
label(delay_off)
sub(r4, r4, 1)
cmp(r4, 0)
bgt(delay_off)
# loop r0 times
sub(r0, r0, 1)
label(loop_entry)
cmp(r0, 0)
bgt(loop1)
So what is wrong with the interrupt callback, can I not even do a simple assembly callback this way?
There are no errors produced by python to tell me I have done something wrong. How do I debug something like this?