Spin > Assembly translation needed
T Chap
Posts: 4,223
I am looking for someone to convert this to assembly. Spin isn't as fast as the need and there is no time to learn Pasm at the moment. I will advance a reasonable fee through western union tomorrow if someone can do this for me. The block to convert is Pub Motorr, I included a few other snippets to show the basics. I need to be able to modify external of the cog (3 cogs are running the pub motorr, x, y, z) the accel, decel, arate, drate value, so these will need to have parameters added to the list. They may need to be update-able while running, so the loop will needs to accommodate. I made a note in the loop.
If interested and can do this sooner than later, please PM me.
Thanks!
Post Edited (TChapman) : 8/14/2009 3:49:17 AM GMT
If interested and can do this sooner than later, please PM me.
Thanks!
long width long Pulsewidth long Disable LONG X, Xcurrent, EnaX ' same as newpos, pos LONG Y, Ycurrent, EnaY LONG Z, Zcurrent, EnaZ Long R Long Xdone, Ydone, Zdone Long GotMessage
Pub start cognew(moveX, @stack1) cognew(moveY, @stack2) cognew(moveZ, @stack3)
PUB motorr(pinstart, radr, forward, reverse, ID) | mstep, mdir, pos, for, rvrs, accel, decel, arate, drate, run x := 0 y := 0 z := 0 xcurrent := 0 ycurrent := 0 zcurrent := 0 Long[noparse][[/noparse]ID] := 1 width := -1500 Mstep := pinstart Mdir := pinstart + 1 For := Reverse 'these switched to avoid changes elsewhere up the line. Rvrs := Forward dira[noparse][[/noparse]MStep] := 1 outa[noparse][[/noparse]MStep] := 0 dira[noparse][[/noparse]MDir] := 1 outa[noparse][[/noparse]MDir] := for FRQA := 0 CTRA := %00100 << 26 + Mstep repeat accel := 90000 'getting updated in the loop aRate := 200 'getting updated in the loop decel := 10000 'getting updated in the loop dRate := 20 'getting updated in the loop frqa := 0 if LONG[noparse][[/noparse]radr] > LONG[noparse][[/noparse]radr + 4] accel := newParameter1 dedel : = newParameter2 arate := newParameter3 drate := newParameter4 Long[noparse][[/noparse]ID] := 0 'set Xdone, Ydone, Zdone as 0, still moving frqa := 1 run := LONG[noparse][[/noparse]radr] - LONG[noparse][[/noparse]radr + 4] outa[noparse][[/noparse]MDir] := For repeat run run := LONG[noparse][[/noparse]radr] - LONG[noparse][[/noparse]radr + 4] PHSA := width if accel => 400 waitcnt(accel + cnt) LONG[noparse][[/noparse]radr + 4] := LONG[noparse][[/noparse]radr + 4] + 1 accel := (accel - aRate) #> 400 'min 400 If LONG[noparse][[/noparse]radr] < LONG[noparse][[/noparse]radr + 4] 'interrupt and decel if new position in opposite dir repeat 1000 'Decel 10% of pos PHSA := width if decel => 400 waitcnt(Decel + cnt) LONG[noparse][[/noparse]radr + 4] := LONG[noparse][[/noparse]radr + 4] + 1 Decel := Decel + dRate quit If LONG[noparse][[/noparse]radr] - LONG[noparse][[/noparse]radr + 4] == 1000 'DECEL 1000 Decel 10% approx of move repeat LONG[noparse][[/noparse]radr] - LONG[noparse][[/noparse]radr + 4] PHSA := width if decel => 400 waitcnt(decel + cnt) LONG[noparse][[/noparse]radr + 4] := LONG[noparse][[/noparse]radr + 4] + 1 Decel := Decel + dRate quit Long[noparse][[/noparse]ID] := 1 ''move done if 1 'REVERSE======================================== accel := newParameter1 dedel : = newParameter2 arate := newParameter3 drate := newParameter4 frqa := 1 if LONG[noparse][[/noparse]radr] < LONG[noparse][[/noparse]radr + 4] Long[noparse][[/noparse]ID] := 0 'set Xdone as 0, not complete, still moving run := LONG[noparse][[/noparse]radr + 4] - LONG[noparse][[/noparse]radr] outa[noparse][[/noparse]MDir] := Rvrs repeat run run := LONG[noparse][[/noparse]radr + 4] - LONG[noparse][[/noparse]radr] PHSA := width if accel => 400 waitcnt(accel + cnt) LONG[noparse][[/noparse]radr + 4] := LONG[noparse][[/noparse]radr + 4] - 1 accel := accel - aRate #> 400 If LONG[noparse][[/noparse]radr] > LONG[noparse][[/noparse]radr + 4] 'interrupt and decel if new position in opposite dir rec'd repeat 1000 PHSA := width if decel => 400 waitcnt(decel + cnt) LONG[noparse][[/noparse]radr + 4] := LONG[noparse][[/noparse]radr + 4] - 1 Decel := Decel + dRate quit If LONG[noparse][[/noparse]radr + 4] - LONG[noparse][[/noparse]radr] == 1000 'decel last 1000 pulses of move repeat LONG[noparse][[/noparse]radr + 4] - LONG[noparse][[/noparse]radr] PHSA := width if decel => 400 waitcnt(decel + cnt) LONG[noparse][[/noparse]radr + 4] := LONG[noparse][[/noparse]radr + 4] - 1 Decel := Decel + dRate quit Long[noparse][[/noparse]ID] := 1 ''move done if 1 feedback for gui
Post Edited (TChapman) : 8/14/2009 3:49:17 AM GMT
Comments
To create acceleration on a stepper, the motor starts out at a rate decided by waitcnt(accel+ cnt). Accel is predefined before the move. On each iteration, Accel should get reduced by aRate, or accel rate. So that the time gets shorter each iteration, the steps to the stepper get closer together, faster RPM. In spin the code works great. In the ASM rendition, the Accel does not change, the speed stays set by Accel. If someone could take a look and see if there is an obvious reason why Accel is not being reduced by aRate that would be great. This code is in the same file as the caller. The decel is working as it should.
Thanks for any suggestions.
There are 3 calls moveX, moveY and moveZ which look like: