Shop OBEX P1 Docs P2 Docs Learn Events
High frequency Stepper Motor driving — Parallax Forums

High frequency Stepper Motor driving

How would we handle this on the P2, is there a smartpin mode that would suit?

Craig

Comments

  • Not totally following you here. The DMC controller is able to control X number of servos or stepper motors up to 6 million steps per second.

    The P2 can output pulses at that rate but needs a driver board to handle the motors.

    A smartpin would really not be needed here as you want to control these motors by outputting a number of pulses at a set or scaled frequency to do precise movements.

    There is a smartpin mode to control servos that are driven by a frequency though.

    Mike

  • @iseries said:
    Not totally following you here. The DMC controller is able to control X number of servos or stepper motors up to 6 million steps per second.

    The P2 can output pulses at that rate but needs a driver board to handle the motors.

    Oh, this is understood. I am only interested in generating the pulse/direction signals.

    A smartpin would really not be needed here as you want to control these motors by outputting a number of pulses at a set or scaled frequency to do precise movements.

    I have never driven a stepper because I am more of a closed-loop servo guy and so my initial thoughts are:

    I already have the velocity profiler/trajectory generator which runs @500Hz, the output of which feeds the PID and the PID is responsible for commanding the BLM or whatever. For a stepper, I imagine dumping X number stepper pulses in a register and specifying the rate at which they are sent to the stepper driver. Or am I overcomplicating this? :|

    Craig

  • %00100 = pulse/cycle output
    this smartpin mode should work

    output N pulses at X frequency and then stop

    if your control loop runs at 500 Hz, you have a 2 milliseconds frame that each of the axe's smart pins should fill with steps. it is unlikely that it fills this 2 ms frame exactly, it will always have to wait a little. this will lead to jittering if not cared for.

  • @Simonius said:
    %00100 = pulse/cycle output
    this smartpin mode should work

    output N pulses at X frequency and then stop

    if your control loop runs at 500 Hz, you have a 2 milliseconds frame that each of the axe's smart pins should fill with steps. it is unlikely that it fills this 2 ms frame exactly, it will always have to wait a little. this will lead to jittering if not cared for.

    Excellent! Many thanks and yes, I expect that some form of buffering might be required. If the smartpin can be used, I'll make it work.

    P2: The answer is "yes", now, what's the question? :)

    Craig

  • pik33pik33 Posts: 2,366
    edited 2023-07-16 17:48

    I control a stepper in my robot. It extends or hides the arm with lamps. No advanced stuff there at all :) As it does its job at needed speed, I didn't even try to play with smartpins or asm. Waitus() amount was determined experimentally to make the arm open at desired speed.

    sub opendownarm
    
    var q=0
    var q2=0
    q=pinread(end_a2)
    if q=0 then exit sub
    pinl(dir2)
    do
      if block<>0 then exit loop
      q=pinread(end_a2)
      if q=0 then q2=q2+1
      if q=1 then q2=0
      if q2>=10 then exit loop
      pinl(pwm2)
      waitus(200)
      pinh(pwm2)
      waitus(200)
      if channel(l_button)<1800 then exit loop
    loop 
    
    end sub
    
  • If you do want to try the smart pin route, it's pretty easy.

    This sets up a pin to output pulses.

    pub config_pulse_pin(pin, khz) | m, x
    
      m := P_PULSE | P_OE
      x.word[0] := 2 #> (clkfreq / (khz * 1_000)) <# $FFFF          ' ticks in period
      x.word[1] := x.word[0] >> 1                                   ' ticks in low cycle (50%)
      pinstart(pin, m, x, 0)
    

    To generate pulses on a smart pin (with option to wait for conclusion of pulses).

    pub pulses_out(pin, count, hold)
    
      pinfloat(pin)                                                 ' reset
      wypin(pin, count)                                             ' set new count
      pinlow(pin)                                                   ' start pulses
    
      if (hold)
        repeat until pinr(pin)                                      ' let pulses finish
    
  • The only positive experience I ever had with steppers is that they put me in business :D
    A huge machine destined for General motors had 3 huge stepper motor axes. Positioning was all over the place.

    I was called in to investigate and told them that they needed to throw away this open loop garbage and stick some closed-loop servos on there. They hired me to make it happen and gave me carte blanche.

    It was a success and they decided that they wanted a bunch more of these machines, provided that I developed the controls. Instant profitable business :+1:

    I will never accept an open loop solution, no matter what :)

    Craig

  • @JonnyMac

    Many thanks Jon...heck, the Props never fail to put a smile on my face B)

    Craig

Sign In or Register to comment.