Shop OBEX P1 Docs P2 Docs Learn Events
Counters for stepper control — Parallax Forums

Counters for stepper control

Graham StablerGraham Stabler Posts: 2,510
edited 2007-01-04 00:47 in Propeller 1
Sorry this is a bit long and rambly but if you want to do CNC or high performance stuff with steppers it may be of interest.

One of the main reasons for my interest in the counter modules was in using them for stepper motor control. I'm moving house next week and am all but packed up ready for a new job in different part of the country but last week I got some time to myself and had a stepper actuator moving in a very pleasing way indeed using the counter modules.

The way I did it was to have a loop, this loop repeated every 1000us as specified by a waitcnt in assembly. The pinA of counter A was connected to the step input of my stepper motor. And this was also connected to the input pin of a second counter running in edge detection mode.

To ramp the speed, a constant acc was added to FRQA on every loop until a maximum was obtained, then the frequency was kept constant until the distance left to travel (as determined by the second counter) equalled the distance taken to accelerate to top speed. At that point acc was taken from FRQA until the distance travelled was as required.

Anything more than a cursory glance at that set up will reveal it is far from ideal but it does get the job done, the beauty being that at the point where it really matters how far you have gone you are moving slowly (comming to rest) and checking the position 1000 times a second is fine.

HOWEVER, I think there is a better way in fact I am fairly sure there is because someone has already done it, the G-Rex from geckodrive uses a numerically controlled oscillator to drive the stepper motors, it also has a loop running at a speed defined by the same master clock. However it cleverly does not bother to count clock pulses, instead it simply relies on the fact that if you intergrate velocity you get distance.

I tried this out on the propeller, on every one of my loops I add acc to FRQ and then add FRQ to an accumulator, this accumulator is proportional to the distance because for example if the step frequency is 1khz and you are looping at 1khz you know you have travelled 1 step on every loop etc etc.

My basic test of this worked a treat, I can move my stepper back and forth at great speed and with tremendous smoothness. The smooth acceleration also reduces the torque demand on the motor on acceleration.

One thing I did notice however was that it did not want to stop for certain distances travelled Why? Well as you ramp up you add acc to FRQ on every loop and you add frq to a variable I will call up and you take it from a variable I will call down which is set to be th distance to travel at the start. When FRQ is the max speed desired you keep going at that speed taking FRQA from down as you go but keeping up the same. When up=down it is time to decellerate until FRQA is zero at which point the full distance should have been covered.

The problem is that it is not. This is why: for a given acc, loop-period and max velocity the acceleration and decelleration phases will take a fixed distance, to ensure you travel the correct distance overall all you can do is alter the number of loops in the cruise stage (assuming there is one) the resolution of position is then the maximum velocity or in other words the distance travelled in 0.01seconds at the max speed. This could be many pulses. It is therefore necessary to jiggle with acc and the max speed before hand to make sure it all works out, that is the only part I have not done.

The upshot of all this is that the propeller should be able to control two axes per cog and very possibly syncronize between multiple cogs, linear interpolation is done by simply working out the frequency ratios between the axes (45 degree move they are equal etc), circular interpolation could also be done with the aid of some cordic, with 1000us to spare it should have time as it is doing nothing else other than adding a few numbers.

If you want to learn more read this post on the geckodrive yahoo group, you will have to join but it is probably worth it if you are interested.

http://finance.groups.yahoo.com/group/geckodrive/message/5

Graham

in a few weeks when I am settled I'll set up the motor again and do a video.

Comments

  • BTXBTX Posts: 674
    edited 2007-01-03 01:43
    Hi Graham.

    Did you see my posts ?

    http://forums.parallax.com/showthread.php?p=620604
    http://forums.parallax.com/showthread.php?p=619570

    Perhaps it could be usefull for you , I didn't use counters, and get very good speed and positioning, but not for CNC machine....

    Usually I drive 6 Nm steppers at more or less 1000 RPM.

    Regards.

    ALberto.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-01-03 11:19
    Yes I did, very interesting stuff however I think the potential for this approach could be amazing.

    For example the G-rex although capable of doing linear interpolation between 6-axis it does not have the processing power to do circular interpolation between 6-axis as you might want to do when controlling a hexapod. Using the propeller you still only have 1000us in which to do this but you have many processors, the processor that produces the pulses just needs to load velocity data from hub ram and stick it on the counters. Its strange to imagine it but any set of even complex multiaxis moves can be represented as just a set of numbers put into the counters FRQ on every loop. The challenge is working out those numbers.

    When a 16cog processor with hardware multiply comes about the sky is the limit.

    Graham

    p.s. I like parallel kinematics: http://www.indoor.flyer.co.uk/kinematics.htm
    p.p.s It would be great for making brooms
  • BTXBTX Posts: 674
    edited 2007-01-03 14:34
    Wow !! that's really cool !! (parallel kinematics)
    I've thinking to do my stepper controller using counters but I didn't it because, when I started the project, I haven't the counters document by parallax, and because when I tried with simple design in spin, I can see, that this could be enough fast for the final speed that I needed, could be really interesting to see your code, when you'll post it.
    At the moment it's sound for me, too much complicated for my actual experience is PChip.

    Best regards.
    Alberto.

    PS. Perhaps in the future I'll be interesting to explore a CNC machine for me (hobby).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-01-03 18:42
    Alberto, I think it will take a while to get something up and running so you are probably best to stick with your routines, they seem to work very well indeed.

    As for me I need to learn more about motion control.

    Cheers,

    Graham
  • BTXBTX Posts: 674
    edited 2007-01-04 00:47
    Graham.
    No problem, my machines are now working with some like those rutines, just I was using three COP8SAC7 to drive three axis, and a AT89S8252 to charge each COP with data, now I'm using only one PChip for that, and the performance is better than the COPs, so I'm not thinking to change again it. (too much time in each factories to do the work....).
    Just only ask for, in the future to play with CNC machine ...(If I'll get some time free). From a long time ago this CNC machines are rounding in my mind..

    Good luck with the projrct and regards !!
    Alberto.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.