Pages: 1 2 [3]   Go Down
Author Topic: Nema 23 driver for 400 RPM  (Read 913 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Tesla Member
***
Karma: 124
Posts: 7158
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

then something like the following would work:

Code:
;Assembler Routine

;Set Up the PORT & Pin In Your ReSet Routine:
          sbi     DDRA, 0      ;Set the Direction = Output
          sbi     PORTA, 0     ;Pull Pin.0 High


PulseStep: ;Assuming 16Mhz, and 10uS pulse, 160 Clks Between cbi and sbi
          cbi    PORTA, 0      ;1 (The Instruction takes 2 clocks, but the Pin
                               ;     goes low @ ~1 Clk)
          push   r16           ;3 Clks or 4 Clks PC = 16 bit // PC = 22 bit
          ldi    r16, 20       ;1 Clk
          ;--------------------------------
          ;                    5 or 6 Clks To Here
    PulseStepLoop:     
          nop                  ;1
          nop                  ;1
          nop                  ;1
          dec    r16           ;1
          breq   PulseStepDone ;1 or 2 if True
          jmp    PulseStepLoop ;3
          ;--------------------------------
          ;                     8 Clks Per Iteration * 18 Iterations = 144 Clcks
          ;
    PulseStepDone    ;          144 Clks + 6 Clocks For Final Iteration = 150 Clks
                     ;          150 Clks + 5 Clks = 155 Clks To Here
                     ;          OR
                     ;          150 Clks + 6 Clks = 156 Clks To Here if the PC = 22 bit
                     ;           
          pop    r16           ;2
          nop                  ;1 **Remove if PC = 22 bit
          nop                  ;1
          sbi    PORTA, 0      ;1 (The Instruction takes 2 clocks, but the Pin
                               ;     goes High @ ~1 Clk)
          ;--------------------------------
          ;                   5 Clks (or 4 Clks if PC = 22 bit)
          ;                 155 Clks + 5 Clks = 160 Clks
          ;                 156 Clks + 4 Clks = 160 Clks   
     ret  ;Or Reti if steps are executed using an ISR         



In my experience this code works perfectly well and is a lot less trouble to write and to debug

Code:
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);

...R
Logged

Pages: 1 2 [3]   Go Up
Jump to: