Step and Direction code from Picaxe, any example code I could start with?

elanman99

Senior Member
I have a stepper motor driven rotary table to use on my milling machine. I also have a PSU and an all singing, all dancing, driver for it that has logic inputs for step, direction and enable.

I want to use a Picaxe with keypad and a serial 16x2 LCD so that I can index the table to set positions. I could start from scratch and create a new programme but I wondered if anyone has done something similar that I could adapt? I have looked in the completed projects section but many of the stepper circuits use the Picaxe to generate signals for each motor winding which I don't need.

Ian
 

oracacle

Senior Member
you would need to encode either it current position or its start position, other than that, all it is is high/low for direction, high low for enable, and pulse the the pin.

its very hard to be able to specifiy what you need to do as you havent specified very much information about what you are doing or posted very much about the hardware - this all singing and dancing driver, is 12v cmos logic, or 5v ttl logic

i did wright quite an extenive set of codings for use with a similar (i presume simlar) controller, direwction is dictated by checking the current known position (start plus x number of step, converted into distance), to the new wanted postion, if the the number was greater then the motor would go one way, lesser the other way

here is a small section of code using the FPU to determin, both direction and number of rotations and steps that need to be taken to obtain the correct postion for the carriage.

Code:
[color=Blue]if [/color][color=Black]tempbyte [/color][color=DarkCyan]<= [/color][color=Navy]129 [/color][color=Blue]then                               [/color][color=Green]'check for too great
            [/color][color=Blue]high [/color][color=Black]cw_ccw
                  [/color][color=Green]'if carriage is to move forward, calculate difference
            [/color][color=Blue]hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Black]selecta, tfloat0, fset, depth, fsub, compare[/color][color=Blue])
            hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Black]selecta, tfloat0, fdiv, thread, fsplit[/color][color=Blue])
                  [/color][color=Green]'tfloat0 noe contains interger, whis will be number of rotatiions
            [/color][color=Blue]hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Black]selecta, tfloat1, fset0[/color][color=Blue])
            hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Black]selecta, tfloat2, fset, steps, fmul, tfloat1[/color][color=Blue])
                  [/color][color=Green]'tfloat2 now contains number of steps
            [/color][color=Blue]low [/color][color=Black]cw_ccw
      [/color][color=Blue]else if [/color][color=Black]tempbyte [/color][color=DarkCyan]>= [/color][color=Navy]129 [/color][color=Blue]then                          [/color][color=Green]'check for number too low
            [/color][color=Blue]low [/color][color=Black]cw_ccw
                  [/color][color=Green]'if carriage is to move backword, calculate difference
            [/color][color=Blue]hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Black]selecta, tfloat0, fset, compare, fsub, depth[/color][color=Blue])
            hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Black]selecta, tfloat0, fdiv, thread, fsplit[/color][color=Blue])
            [/color][color=Green]'hi2cout 0, (selecta, tfloat0, fmul, thread, )
                  'tfloat0 now contains interger, whis will be number of rotatiions
            [/color][color=Blue]hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Black]selecta, tfloat1, fset0[/color][color=Blue])
            hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Black]selecta, tfloat2, fset, steps, fmul, tfloat1[/color][color=Blue])
                  [/color][color=Green]'tfloat2 now contains number of steps
            [/color][color=Blue]high [/color][color=Black]cw_ccw
      [/color][color=Blue]end if[/color]
dunot know if that is any help

heres is s ection code that parks the carriage and the start

