Digital filter and assembler code examples
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Digital filter and assembler code examples
I've posted some code here https://github.com/peterhinch/micropython-filters.git with implementations of moving average and FIR (finite impulse response) functions written in ARM assembler. These are intended for use in interrupt callbacks to handle real time integer data from the ADC's or transducers and are fast (typically 8-25uS - the readme provides further guidance).
There is also a file asm.py illustrating the technique of dealing with ARM assembler instructions which are not yet implemented in MicroPython.
For obbvious reasons this code is only of use on ARM hosts. The routines have been developed and tested on the MicroPython board.
There is also a file asm.py illustrating the technique of dealing with ARM assembler instructions which are not yet implemented in MicroPython.
For obbvious reasons this code is only of use on ARM hosts. The routines have been developed and tested on the MicroPython board.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Digital filter and assembler code examples
Thanks for putting this together! I had a quick look; I can see that you really made the effort to explain your process and show how it all works. Not just useful code, but a solid reference for anyone trying to write their own assembler. Nice work!
-Bryan
-Bryan
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Digital filter and assembler code examples
Thank you!
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Digital filter and assembler code examples
Peter,
where does this data() instruction in our inline assembler come from? I haven't seen this being mentioned anywhere in the official docs or the Wiki.
where does this data() instruction in our inline assembler come from? I haven't seen this being mentioned anywhere in the official docs or the Wiki.
Re: Digital filter and assembler code examples
It was a workaround to be able to use the unimplemented push and pop assembly instructions. But as of about two hours ago, push and pop are implemented by the uPy assembler: https://github.com/micropython/micropyt ... baa5e262c2 The data() instruction may still be useful for providing other unimplemented instructions.ul5255 wrote:Peter,
where does this data() instruction in our inline assembler come from? I haven't seen this being mentioned anywhere in the official docs or the Wiki.
-Bryan
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Digital filter and assembler code examples
Thank you As for ITE I hadn't spotted that one. Very handy - I'll experiment. It's great that PUSH and POP are now done - it would be good to see SDIV and UDIV implemented. In the meantime the data workround is handy and I edited the wiki yesterday to outline it.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Digital filter and assembler code examples
udiv, sdiv, clz and rbit are now implemented.
Let me know if there's anything else you need, or any other ideas for improving the inline assembler
Let me know if there's anything else you need, or any other ideas for improving the inline assembler
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Digital filter and assembler code examples
Eek. In its general form the IT instruction is a bit of a brain-bender Unless I'm misunderstanding the required syntax, there is a problem with the ite.ge() instruction implementation. The following code works if I emit the instruction using a data statement, but crashes if I replace the latter with the commented out line.Do you know about the ite instruction?
Code: Select all
@micropython.asm_thumb
def rats(r0):
mov(r7, 0)
mov(r1, 1)
mov(r2, 2)
mov(r3, 4)
cmp(r0, r2)
# ite.ge()
data(2, 0xbfac) # emit ite.ge()
orr(r7, r1) # Executed if r0 >= 2
orr(r7, r2) # Executed if r0 < 2
orr(r7, r3) # Always executed.
mov(r0, r7)
def testit():
for x in range(6):
print(x, hex(rats(x)))
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
ITE instruction
With the latest (15th Feb) build ite.ge() throws an argument count error when the module is loaded. I had a suspicion that Python might be supplying an unwanted argument so I created a build with the ite.ge opcode changed to itege. This seems to work as expected.
Great improvements to the assembler!
Incidentally when I did the build I got the strangest warning:
make: warning: Clock skew detected. Your build may be incomplete.
Great improvements to the assembler!
Incidentally when I did the build I got the strangest warning:
make: warning: Clock skew detected. Your build may be incomplete.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.