​ ​ ​ ​ stepper-control-with-acceleration - Page 3
Page 3 of 3 FirstFirst 1 2 3
Results 21 to 27 of 27

Thread: stepper-control-with-acceleration

  1. #21
    Senior Member
    Join Date
    Jan 2010
    Location
    34 France
    Posts
    3,767

    Default

    About pauseus :

    on a 14M2 @ 4MHz:
    Pauseus 05 = 1044 Ás
    Pauseus 10 = 1094 Ás
    Pauseus 50 = 1533 Ás
    Pauseus 100 = 2038 Ás
    Pauseus 200 = 3022 Ás
    Pauseus 500 = 6189 Ás
    Pauseus 1000 = 10726 Ás
    Pauseus 10000 = 100635 Ás
    S'il n'y a pas de solution, c'est qu'il n'y a pas de problŔme . (Les Shadoks)

  2. #22
    Senior Member
    Join Date
    Feb 2012
    Location
    London
    Posts
    2,430

    Default

    Hi,

    Yes, the incremental step is close to 10 us, but there is some additional "overhead" (which may not be constant). I measured (post #12) PAUSEUS 1 at about 720 us and PAUSEUS 2 at 730 us, etc., but PAUSEUS 0 at 630 us, which is significantly slower than PAUSE 0 that I timed at around 300 us (the fastest M2 PICaxe command I've found so far).

    PICaxe stores numbers as variable-width tokens, which may explain why commands using integer values of less than 2, and less than 256 (and < 16?) may execute faster than when larger values are used. However, numerical calculations are always performed on Word values, so there is no speed advantage in using byte variables in calculations.

    For this thread I checked a few more execution times; FOR .. TO .. STEP .. NEXT takes around 1700 us per pass (@ 4 MHz = Instruction cycles) and (IIRC) PULSOUT N around 600 + 10*N us. But beware of READ{TABLE} with a WORD qualifier, which can be rather slow because the compiler increments and then decrements the "pointer" each time.

    Cheers, Alan.
    Last edited by AllyCat; 25-05-2017 at 16:29.

  3. #23
    Senior Member
    Join Date
    Feb 2012
    Location
    London
    Posts
    2,430

    Default

    Hi,

    Quote Originally Posted by PieM View Post
    on a 14M2 @ 4MHz:
    Pauseus 05 = 1044 Ás
    Pauseus 10 = 1094 Ás
    Pauseus 50 = 1533 Ás
    Pauseus 100 = 2038 Ás
    Pauseus 200 = 3022 Ás
    Pauseus 500 = 6189 Ás
    Pauseus 1000 = 10726 Ás
    Pauseus 10000 = 100635 Ás
    I didn't want to say that those figures are "wrong", because measuring consistent PICaxe execution times is almost impossible, due to the variable-width tokens and many other factors. Also (as with many PICaxe instructions), it's possible to use either a variable (eg W2) or a "literal" constant (ie a number) as the parameter. So I've been rechecking my measurements and the above figures do seem rather high. Here are the figures that I've just measured on a 20M2, using the method I linked above.

    Code:
     
    pauseus w2 =0 = 641us 
    pauseus w2 =1 = 731us 
    pauseus w2 =2 = 741us 
    pauseus w2 =5 = 771us 
    pauseus w2 =10 = 821us 
    pauseus w2 =50 = 1221us 
    pauseus w2 =100 = 1721us 
    pauseus w2 =200 = 2721us 
    pauseus w2 =500 = 5721us 
    pauseus w2 =1000 = 10721us 
    pauseus w2 =5000 = 50721us 
    pause w2 =0 = 420us 
    pause w2 =1 = 1408us 
    pause w2 =2 = 2414us 
    pause 0 = 361us 
    pause 1 = 1342us 
    pause 2 = 2384us 
    pauseus 0 = 545us 
    pauseus 1 = 646us 
    pauseus 2 = 709us 
    pauseus 5 = 709us 
    pauseus 10 = 757us 
    pauseus 50 = 1248us 
    pauseus 100 = 1751us 
    pauseus 200 = 2725us 
    pauseus 500 = 5863us 
    pauseus 1000 = 10804us 
    pauseus 5000 = 50821us
    The results using the variable (w2) are completely consistent (but may be different if even a tiny change is made to the program structure). However, the values using a "constant" differ considerably because of the variable token widths and boundaries. Note that the same result for PAUSEUS 2 and 5 is NOT a bug (just a coincidence), they will be quite different if the program is changed even slightly !

    For anyone who wants to check the method (or adapt it for their own measurements) here is my test program. Maybe one day I will "tidy it up" to be a little less obscure, but I've found it to be a very useful tool. However it will only run a "real" M2, not an X2 or the simulator. Note the "sanity checks" which may show if a system interrupt has occurred and occasionally the program may produce a result exactly 256 in error.

    Code:
    #picaxe 20m2			; Or any other M2
    #no_data
    
    symbol TMR1L = $16		; SFRs only tested with M2 PICAXEs
    symbol TMR1H = $17
    symbol T1CON = $18
    
    exectimes:
    ;	pause 100    ; Make a tiny change to this (or any) line and the results may be different !
    	for b25 = 0 to 256 step 64		; Sanity check with different initial Timer values
    	w13 = 0					; Null delay (subroutine call, etc.)
    	b1 = b25					; Not used
    	b2 = b25					; Not used
    	sertxd(cr,lf,"Skew= ",#b25," Overhead= ")
    	gosub start
    	gosub measure
    	gosub show
    	w13 = w11						; Set NUL time
    	for b1 = 0 to 10
    		lookup b1,(0,1,2,5,10,50,100,200,500,1000,5000),w2
    		sertxd(cr,lf,"pauseus w2 =",#w2," = ")		; Test 0 Code
    		gosub start
    		pauseus w2 
    		gosub measure
    		gosub show
    	next b1
    
    	sertxd(cr,lf,"pause w2 =0 = ")			; Test 1 Code
    	w2 = 0
    	gosub start
    	pause w2
    	gosub measure
    	gosub show
    	
    	sertxd(cr,lf,"pause w2 =1 = ")			; Test 1 Code
    	w2 = 1
    	gosub start
    	pause w2
    	gosub measure
    	gosub show
    
    	sertxd(cr,lf,"pause w2 =2 = ")			; Test 1 Code
    	w2 = 2
    	gosub start
    	pause w2
    	gosub measure
    	gosub show
    			
    	sertxd(cr,lf,"pause 0 = ")				; Test 2 Code
    	gosub start
    	pause 0
    	gosub measure
    	gosub show
    	
    	sertxd(cr,lf,"pause 1 = ")				; Test 3 Code
    	gosub start
    	pause 1
    	gosub measure
    	gosub show	
    
    	sertxd(cr,lf,"pause 2 = ")				; Test 4 Code
    	gosub start
    	pause 2
    	gosub measure
    	gosub show
    				
    	sertxd(cr,lf,"pauseus 0 = ")				; Test 5 Code
    	gosub start
    	pauseus 0
    	gosub measure
    	gosub show
    
    	sertxd(cr,lf,"pauseus 1 = ")				; Test 6 Code
    	gosub start
    	pauseus 1
    	gosub measure
    	gosub show
    	
    	sertxd(cr,lf,"pauseus 2 = ")				; Test 7 Code
    	gosub start
    	pauseus 2
    	gosub measure
    	gosub show	
    	
    	sertxd(cr,lf,"pauseus 5 = ")				; Test 8 Code
    	gosub start
    	pauseus 5
    	gosub measure
    	gosub show	
    	
    	sertxd(cr,lf,"pauseus 10 = ")				; Test 9 Code
    	gosub start
    	pauseus 10
    	gosub measure
    	gosub show
    
    	sertxd(cr,lf,"pauseus 50 = ")				; Test 10 Code
    	gosub start
    	pauseus 50
    	gosub measure
    	gosub show
    	
    	sertxd(cr,lf,"pauseus 100 = ")			; Test 11 Code
    	gosub start
    	pauseus 100
    	gosub measure
    	gosub show	
    	
    	sertxd(cr,lf,"pauseus 200 = ")			; Test 12 Code
    	gosub start
    	pauseus 200
    	gosub measure
    	gosub show
    
    	sertxd(cr,lf,"pauseus 500 = ")			; Test 13 Code
    	gosub start
    	pauseus 500
    	gosub measure
    	gosub show
    	
    	sertxd(cr,lf,"pauseus 1000 = ")			; Test 14 Code
    	gosub start
    	pauseus 1000
    	gosub measure
    	gosub show	
    	
    	sertxd(cr,lf,"pauseus 5000 = ")			; Test 15 Code
    	gosub start
    	pauseus 5000
    	gosub measure
    	gosub show
    
    	sertxd(cr,lf,"Nul Test: ")				; Sanity check
    	gosub start
    	gosub measure
    	gosub show	
    	sertxd(cr,lf)
    
    	pause 10000
    	next b25	
    
    ; Subroutines
    start:
    	pokesfr TMR1L,b25				; Sanity check
    	pokesfr TMR1H,0
    	return
    measure:
    	peeksfr TMR1H,b22				; Read 1st Hi byte
    	peeksfr TMR1L,b24				; Read Low byte
    	peeksfr TMR1H,b23				; Read 2nd Hi byte
    report:
    	if b24 < 128 then inc b22 endif
    	w11 = b22 + b23 / 2				; Average Start High
    	b23 = b22
    	b22 = b24					; Start Low byte
    	w11 = w11 - w13 - b25
    	return
    show:	
    	sertxd (#w11,"us ")	
    	return
    Cheers, Alan.

  4. #24
    Senior Member
    Join Date
    Sep 2016
    Location
    United Kingdom
    Posts
    668

    Default

    I tried some ebay cheap steppers with this or some similar code
    Code:
    ;28x2 A.0 to A3 are unipolar motor pins 
    #picaxe 28x2
    Symbol oYellowLED       = C.2
    
    symbol posrotor         = b0
    symbol direc            = b1
    symbol outbyte          = b2
    symbol motorspeed       = b3
    symbol tempmotorspeed   = b4
    '
    '      Misc Constants
    Symbol False            = 0
    Symbol True             = 1
    '
    '      Timer Constants
    Symbol mskBGTimer       = %10000000 'When only the timer is running (normally would have hInt0 & 1 config as well)
    Symbol flgBGTimer       = %10000000 'When only the timer is running (normally would have hInt0 & 1 config as well)
    Symbol tmrIntOn1stTick  = 65535     'Interrupt to be caused by roll over on first major tick
    Symbol tmr10mS_16        = 64911     '= 65536 - (Treq * 1,000,000 / Clk / 256)
    'Symbol tmr100mS_8x4     = 62411     '= 65536 - (Treq * 1,000,000 / Clk / 256)
                                        ' Where: Treq = Required Time in microseconds; Clk = 16,000,000.
    '
    Init: let dirsa=%11111111
          let posrotor=1
          let direc=1
          let motorspeed=0
          let tempmotorspeed=motorspeed
          setfreq m16
          '
          'Start the background timer (runs continuously)
          TOFlag = False
          Timer = tmrIntOn1stTick             '
          SetTimer tmr10mS_16                 'Expires after (every) 100 milliseconds
          SetIntFlags flgBGTimer, mskBGTimer  'Set timer 0 to interrupt
          '
          ' **** Main Loop ****
    do
    ;let direc=1
    ;for w6=1 to 65535
    ;next w6
    ;pause 2000
    
    ;let direc=0
    ;for w6=1 to 65535
    ;next w6
    ;pause 2000
    loop  
    
     
    Interrupt:  High oYellowLED
                If tempmotorspeed > 0 then
                   dec tempmotorspeed
                Else
                   let tempmotorspeed=motorspeed
                   if direc=0 then
                      inc posrotor
                      if posrotor=8 then
                         let posrotor=1
                      endif 
                   else
                   dec posrotor
                   if posrotor=0 then
                      let posrotor=8
                      endif
                   endif
                   lookup posrotor,(0,%00000011,%00000010,%00000110,%00000100,%00001100,%00001000,%00001001),outbyte
                   pinsa=outbyte
                EndIf
    Int_Enable: TOFlag = False                            'Clear the flag
                Timer = tmrIntOn1stTick                   'Reset the timer
                SetIntFlags flgBGTimer, mskBGTimer        'Set timer 0 to interrupt
                Low oYellowLED
                return
    I got 2 motor code as well,same but 2 motors,more pins

  5. #25
    Senior Member
    Join Date
    Aug 2011
    Location
    US
    Posts
    447

    Default

    Wow. It's really amazing how far off the responses to the OP question have become. He wanted to accelerate a stepper from a dead stop to some given speed, using a dedicated stepper driver. His question was valid, because most stepper motors won't go from zero to max step rate in one go. From what I understand, his question was how to fix that. NOT how to phase sequence stepper coils or anything like that. Go back to the original post, and try again folks.

  6. #26
    Senior Member
    Join Date
    Feb 2012
    Location
    London
    Posts
    2,430

    Default stepper-control-with-acceleration

    Hi,

    Hmm, the code seems to run at maximum speed (100 Hz ?) when "motorspeed" is set to zero, half-speed if set to 1 , 1/3 speed for 2, etc., but I can't see any code for acceleration / deceleration. Also, there appears to be a bug, so it uses only 7 phases (Coil on A.0 is never driven alone).

    Cheers, Alan.

  7. #27
    Senior Member
    Join Date
    Feb 2012
    Location
    London
    Posts
    2,430

    Default

    Quote Originally Posted by rq3 View Post
    .. the OP question was valid, because most stepper motors won't go from zero to max step rate in one go. From what I understand, his question was how to fix that...
    +1 . But the OP does rather appear to have lost interest in the thread, with no answers to questions since page 1. If he really does need a step rate of 2 kHz and a speed "ramp" in one second, then the PICaxe instruction timings might be quite critical (probably ruling out interrupts).

    Cheers, Alan.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •