PDA

View Full Version : Problem Time

Newzed
08-05-2005, 10:26 PM
I have a small problem.· I need to move my stepper 25.75 steps.· Obviously, the BS2E can't do that.· If I move the stepper 26 steps, every four iterations the stepper gains one step, so every fifth iteration I need to move the stepper only 25 steps to compensate for the error.· Is this the correct way to do it?

goleft:
HIGH dir
z = 0·········· 'counter
w = 26········· 'number of steps
FOR x = 1 TO w·
PULSOUT stp, 10
z = z + 1
IF z = 5 then
w = 25
z = 0
ELSE w = 26
ENDIF
NEXT
PAUSE 1000
RETURN

Sid

Yanroy
08-05-2005, 10:41 PM
If I understand your code correctly, I think having the IF statement inside the loop introduces a logic error.· I think you need a nested loop:

goleft:
HIGH dir
for z = 0 to 5 'counter
IF z = 5 then
w = 25
ELSE
w = 26
ENDIF

FOR x = 1 TO w
PULSOUT stp, 10
NEXT
NEXT
PAUSE 1000
RETURN

This should execute the PULSOUT 26 times each of the first 4 loops, but 25 times for the·fifth loop.· You may need to put this inside even another loop if you want to run even further (or you can call the subroutine multiple times).· Since this didn't seem to be a concern in your original code, I think you can handle it here :)· good luck.

Newzed
08-05-2005, 11:57 PM
Yanroy, I studied your program, but I don't think it will work.· I only want the stepper to step 26 times - this equals .0005 of travel -· except that every fifth step is 25 instead of 26.· With your program, the stepper will step·4 x 26 + 1 x 25 = 129 steps = .0025 travel. I loaded the program and ran it, debugging w, x, and z.· It cycled thru the x line 5 times with the fifth iteration w = 25.

Thanks for the effort anyway -· it is sincerely appreciated.

Sid

·

Yanroy
08-06-2005, 03:07 AM
ah, I understand a lot better now what you meant... Adapting what I gave you to what you actually wanted it to do should be a very simple matter.· Just remove the outer loop and make sure that NOWHERE else in your program is the z variable changed.

goleft:
HIGH dir
z = z + 1
IF z = 5 then
z = 0
w = 25
ELSE
w = 26
ENDIF

FOR x = 1 TO w
PULSOUT stp, 10
NEXT

PAUSE 1000
RETURN

The variable z is being treated like a static member variable in C++ (if you're not familar with C++, don't worry about it).· I hope this is the correct solution.

Another thought: I'm guessing you're attempting to build a CNC machine.· If you want to make this even more accurate (and simplify the code), have whatever is sending the movement info (I assume a computer) crunch the numbers to figure out how many steps there should be in whatever motion it has planned.· This will essentially cause it to "round" to the nearest step.

Newzed
08-06-2005, 04:51 AM
I just figured out that what I wrote above won't work - no matter what, the program is going to cycle 26 times, which is too much travel.· What I need to do is change the travel, not the steps.· So I thought that if I periodically reversed the travel for just a few steps, I could compensate for the excess travel.· This is what I want to say:

for y = 1 to 1000
if y/111 'is an integer then gosub correct'·· Need help with this
w = 26········· 'number of steps
FOR x = 1 TO w·
PULSOUT stp, 10
next
pause 500
next

Something like (Ithink):

x = 111
z =y//x
if z = 0 then gosub correct

Am I close?

Post edited.

Sid

Post Edited (Newzed) : 8/5/2005 9:54:26 PM GMT

Newzed
08-06-2005, 04:57 AM
I just corrected my last post.

Sid