Pi Pico push seems to truncate value at 5 bits

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
sgall17
Posts: 8
Joined: Sun Jan 31, 2021 9:55 pm

Pi Pico push seems to truncate value at 5 bits

Post by sgall17 » Thu Aug 19, 2021 8:31 am

The following clip is very basic but as far as I can see is giving the wrong result. Where am I going wrong?

I wanted to implement a tachometer by decrementing X until a pin goes HIGH. I thought I could get the X value out by just moving X into ISR then pushing it. As below:.....

Frequency in statemachine doesnt matter and other values I have left at defaults which I think should be OK.

I have used sm.exec so I can try lots of different values.

Code: Select all


import rp2

code]@rp2.asm_pio()
def prog():
   # set(x,63)
    mov(isr,x)
    push()


sm = rp2.StateMachine(0, prog, freq=4000)
sm.active(1)

for a in range(50):
    sm.exec("set(x,%s)" % a)
    print (sm.get())
    
sm.active(0)
The result is as below:

0
1
2
...

29
30
31
0
1
...
10
11
12

It seems that only the 5 least significant digits are being returned?
What I have done wrong?

GerryKeely
Posts: 5
Joined: Wed Feb 17, 2021 10:12 pm

Re: Pi Pico push seems to truncate value at 5 bits

Post by GerryKeely » Thu Aug 19, 2021 11:54 am

Using set x you are limited to a 5 bit no. ie max value 31.
See the RP2040 data sheet section 3.4.10
To load a full 32 bit no. you have to load x(or y) using the ISR or OSR.
eg
mov(x,osr)
label("loop1")
jmp(x_dec,"loop1")

put(value) can be used to load the osr with a full 32 bit no.

regards
Gerry

sgall17
Posts: 8
Joined: Sun Jan 31, 2021 9:55 pm

Re: Pi Pico push seems to truncate value at 5 bits

Post by sgall17 » Fri Aug 20, 2021 8:44 am

Thanks very much - I can see that now. I just assumed loading a register with an immediate value was like normal assembler.

Post Reply