How can I Make this code FASTER
krazyideas
Posts: 119
Beginer Me again.
Well after seeing the abiltiy of assembly, namely so mind boggaling freakin fast. I have a couple questions
First Question is Does anyone know where I can find some tutorals of how to program in assembly?? hopefully a tutoral that would teach me enough so that I could write the below code in assembly.
Second Question is How could I speed this code up. It works great but being the beginner that I am, I betting there is a better way, even remaining in Spin. Here it is.
The first conditon is easy and simple because no matter how much a move it around with my control program it will never cross the reset of the count.
The second condition is like 5 times more complacated because as I change it's values I need it to stay in time.
EXAMPLE. Say Final12 + OFFadj1 added to 2900. Well the count only goes to 2880 before it is reset. So I have to take the difference of 2900 - 2880 and make that the trigger point. The trigger point should be 20 not 2900.
Third Question is how fast is the above Spin program I wrote?
I want the motor to turn at 7,000 RPM, the encoder has 2880 pluses per rotation. So would the code be capable of doing that accuratly??
Foruth Question I run the above code in 1 cog to 1 coil ratio. Would the code be able to handle say 2, 3, 4, 5 ,6 ect... coils???
Thanks is advance.
Well after seeing the abiltiy of assembly, namely so mind boggaling freakin fast. I have a couple questions
First Question is Does anyone know where I can find some tutorals of how to program in assembly?? hopefully a tutoral that would teach me enough so that I could write the below code in assembly.
Second Question is How could I speed this code up. It works great but being the beginner that I am, I betting there is a better way, even remaining in Spin. Here it is.
PUB Coil1 | extra1 dira [7]~~ extra1 := 0 ONadj1 := 0 Offadj1 := 0 Final11 := 24 'Final1 represents the 2nd pulses ON DEGREE Final12 := 264 'Final2 represents the 2nd pulses OFF DEGREE Repeat if count => 1464 + ONadj1 and count =< 1680 + Offadj1 outa[7]~ {The numbers repesent the starting point then I modifi ONadj1 and Offadj1 to change ' the triggering points} elseif Final12 + OFFadj1 => Final11 + ONadj1 and Final11 + ONadj1 =< 2880 if count => Final11 + ONadj1 and count =< Final12 + OFFadj1 outa[7]~ else outa[7]~~ elseif Final11 + ONadj1 =< 2880 if count => Final11 + ONadj1 outa[7]~ elseif count =< Final12 + OFFadj1 outa[7]~ else outa[7]~~ elseif Final11 + ONadj1 > 2880 extra1 := (Final11 + ONadj1) - 2880 if count => extra1 and count =< Final12 + OFFadj1 outa[7]~ else outa[7]~~ else outa[7]~~
The first conditon is easy and simple because no matter how much a move it around with my control program it will never cross the reset of the count.
The second condition is like 5 times more complacated because as I change it's values I need it to stay in time.
EXAMPLE. Say Final12 + OFFadj1 added to 2900. Well the count only goes to 2880 before it is reset. So I have to take the difference of 2900 - 2880 and make that the trigger point. The trigger point should be 20 not 2900.
Third Question is how fast is the above Spin program I wrote?
I want the motor to turn at 7,000 RPM, the encoder has 2880 pluses per rotation. So would the code be capable of doing that accuratly??
Foruth Question I run the above code in 1 cog to 1 coil ratio. Would the code be able to handle say 2, 3, 4, 5 ,6 ect... coils???
Thanks is advance.
Comments
There are several links to tutorials on assembly language in the "sticky" threads at the top of the forum thread list. deSilva's Machine Language Tutorial is good, but look at the others.
To really estimate the speed of the Spin program, you'd have to compile it with something like BST which can give you a listing of the interpretive code produced. Unfortunately, there's not a list of each of the interpretive operations and its timing. It's more complicated than that ... you have to look at addressing modes, etc.
You're talking about roughly 250K pulses per second or 4us per pulse. Very simple Spin might do that ... not what you've got. You'll need to use assembly language or do something completely different using the cog counters. I couldn't tell you what because you've not supplied enough information about what you're trying to do, but the cog counters are fast.
Assembly is a lot faster than Spin. You should be able to handle multiple coils in assembly.
One of the great things about the Propeller is that it has the tools to time itself. Just this morning I wanted to find out how long it took to read 512 bytes (128) longs from a microSD card and then transfer the low byte of each to a DMX driver (for a stand-alone DMX cue broadcaster). Here's the general trick in Spin:
The value in t is the number of system ticks your code consumed. I tend to send the result to a terminal. Note, too, that when you know the system frequency you can easily convert to the raw counts to a useful value.
Why the -544 value? Is that explained anywhere?
And why "t := -cnt" instead of just 'cnt'?
JonnyMac's Spin Zone articles really helped when I was learning to program in PASM.
I've read enough of Jon's stuff to know this.
The "-544" compenstates for the overhead of setting up the timer.
By using "t := -cnt" and then adding the later value of cnt, you can have a timer with just one variable.
That's another big +1.
I can dig and experiment and eventually find something that will work.
But working examples are priceless.
I'll let you know when I find some more questions
Take care
My cousin was telling me about C++ and how awesome it is, and how you write in a high level language like Spin. But when it is complied it is complied into assembly and therefore no slower then assembly.
So I was wondering if that was true (or if there are some BUT's to be considered) and also if the Prop can understand C++ ??
The limitation is that you cannot use all of the C++ features. Dynamic objects are a no-no for example. (Dynamic objects are where you create new objects during run time and they are not statically allocated).
As Kye points out Propeller GCC C++ can be used with Propeller when used within reason.
Using std:: namespace for things like std::cout requires a big solution like C3 or others 1MB flash + SRAM.
Kye, Ted (denominator) added support for small dynamic objects in his tiny library for LMM mode.
I haven't tested this aspect yet, but his work is quite good, so I expect it should work.
See this wiki for more info: http://code.google.com/p/propgcc/wiki/PropGccTightMemory
I haven't tried any prop GCC stuff yet. I've been busy with CMUcam4. SparkFun is going to be selling them soon. I have to prepare for a big release.
Me too, but I've gotten over it mostly. My wife of 20+ years is Thai, and we influence each other's language habits.
No pressure Best of luck with your release!
What I am wanting to do is covert a Spin program I have into assembly but I am haveing a heck of time doing it and am looking for another way to get the speed of assembly, because my brain is rejecting the learning of assembly.
Thanks
What I am wanting to do is covert a Spin program I have into assembly but I am haveing a heck of time doing it and am looking for another way to get the speed of assembly, because my brain is rejecting the learning of assembly.
Thanks
I am not sure, but I would expect that both Catalina and GCC can output a listing. If so, then why not write your code in C and look at the output. Then you can use this as the basis for your PASM code. Of course, if you can get away with the size and slower overheads of C, then just use it.
Propeller GCC supports different modes COG, LMM, and the XMM variants.
COG C programs run in a COG, not LMM.
Therefore COG C programs will run as fast as PASM in a COG.
That is not to say that it will be as good as hand-crafted PASM programs.
For one thing, COG C programs use some HUB RAM as stack space if necessary.
We have some drivers written in COG C and some example programs.
It is possible write a driver with COG C that can be used with Spin.