ASM SUB help needed
T Chap
Posts: 4,223
Could use some help understanding this. In the code below, if the commented out MOV is in, nothing happens. If it is commented out, the loop runs the motor at a fixed speed set by accel. I want the accel to decrease by aRate each time around to speed up the loop. I have tried lots of combinations, using tmp1, using accel, Caccel, Carate, and other ways to move the values over so it can be updated and used the next pass. I set the initial values 5500, 100 shown below.
Thanks for any tips.
Post Edited (TChapman) : 8/16/2009 9:11:05 PM GMT
Thanks for any tips.
repeat2 RDLONG PHSA, pwidth 'set PHSA := width for pulse size MOV ctmp1, accel 'set ctmp1 to accel ADD ctmp1, CNT 'add cnt to accel value WAITCNT ctmp1, #0 'waitcnt for ctmp1 waitcnt(accel + CNT) MOV ctmp1, accel 'set ctm1 to accel from previous accel val SUB ctmp1, arate 'subtract arate from accel to shorten waitcnt next time 'MOV accel, ctmp1 'copy result back to accel <<<<<<<<<<<<<<< won't run with this in JMP #repeat2 'loop Caccel LONG 5500 'accel Carate LONG 100 accel RES 1 arate RES 1
Post Edited (TChapman) : 8/16/2009 9:11:05 PM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
But this is the short version that cuts to the chase about the sub and mov problem:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The motor runs at a fixed speed based on accel + CNT in the waitcnt. Any combintation I have tried to reduce accel on each iteration does nothing. Either the speed is still fixed, or in the code initially posted on the thread, the motor doesn't move at all. I simply want to subtract aRate from accel on each pass, thereby speeding up the waitcnt and motor speed as in acceleration mode until it hits a fixed number. In SPIN, the result of accel - arate ended up as 0, but even at that speed, the motors were still too slow. So I am sorting out the ASM version and studying the conversion. In ASM I will have to put a limit on how low the value can go (accel - arate) so that it doesn't go too fast. The ASM is already extremely fast compared to the SPIN, so a limiter will be required, similar to SPIN limit min #> . Using an externally loaded(USB to Serial) variable to set the speed limit remotely will be the goal. But first I need to solve the basic loop with accel.
Post Edited (TChapman) : 8/16/2009 9:41:50 PM GMT
> This new experience with ASM is an eye opener to the radical difference in speeds and how you have to think things through differently to deal with those speeds.
Yeah, the first time I saw the number of clock cycles in a second, my eyes crossed as I tried to imagine it.
And then, since most pasm instructions take only 4 clock cycles, how many of them can you pack into one second? WOW!
Yes, the prop's not the fastest micro on the planet, but with 7 other cogs, it's certainly acceptable, eh?
cheers
- H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
(Your OP caught my attention because I'm learning pasm too and am looking at doing a similar control mechanism).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Phil
This makes me want to put together an app that translates SPIN instructions to ASM.
Input #> 400 on the SPIN side and output mins value, value2 on the other. Copy and paste to your code. I see lots of little chunks that could be translated rather easily.
-Phil
How many hours spent trying to get speed out of Spin, could have already learned the 6 to 8 basic ASM instructions and been up and running.
It appears that if you want to use an actual number for the value2 of each instruction, you havr to keep the number under 8 bits, else refer to a register/long.
The source field can have 9 bits for immediate addressing (indicated by #).