Anything to convert spin to PASM?
T Chap
Posts: 4,223
I looked at the resource sticky but didn’t see it. I want to find an SPI object and modify it to do a specific role and then convert it to PASM. The object needs to be sent a pointer to a long that will be read by others. The PASM object also needs to have a few spin commands from a main program to do some things as needed.
PASM Loop:
Read an SPI device
Update a variable with the value from a device
If requested from SPIN main program, send a value to the device via SPI then continue the Read loop.
Is there something that will let me write this in SPIN and convert it?
Edit After some digging it looks like fastspin command line exe converts spin to pasm. I downloaded the files from github, dragged a spin file on top of fastspin.exe and it output a text file of the pasm conversion. Now to write the spin program I need and test it.
PASM Loop:
Read an SPI device
Update a variable with the value from a device
If requested from SPIN main program, send a value to the device via SPI then continue the Read loop.
Is there something that will let me write this in SPIN and convert it?
Edit After some digging it looks like fastspin command line exe converts spin to pasm. I downloaded the files from github, dragged a spin file on top of fastspin.exe and it output a text file of the pasm conversion. Now to write the spin program I need and test it.
Comments
The demo should have a main SPIN program that first launches the LS7366 PASM code that will only read the LS7366 quad encoder module via SPI. This requires the first step of toggling SSN pin from high to low, then SPI command to get the encoder position, then the SPI reading the position , then SSN pin goes back high.
I know what I have will not work yet, I don't even know if the converted PASM code works as there is no way to test it until I connect its output to the LCD.
I need some help with the PASM to get it at least to a starting point. The main program works in SPIN, and it does CNTRREAD in SPIN and returns the encoder position and it is displayed on the LCD. On the PASM version what I want to do is send the PASM core a variable to update with the SPI read position, the value to update is EncoderTest. At present the PASM code does not recognize the EncoderTest I sent it as a pointer. I need help to 1. tell the PASM code to return the value via EncoderTest and 1. keep looping.
Any suggestions appreciated. I already have too much time in trying to figure this out, I'd be happy to pay a fee for a few hours if someone want to help write an object based on some existing SPIN code.
Here is the main program, the SPIN version "object", and the fastspin conversion lsobject.cog.spin
In added a substitution in the object to only return "5" just to see if the object worked and it did return 5. So it looks like the SPI is now working.
using BST
EDIT Actually nothing is happening on the lines. SSN is high and it should be LOW for all data to be moving. But __busy is -1. Remove the call for setup and busy is 0.
Remove the setup call from main and loop Cntrread from main and the clock runs and SSN runs but no miso mosi activity.
Similarly for the waitcnt inside your Setup loop in LSobject.spin.
I'm also curious about the code that looks like: that occurs in lots of places. This is toggling the Cpin very quickly indeed when compiled with fastspin. Possibly you want delays after both of the !outa[Cpin] and not just the first one? So something like:
You might even want to make this a subroutine so that you can easily tweak the delays.
Regards,
Eric
I added the extra waitcnt lines but still no activity on MOSI or MISO.
I assumed based on what you suggested earlier that I did not need to call Cntrread, that it would automatically run because that's how the SPIN was running.
The problem with CNTRClear after Setup is that once you call Setup the new COG will be spending its time in a polling loop doing CNTRRead and updating long[EncoderPtr]. It will literally have no ability to respond to any other commands (such as a request to do CNTRClear).
You could extend Setup to have a command pointer as well, something like:
Alternatively, of course, you could never call Setup() at all and just have the main Spin cog poll by calling CNTRRead itself. I'm not sure what your goal is in having the sub (pasm) COG continually updating long[EncoderPtr]. Is it that you want the main COG to be doing some processing in parallel with the CNTRRead? If so you can split the CNTRRead up into two parts: StartCNTRRead (which actually does the work and sets a variable with the result, but does not return a value) and GetCNTRRead(which just returns the value from the variable). See the "Synchronous and Asynchronous Operation" section in the SpinPasmIntegration.md document for an example.
Edit Nope it hangs up cogstop as well. I think the PASM code will have to be modified to watch a pointer to a command value as I don't think the SPIN calls are going to work after the loop starts.
Maybe that’s what you were thinking on the main side but I was trying to re call setup.
MAIN
Object
EDIT I combines some repeated items into a method and shaved 25 longs now 10 longs over.
I'm curious: what's your overall goal with converting this code to PASM? Is it to speed it up? You may be able to just compile your whole project with fastspin (in LMM mode, so it doesn't have to fit in a COG).