CNC Stepper help calling all software wizards

Hi there thanks to all for the help with the cnc encoder it works well
New one for you clever software writers
I need a software solution for driving a stepper motor.
Brief
I want to use a Picaxe14M
1 Input pin for step pulse from printer port
1 Input for direction from printer port
4 outputs driving Mosfets (to Stepper motor)
When I detect a high pulse on the step input pin it will drive the stepper one step
When then dir input pin is high the next time it detects a high on the step pin it will drive the stepper one step in the opposite direction.
Hope this makes sense it is for driving a milling table on my cnc mill that I am building.
Regards Andy Quirot

P.S. I am a mechanical engineer not a computer wizard
 

evanh

Senior Member
You'd be much better off just poking all four data lines from the parallel port straight into the stepper amplifier.
 
So far CAN YOU MAKE IT WORK??????

symbol loop1 = b1
main:
if pin0 = 1 and pin1 = 0 then
loop1 = loop1 + 1
if loop1 = 5 then
loop1 = 1
end if
end if

if pin0 = 1 and pin1 = 1 then
loop1 = loop1 -1
if loop1 = 0 then
loop1 = 4
end if
end if

if loop1 = 1 then
pin5 = 1
pin4 = 0
pin3 = 1
pin2 = 0
end if
if loop1 = 2 then
pin5 = 1
pin4 = 0
pin3 = 0
pin2 = 1
end if
if loop1 = 3 then
pin5 = 0
pin4 = 1
pin3 = 0
pin2 = 1
end if
if loop1 = 4 then
pin5 = 0
pin4 = 1
pin3 = 1
pin2 = 0
end if
goto main
 
Last edited:

jonphenry

New Member
Andy, if I understand correctly what you want to do this will work for you.

When the step pin is high the dir pin will dictate fwd or rev. depending on the direction, youll drive the coils one at a time fwd or backward. Correct?

symbol move=pin0
symbol dir=pin1

main:

if move=1 and dir=0 then fwd
if move=1 and dir=1 then rev
goto main


fwd:

let b1=b1+1
goto drive

rev:

let b1=b1-1

drive:

let b1=b1 & 3
lookup b1,(%1010,%1001,%0101,%0110),b2
let pins=b2
goto main

Hope this works for you.
 
Last edited:
Hi there

Thanks for that
I will try it tonight when i have finished work looks neater than mine thanks
Regards Andy Quirot
 

SD2100

New Member
I had a fiddle with the code, I added moveflag so the stepper will only do one step per pulse from the PC, pin0 must go low and reset moveflag for each step.

Code:
symbol move=pin0
symbol dir=pin1
symbol moveflag=b0

main:
    if move=0 then
        moveflag=0
    end if
    
    if move=1 and dir=0 and moveflag=0 then fwd
    if move=1 and dir=1 and moveflag=0 then rev
goto main

fwd:
    moveflag=1
    let b1=b1+1
    goto drive

rev:
    moveflag=1
    let b1=b1-1

drive:
    let b1=b1 & 3
    lookup b1,(%1010,%1001,%0101,%0110),b2
    let pins=b2
    goto main
 

BCJKiwi

Senior Member
You could save one more line of code by removing the line moveflag=1 after both fwd: and rev: and placing it once after drive:
 
hi there
could i join the step pin and the move pin togother. so when it goes from high to low it resets the move.

The story is i brought a milling mechine and it was fitted with encoders and came with a controler card but arter one of the encoders failing i would cost to much to replace so the controler card would not work.

the software i am using to control the mill outputs a high to pin 3 of the printer port to step the stepper one step, if it wants to reverse the direction of the stepper it puts a high on pin 4 of the printer port and so on for the three steppers X,Y and Z. This i why when reversing the stepper it must NOT reset.

So this is why i want to build a controler card using Picaxe chips.

Regards Andy Quirot

P.S. it seems to work ok i am going to conect it to my mill and do some test runs??
 

jonphenry

New Member
Andy, connect Pin 3 of the printer port to pin0 on the picaxe and Pin 4 of the printer port to pin1 on the picaxe.

The commented out code is if you want only one step for each pulse from the printer port. If thats what you desire, uncomment it.

If you want the steppers to keep stepping as long as the pulse id high, leave the commented code out.

'symbol movefwd=b3
'symbol moverev=b4

main:

'if pin0=0 then let movefwd=0 endif
'if pin1=0 then let moverev=0 endif
if pin0=1 and movefwd=0 then fwd
if pin1=1 and moverev=0 then rev
goto main


fwd:

'movefwd=1
let b1=b1+1
goto drive

rev:

'moverev=1
let b1=b1-1

drive:

let b1=b1 & 3
lookup b1,(%1010,%1001,%0101,%0110),b2
let pins=b2
goto main
 
Last edited:
Top