Code:
      [color=Blue]setfreq m16                                                 [/color][color=Green]'set frequence to 16mhz
      [/color][color=Blue]high [/color][color=Black]enable                                                 [/color][color=Green]'enable motor
      [/color][color=Blue]if [/color][color=Black]M_end [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then                                           [/color][color=Green]'check for carriage at motor end
            [/color][color=Blue]high [/color][color=Black]cw_ccw                                           [/color][color=Green]'set motor direction - toward bearing
            [/color][color=Blue]for [/color][color=Black]tempword [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]6400                              [/color][color=Green]'move 2mm
                  [/color][color=Blue]high [/color][color=Black]clk : [/color][color=Blue]low [/color][color=Black]clk                              [/color][color=Green]'increment motor
            [/color][color=Blue]next [/color][color=Black]tempword
      [/color][color=Blue]end if
      if [/color][color=Black]B_end [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then                                           [/color][color=Green]'check for carriage at bearing end
            [/color][color=Blue]low [/color][color=Black]cw_ccw                                            [/color][color=Green]'set motor direction, towards motor
            [/color][color=Blue]for [/color][color=Black]tempword [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]6400                              [/color][color=Green]'move 2mm
                  [/color][color=Blue]high [/color][color=Black]clk : [/color][color=Blue]low [/color][color=Black]clk                              [/color][color=Green]'increment motor position
            [/color][color=Blue]next [/color][color=Black]tempword
      [/color][color=Blue]end if
      low [/color][color=Black]enable                                                  [/color][color=Green]'disable motor
      [/color][color=Blue]setfreq m8[/color]
 

elanman99

Senior Member
you would need to encode either it current position or its start position, other than that, all it is is high/low for direction, high low for enable, and pulse the the pin.

its very hard to be able to specifiy what you need to do as you havent specified very much information about what you are doing or posted very much about the hardware - this all singing and dancing driver, is 12v cmos logic, or 5v ttl logic

i did wright quite an extenive set of codings for use with a similar (i presume simlar) controller, direwction is dictated by checking the current known position (start plus x number of step, converted into distance), to the new wanted postion, if the the number was greater then the motor would go one way, lesser the other way

here is a small section of code using the FPU to determin, both direction and number of rotations and steps that need to be taken to obtain the correct postion for the carriage.
Thanks

The stepper controller I have is a 'Centent CN0162' microstepping one that is very configurable and can drive 4 wire motors at up to 7 Amps on an 80 Volt supply. It has opto isolated inputs so interfacing it to a Picaxe is straightforward. The 200 step motor drive the table via a 60:1 worm reduction.

I want to be ably to divide 360 degrees (c200,000 steps) into different amounts for cutting gear teeth and drilling circular flanges with a pattern of bolt holes. Pre-programmed PIC and Atmel chips are available but the ones I have seen drive the stepper coils direct so do not appeal to me. I expect I would want to enter start position using +/- buttons to increment the motor manually, then start (drill first hole or whatever) then the table would move to the next angular position on a switch closure, and the process repeated for the full circle.

Apart from being to divide up a single rotation the ability to run continuously at different (slow) speeds would be useful. Once I have the basic programme working the ease of programming a Picaxe means I can easily modify and adapt as I go along.

Without feedback the code would only know its start position so would have to store and calculate from that.

Ian
 

oracacle

Senior Member
Ok, that makes a little more sense, its looking to be a very maths heavy situation too. You have a 200 step motor, witha 60:1 reduction and then the micro step which i presume you need to pre-select.

if we presume you use full step mode you get 12000 steps for a single rotation of the bed, or 0.03 degree for each step of the motor (depending on back lash). when you say 200,000, is the 200,000 step from the motor or of the table

You maybe able to atapt something i used for calulating the number if rotations and step for the distance to be travelled
number of rotations = distance / number of steps - the whole number is the number of rotation
the decimal is the multiplied by the number of steps per rototation

eg: my controller gave my 12600 micro step per roation, and i used a thre pitch of 4mm
6mm = 6/4 = 1.5
0.5 * 12600 = 6300

hmm, maybe simple thinking about, degrees to move * degrees per step.
once you know how many step in a motor rotation you should be able to figure out the number of rotations, if needed. you can have variable for the degree of motion, an a varible to hold a flag to define + or - direction.

like that you maybe able to have the code code you want on a eeprom or alikes

This could be an interesting project
 

elanman99

Senior Member
I dont know how I dreamt up the 200,000 number, its 12,000 as you pointed out. I was not planning to use the microstepping mode as full steps give me more than enough resolution.

Now I need to give some thought to planning the programme, maths is not my best subject but I will do it in stages as I go along.

Ian
 

SAborn

Senior Member
You do know that programs like Mach3 etc will directly interact with your driver card through a parallel port on any old redundant PC, and then you have the advantage of using some simple CAD programs to write the design G-code for you.

A old PC will always be 100 or 1000 times faster than any picaxe controller, and work far better and smoother than a Slo...ow picaxe.

Computers are great at number crunching, where a picaxe is poor at that task, and as all CNC coords are just number crunching than the PC is the far better option.
 
Top