Assembly Stepper help needed
T Chap
Posts: 4,223
I could sure use some help on this stepper loop. The program takes values from a GUI, and the motor program chases the new position, with ramp up and ramp down on every move. There are two halves to the assembly program, one is for a forward movement and one is for a reverse movement, both include provisions for decelerating during a current move.
The problem seems to be in Repeat 4 ' Forward Decel (same issue on the Reverse too) which is the point at which a move will start to ramp down over the last 1000 steps. The Ramp down is supposed to start at the same speed it was moving at during the maximum speed of the move, set by MAXSPEED. But what seems to be happening is that the Decel Repeat4 does not pick up at the same speed, but starts it's loop at a slower speed, and an audible 'thump' is heard at the transition. I am not good at assembly, and have tried several attempts to get the repeat4 to use the same speeds for waitcnt but have had no luck. I was hoping someone might see something obvious so that it would be simple to have repeat4 assume the same speed(waitcnt value) and ramp down from there.
Repeat2 is the starting motion repeat loop which includes ramp up. At the end of the Repeat2, it should go to Repeat4 for the final 1000 steps. The idea being that the steps start out at a slow rate(accel) with waitcnt, then the accel value is decreased every loop until the maximum speed is achieved. For the last 1000 steps, the Repeat4 picks up, and it should use the same accel value( or MAXSPEED) and slow from there by increasing the waitcnt amount.
At higher speeds, I think this transition is causing lost steps and a cumulative drift, lower speeds are fine.
Here is the repeat 4. The program is uploaded as well, see the DAT for the problem.
The illustration shows the thump.
The problem seems to be in Repeat 4 ' Forward Decel (same issue on the Reverse too) which is the point at which a move will start to ramp down over the last 1000 steps. The Ramp down is supposed to start at the same speed it was moving at during the maximum speed of the move, set by MAXSPEED. But what seems to be happening is that the Decel Repeat4 does not pick up at the same speed, but starts it's loop at a slower speed, and an audible 'thump' is heard at the transition. I am not good at assembly, and have tried several attempts to get the repeat4 to use the same speeds for waitcnt but have had no luck. I was hoping someone might see something obvious so that it would be simple to have repeat4 assume the same speed(waitcnt value) and ramp down from there.
Repeat2 is the starting motion repeat loop which includes ramp up. At the end of the Repeat2, it should go to Repeat4 for the final 1000 steps. The idea being that the steps start out at a slow rate(accel) with waitcnt, then the accel value is decreased every loop until the maximum speed is achieved. For the last 1000 steps, the Repeat4 picks up, and it should use the same accel value( or MAXSPEED) and slow from there by increasing the waitcnt amount.
At higher speeds, I think this transition is causing lost steps and a cumulative drift, lower speeds are fine.
Here is the repeat 4. The program is uploaded as well, see the DAT for the problem.
The illustration shows the thump.
repeat2 'START FORWARD motion here if new position > current position 'run := LONG[newposition] - LONG[currentposition] NEW position - current position RDLONG tnew, newposition RDLONG tcurrent, currentposition MOV Run, tnew SUBS Run, tcurrent RDLONG tMaxSpeed, MaxSpeed 'turn pin on RDLONG PHSA, pwidth ' <<<<<FIRE PIN FORWARD ACCEL+ RUN MINS accel, tMaxSpeed MOV ctmp1, accel ADD ctmp1, CNT WAITCNT ctmp1, #0 SUBS accel, arate 'accel - arate to ramp up speed ' 'update position +1 'LONG[currentposition] := LONG[currentposition] + 1 MOV ctmp1, currentposition RDLONG ctmp2, ctmp1 ADD ctmp2, #1 WRLONG ctmp2, ctmp1 'update accel = accel - arate accelerate motor/loop 'if LONG[newposition] < LONG[currentposition] [[[endif2]]] RDLONG ctmp1, newposition MOV ctmp2, currentposition RDLONG ctmp2, ctmp2 CMPS ctmp1, ctmp2 WC IF_NC JMP #endif2 MOV rep3cnt, C1000 repeat4 'FORWARD DECEL <<<<<<<<<<<<<<<start ramping down, use same speed to start ramp 'set pin on RDLONG PHSA, pwidth '<<<< FIRE PIN FORWARD DECEL 1000 RDLONG tMaxSpeed, MaxSpeed MINS decel, MaxSpeed MOV ctmp1, decel ADD ctmp1, CNT WAITCNT ctmp1, #0 '<<< sets decel ramp rate ADD decel, drate 'update position by + 1 'LONG[currentposition] := LONG[currentposition] + 1 MOV ctmp1, currentposition RDLONG ctmp2, ctmp1 ADD ctmp2, #1 WRLONG ctmp2, ctmp1 'update decel rate by drate DJNZ rep4cnt, #repeat4 'decriment and jump if not 0
Comments
Instead of using separate variables for both ACCEL and DECEL, I removed all the DECEL variables and replaced them with ACCEL in the ramp down repeat loop, now it seems to work as it should.