Spin & Win with Spin2 and Inline Assembly
JonnyMac
Posts: 9,104
There is no denying that the P2 is significantly faster than its predecessor, the P1, even running the same code at the same clock speed. Of the most exciting features of Spin2 -- in my opinion -- is the ability to add snippets of inline code. Though the requirement for inline assembly is neither frequent or usual, it can be very useful at achieving one's goals while conserving cogs (important resources). There is no longer a need to consume a cog to run a few lines of assembly code.
For example: You may want to design a convention badge that has a few WS2812b LEDs to use as indicators. If you don't need the features of a fully-fledged pixel driver, a simple inline routine can be used to update the LEDs -- this keeps a cog free for other, more important processes.
Please use this thread to share your Spin2/Inline Assembly success stories. I am well aware that some programmers think that inline assembly should be avoided. That's okay, this is a big forum and you can express your thoughts elsewhere. My intent is to use this thread to create a cookbook of useful inline assembly routines.
Suggestions:
-- keep your code neatly formatted
-- comment your code (more is better)
-- test before posting, and attach test code if possible
For example: You may want to design a convention badge that has a few WS2812b LEDs to use as indicators. If you don't need the features of a fully-fledged pixel driver, a simple inline routine can be used to update the LEDs -- this keeps a cog free for other, more important processes.
Please use this thread to share your Spin2/Inline Assembly success stories. I am well aware that some programmers think that inline assembly should be avoided. That's okay, this is a big forum and you can express your thoughts elsewhere. My intent is to use this thread to create a cookbook of useful inline assembly routines.
Suggestions:
-- keep your code neatly formatted
-- comment your code (more is better)
-- test before posting, and attach test code if possible
Comments
The test code creates a pulse generator in another cog. The program does not use a smart pin mode, which allows one cog to write to the pin while another reads from it.