TODOPIC

Mecatrónica => CNC - Control Numérico Computarizado => Mensaje iniciado por: todopic en 13 de Noviembre de 2007, 20:58:57

Título: Control de motores PAP por micro pasos
Publicado por: todopic en 13 de Noviembre de 2007, 20:58:57
(http://www.piclist.org/images/member/RB-ezy-Q33/circuit.jpg)

(http://www.romanblack.com/lini00.jpg)

el programa de control de micropasos


descargar http://www.piclist.org/techref/io/stepper/linistep/lini_asm.txt (http://www.piclist.org/techref/io/stepper/linistep/lini_asm.txt)

pcb
(http://www.piclist.org/images/member/RB-ezy-Q33/board.jpg)

(http://www.piclist.org/images/member/RB-ezy-Q33/CURREN0S.jpg)

visiten la pagina de su diseñador ---> http://www.romanblack.com/lini.htm (http://www.romanblack.com/lini.htm)


Norberto :mrgreen:
Título: Re: Control de motores PAP por micro pasos
Publicado por: ESTECA55 en 13 de Noviembre de 2007, 21:24:56
Excelente aporte Norberto!!

Yo tengo en desarrollo una controladora bipolar con micropasos, pero por razones de tiempo no e podido terminarla.

Lo que no entendí del circuito este es como censa la corriente para hacer los micropasos.

Saludos!
Título: Re: Control de motores PAP por micro pasos
Publicado por: marmatar en 19 de Noviembre de 2007, 10:58:49
Hola Norberto...
Si mal no recuerdo éste circuito lo habíamos analizado en el primer tema de la fresadora 3d, y no prosperó por algo aunque no recuerdo porqué... quizás por falta de experiencia y conocimiento fué dejado de lado.

A ver si ahora se le puede sacar el jugo.

Estaré atento...

Un abrazo

marmatar
Título: Re: Control de motores PAP por micro pasos
Publicado por: todopic en 10 de Abril de 2014, 07:56:07
Código: ASM
  1. ; ******************************************************************************
  2. ;
  3. ;  LiniStepper v1
  4. ;
  5. ;  PIC 16F84 / 16F628 code
  6. ;
  7. ;  Copyright Aug 2002 Roman Black   http://www.romanblack.com
  8. ;
  9. ;  PIC assembler code for the LiniStepper stepper motor driver board.
  10. ;  200/400/1200/3600 steps
  11. ;
  12. ;  v1.0 Seems to be working ok for now, few minor things need improving;
  13. ;               * touch up phase switching for direction -> 0
  14. ;               * table system is messy, can reduce in size a LOT if needed
  15. ;               * low-power mode doesn't microstep, only halfstep
  16. ;               * no easy way to step motor from within PIC softweare
  17. ;
  18. ;  (set mplab TABS to 5 for best viewing this .asm file)
  19. ;******************************************************************************
  20.  
  21.  
  22. ;==============================================================================
  23. ; mplab settings
  24.  
  25.         ERRORLEVEL -224         ; suppress annoying message because of option/tris
  26.         ERRORLEVEL -302         ; suppress message because of bank select in setup ports
  27.  
  28.         LIST b=5, n=97, t=ON, st=OFF            ;
  29.         ; absolute listing tabs=5, lines=97, trim long lines=ON, symbol table=OFF
  30.  
  31. ;==============================================================================
  32. ; processor defined
  33.  
  34.         ;include <p16f84A.inc>
  35.         include <p16f628.inc>
  36.  
  37. ; processor config
  38.  
  39.         IFDEF __16F84A
  40.                 __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
  41.         ENDIF
  42.         IFDEF __16F628
  43.                 __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC & _MCLRE_ON & _BODEN_OFF & _LVP_OFF
  44.         ENDIF
  45.  
  46.  
  47. ;==============================================================================
  48. ; Variables here
  49.  
  50.         ;-------------------------------------------------
  51.         IFDEF __16F84A
  52.                 #define RAM_START       0x0C
  53.                 #define RAM_END RAM_START+d'68'                 ; 16F84 has only 68 ram
  54.         ENDIF
  55.         IFDEF __16F628
  56.                 #define RAM_START       0x20   
  57.                 #define RAM_END RAM_START+d'96'                 ; F628 has 96 ram
  58.         ENDIF
  59.         ;-------------------------------------------------
  60.         CBLOCK  RAM_START
  61.  
  62.                 status_temp             ; used for int servicing
  63.                 w_temp                  ; used for int servicing
  64.  
  65.                 step                            ; (0-71) ustep position!
  66.                 steptemp                        ; for calcs
  67.  
  68.                 phase                   ; stores the 4 motor phase pins 0000xxxx
  69.                 current1                        ; for current tween pwm
  70.                 current2                        ; for current tween pwm
  71.  
  72.                 inputs                  ; stores new input pins
  73.                 inputs_last             ; stores last states of input pins
  74.  
  75.         ENDC
  76.  
  77.         ;-------------------------------------------------
  78.         ; PIC input pins for porta
  79.  
  80.         #define         STEP                    0               ; / = move 1 step, \=do nothing
  81.         #define         DIR                     1               ; lo= cw,  hi=ccw
  82.         #define         POWER           2               ; lo=low power, hi=full power
  83.  
  84.         ;-------------------------------------------------
  85.         ; Custom instructions!
  86.  
  87.         #define skpwne          skpnz                   ; after subxx, uses zero
  88.         #define skpweq          skpz                            ; after subxx, uses zero
  89.         #define skpwle          skpc                            ; after subxx, uses carry
  90.         #define skpwgt          skpnc                   ; after subxx, uses carry
  91.  
  92. ;==============================================================================
  93. ; CODE GOES HERE
  94.  
  95.         org 0x0000                      ; Set program memory base at reset vector 0x00
  96. reset
  97.         goto main                               ;
  98.  
  99.  
  100.  
  101. ;==============================================================================
  102. ; INTERRUPT vector here
  103.         org 0x0004                      ; interrupt routine must start here
  104. int_routine
  105.  
  106.         ;-------------------------------------------------
  107.                                                 ; first we preserve w and status register
  108.  
  109.         movwf w_temp                    ; save off current W register contents
  110.         movf    STATUS,w                ; move status register into W register
  111.         movwf status_temp               ; save off contents of STATUS register
  112.         ;-------------------------------------------------
  113.                                                 ; we get here every 256 timer0 ticks  3900Hz
  114.                                                 ; int body code here if you want
  115.  
  116.         ;-------------------------------------------------
  117.                                                 ; finally we restore w and status registers and
  118.                                                 ; clear TMRO int flag now we are finished.
  119. int_exit
  120.         bcf INTCON,T0IF         ; reset the tmr0 interrupt flag
  121.         movf status_temp,w      ; retrieve copy of STATUS register
  122.         movwf STATUS                    ; restore pre-isr STATUS register contents
  123.         swapf w_temp,f
  124.         swapf w_temp,w                  ; restore pre-isr W register contents
  125.         retfie                          ; return from interrupt
  126.         ;-------------------------------------------------
  127.  
  128. ;==============================================================================
  129.  
  130.  
  131.  
  132.  
  133. ;******************************************************************************
  134. ; MOVE MOTOR              sets 8 portb output pins to control motor
  135. ;******************************************************************************
  136. ; NOTE!! var step is used for sequencing the 0-71 steps
  137. ; uses tables! so keep it first in the code and set PCLATH to page 0
  138.  
  139. ;------------------
  140. move_motor                              ; goto label
  141. ;------------------
  142.  
  143.         ;-------------------------------------------------
  144.         ; this code controls the phase sequencing and current
  145.         ; settings for the motor.
  146.  
  147.         ; there are always 72 steps (0-71)
  148.  
  149.         ; we can split the main table into 2 halves, each have identical
  150.         ; current sequencing. That is only 12 entries for hardware current.
  151.  
  152.         ; Then can x3 the table to get 36 table entries which cover all 72 steps.
  153.         ; the 36 entries jump to 36 code pieces, which set the current values
  154.         ; for the 2 possible tween steps... We need 2 current values, one
  155.         ; for the x2 value and one for the x1 value.
  156.         ;-------------------------------------------------
  157.         ; PHASE SEQUENCING (switch the 4 coils)
  158.  
  159.         ; there are 4 possible combinations for the phase switching:
  160.         ; each have 18 steps, total 72 steps:
  161.  
  162.         ;       A+ B+   range 0         step 0-17
  163.         ;       A- B+   range 1         18-35
  164.         ;       A- B-   range 2         36-53
  165.         ;       A+ B-   range 3         54-71
  166.  
  167.         ;-------------------------------------------------
  168.                                                 ; find which of the 4 ranges we are in
  169.         movf step,w                     ; get step
  170.         movwf steptemp                  ; store as working temp
  171.  
  172.         movf steptemp,w         ;
  173.         sublw d'35'                     ; sub to test
  174.         skpwle                          ;
  175.         goto half_hi                    ; wgt, steptemp is 36-71 (upper half)
  176.  
  177.         ;-------------------------
  178. half_low                                        ; wle, steptemp is 0-35
  179.  
  180.         movf steptemp,w         ;
  181.         sublw d'17'                     ; sub to test
  182.         skpwle                          ;
  183.         goto range1                     ; wgt
  184.        
  185. range0                                  ; wle
  186.         movlw b'00000101'               ; 0101 = A+ B+
  187.         goto phase_done         ;
  188.  
  189. range1
  190.         movlw b'00001001'               ; 1001 = A- B+
  191.         goto phase_done         ;
  192.  
  193.         ;-------------------------
  194. half_hi                                 ; steptemp is 36-71
  195.                                                 ; NOTE! must subtract 36 from steptemp, so it
  196.                                                 ; will become 0-35 and ok with table later!
  197.         movlw d'36'                     ; subtract 36 from steptemp,
  198.         subwf steptemp,f                ; (now steptemp is 0-35)
  199.  
  200.                                                 ; now find the range
  201.         movf steptemp,w         ;
  202.         sublw d'17'                     ; sub to test
  203.         skpwle                          ;
  204.         goto range3                     ; wgt
  205.        
  206. range2                                  ; wle
  207.         movlw b'00001010'               ; 1010 = A- B-
  208.         goto phase_done         ;
  209.  
  210. range3
  211.         movlw b'00000110'               ; 0110 = A+ B-
  212.  
  213. phase_done                              ; note! steptemp is always 0-35 by here
  214.         movwf phase                     ; store phase values
  215.  
  216.         ;-------------------------------------------------
  217.         ; at this point we have the phasing done and stored as the last
  218.         ; 4 bits in var phase; 0000xxxx
  219.        
  220.         ; now we have 36 possible current combinations, which we can do
  221.         ; by separate code fragments, from a jump table.
  222.  
  223.         ; as we have 2 power modes; full and low power, we
  224.         ; need 2 tables.
  225.  
  226.         ;-------------------------------------------------
  227.  
  228.         btfss inputs,POWER              ; select table to use
  229.         goto table_lowpower             ;
  230.  
  231.         ;-------------------------------------------------
  232.         ; HIGH POWER TABLE
  233.         ;-------------------------------------------------
  234.  
  235. table_highpower                 ;
  236.  
  237.         movf steptemp,w         ; add steptemp to the PCL
  238.         addwf PCL,f                     ;
  239.                                                 ; here are the 36 possible values;
  240.         ;-------------------------
  241.         goto st00                               ; * (hardware 6th steps)
  242.         goto st01                               ;   (pwm tween steps)
  243.         goto st02                               ;   (pwm tween steps)
  244.         goto st03                               ; *
  245.         goto st04                               ;
  246.         goto st05                               ;
  247.  
  248.         goto st06                               ; *
  249.         goto st07                               ;
  250.         goto st08                               ;
  251.         goto st09                               ; *
  252.         goto st10                               ;
  253.         goto st11                               ;
  254.  
  255.         goto st12                               ; *
  256.         goto st13                               ;
  257.         goto st14                               ;
  258.         goto st15                               ; *
  259.         goto st16                               ;
  260.         goto st17                               ;
  261.  
  262.         goto st18                               ; *
  263.         goto st19                               ;
  264.         goto st20                               ;
  265.         goto st21                               ; *
  266.         goto st22                               ;
  267.         goto st23                               ;
  268.  
  269.         goto st24                               ; *
  270.         goto st25                               ;
  271.         goto st26                               ;
  272.         goto st27                               ; *
  273.         goto st28                               ;
  274.         goto st29                               ;
  275.  
  276.         goto st30                               ; *
  277.         goto st31                               ;
  278.         goto st32                               ;
  279.         goto st33                               ; *
  280.         goto st34                               ;
  281.         goto st35                               ;
  282.  
  283.         ;-------------------------------------------------
  284.         ; LOW POWER TABLE
  285.         ;-------------------------------------------------
  286.         ; as low power mode is for wait periods we don't need to
  287.         ; maintain the full step precision and can wait on the
  288.         ; half-step (400 steps/rev). This means much easier code tables.
  289.         ; The nature of the board electronics is not really suited
  290.         ; for LOW power microstepping, but it could be programmed here
  291.         ; if needed.
  292.  
  293.         ; NOTE!! uses my hi-torque half stepping, not normal half step.
  294.  
  295.         ;  doing half stepping with the 55,25 current values gives;
  296.         ; 55+25 = 80
  297.         ; max current 100+100 = 200
  298.         ; typical (high) current 100+50 = 150
  299.         ; so low power is about 1/2 the current of high power mode,
  300.         ; giving about 1/4 the motor heating and half the driver heating.
  301.  
  302.         ; for now it uses only half-steps or 8 separate current modes.
  303.         ; we only have to use 4 actual current modes as
  304.         ; the table is doubled like the table_highpower is.
  305.  
  306.         ; NOTE!! I have left the table full sized so it can be modified
  307.         ; to 1200 or 3600 steps if needed.
  308.         ;-------------------------------------------------
  309.  
  310. table_lowpower                          ;
  311.  
  312.         movf steptemp,w         ; add steptemp to the PCL
  313.         addwf PCL,f                     ;
  314.                                                 ; here are the 36 possible values;
  315.         ;-------------------------
  316.                                                 ; A+ B+ (A- B-)
  317.  
  318.         goto lp00                               ;
  319.         goto lp00                               ;
  320.         goto lp00                               ;
  321.         goto lp00                               ;
  322.         goto lp00                               ;       55,25 (100,45) current low (high)
  323.         goto lp00                               ;
  324.         goto lp00                               ;
  325.         goto lp00                               ;
  326.         goto lp00                               ;
  327.  
  328.         goto lp09                               ;
  329.         goto lp09                               ;
  330.         goto lp09                               ;
  331.         goto lp09                               ;
  332.         goto lp09                               ;       25,55 (45,100)
  333.         goto lp09                               ;
  334.         goto lp09                               ;
  335.         goto lp09                               ;
  336.         goto lp09                               ;
  337.  
  338.         ;-------------------------
  339.                                                 ; A- B+ (A+ B-)
  340.  
  341.         goto lp18                               ;
  342.         goto lp18                               ;
  343.         goto lp18                               ;
  344.         goto lp18                               ;
  345.         goto lp18                               ;       25,55 (45,100)
  346.         goto lp18                               ;
  347.         goto lp18                               ;
  348.         goto lp18                               ;
  349.         goto lp18                               ;
  350.  
  351.         goto lp27                               ;
  352.         goto lp27                               ;
  353.         goto lp27                               ;
  354.         goto lp27                               ;
  355.         goto lp27                               ;       55,25 (100,45)
  356.         goto lp27                               ;
  357.         goto lp27                               ;
  358.         goto lp27                               ;
  359.         goto lp27                               ;
  360.  
  361.         ;-------------------------------------------------
  362.         ; all tables done, no more tables after this point!
  363.         ;-------------------------------------------------
  364.         ; next are the 36 code fragments for the high power table.
  365.  
  366.         ; CURRENT INFO.
  367.         ; hardware requires that we send the entire 8 bits to the motor
  368.         ; at one time, to keep pwm fast.
  369.  
  370.         ; ----xxxx,  where xxxx is the coils on/off phasing (done)
  371.         ; xxxx----,  where xxxx is the current settings for the A and B phases;
  372.         ; xx------,  where xx is current for A phase
  373.         ; --xx----,  where xx is current for B phase
  374.  
  375.         ; hardware currents for 6th stepping have 4 possible values;
  376.         ; 00  =  0% current
  377.         ; 01  =  25% current
  378.         ; 10  =  55% current
  379.         ; 11  =  100% current
  380.  
  381.         ;-------------------------------------------------
  382.         ; PWM INFO.
  383.         ; hardware gives us 6th steps, or 1200 steps/rev.
  384.         ; to get 3600 steps/rev we need TWO more
  385.         ; "tween" steps between every proper hardware 6th step.
  386.  
  387.         ; to do this we set 2 currents, current1 and current2.
  388.         ; then we do FAST pwm, with 2 time units at current2,
  389.         ; and 1 time unit at current1.
  390.         ; this gives a current which is between the two currents,
  391.         ; proportionally closer to current2. (2/3 obviously)
  392.         ; this gives the ability to get 2 evenly spaced "tween" currents
  393.         ; between our hardware 6th step currents, and go from 1200 to 3600.
  394.  
  395.         ; the next 36 code fragments set the 2 currents desired, then
  396.         ; we goto a fast-pwm loop (same loop used for all currents)
  397.         ; which modulates between the 2 currents and gives final
  398.         ; output current.
  399.         ;-------------------------------------------------
  400.  
  401. st00                                            ; (6th step)
  402.         movf phase,w                    ; get coil phasing (is 0000xxxx)
  403.         iorlw b'11000000'               ; set currents; 100,0
  404.         movwf current2                  ;
  405.         movwf current1                  ;
  406.         goto pwm                                ;
  407.  
  408. st01                                            ; (tween step)
  409.         movf phase,w                    ; get coil phasing
  410.         iorlw b'11000000'               ; set 100,0
  411.         movwf current2                  ;
  412.         movf phase,w                    ;
  413.         iorlw b'11010000'               ; set 100,25
  414.         movwf current1                  ;
  415.         goto pwm                                ;
  416.  
  417. st02                                            ; (tween step)
  418.         movf phase,w                    ; get coil phasing
  419.         iorlw b'11010000'               ; set 100,25
  420.         movwf current2                  ;
  421.         movf phase,w                    ;
  422.         iorlw b'11000000'               ; set 100,0
  423.         movwf current1                  ;
  424.         goto pwm                                ;
  425.  
  426.         ;-------------------------
  427.  
  428. st03                                            ; (6th step)
  429.         movf phase,w                    ;
  430.         iorlw b'11010000'               ; set 100,25
  431.         movwf current2                  ;
  432.         movwf current1                  ;
  433.         goto pwm                                ;
  434.  
  435. st04                                            ;
  436.         movf phase,w                    ;
  437.         iorlw b'11010000'               ; set 100,25
  438.         movwf current2                  ;
  439.         movf phase,w                    ;
  440.         iorlw b'11100000'               ; set 100,55
  441.         movwf current1                  ;
  442.         goto pwm                                ;
  443.  
  444. st05                                            ;
  445.         movf phase,w                    ;
  446.         iorlw b'11100000'               ; set 100,55
  447.         movwf current2                  ;
  448.         movf phase,w                    ;
  449.         iorlw b'11010000'               ; set 100,25
  450.         movwf current1                  ;
  451.         goto pwm                                ;
  452.  
  453.         ;-------------------------
  454.  
  455. st06                                            ; (6th step)
  456.         movf phase,w                    ;
  457.         iorlw b'11100000'               ; set 100,55
  458.         movwf current2                  ;
  459.         movwf current1                  ;
  460.         goto pwm                                ;
  461.  
  462. st07                                            ;
  463.         movf phase,w                    ;
  464.         iorlw b'11100000'               ; set 100,55
  465.         movwf current2                  ;
  466.         movf phase,w                    ;
  467.         iorlw b'11110000'               ; set 100,100
  468.         movwf current1                  ;
  469.         goto pwm                                ;
  470.  
  471. st08                                            ;
  472.         movf phase,w                    ;
  473.         iorlw b'11110000'               ; set 100,100
  474.         movwf current2                  ;
  475.         movf phase,w                    ;
  476.         iorlw b'11100000'               ; set 100,55
  477.         movwf current1                  ;
  478.         goto pwm                                ;
  479.  
  480.         ;-------------------------
  481.  
  482. st09                                            ; (6th step)
  483.         movf phase,w                    ;
  484.         iorlw b'11110000'               ; set 100,100
  485.         movwf current2                  ;
  486.         movwf current1                  ;
  487.         goto pwm                                ;
  488.  
  489. st10                                            ;
  490.         movf phase,w                    ;
  491.         iorlw b'11110000'               ; set 100,100
  492.         movwf current2                  ;
  493.         movf phase,w                    ;
  494.         iorlw b'10110000'               ; set 55,100
  495.         movwf current1                  ;
  496.         goto pwm                                ;
  497.  
  498. st11                                            ;
  499.         movf phase,w                    ;
  500.         iorlw b'10110000'               ; set 55,100
  501.         movwf current2                  ;
  502.         movf phase,w                    ;
  503.         iorlw b'11110000'               ; set 100,100
  504.         movwf current1                  ;
  505.         goto pwm                                ;
  506.  
  507.         ;-------------------------
  508.  
  509. st12                                            ; (6th step)
  510.         movf phase,w                    ;
  511.         iorlw b'10110000'               ; set 55,100
  512.         movwf current2                  ;
  513.         movwf current1                  ;
  514.         goto pwm                                ;
  515.  
  516. st13                                            ;
  517.         movf phase,w                    ;
  518.         iorlw b'10110000'               ; set 55,100
  519.         movwf current2                  ;
  520.         movf phase,w                    ;
  521.         iorlw b'01110000'               ; set 25,100
  522.         movwf current1                  ;
  523.         goto pwm                                ;
  524.  
  525. st14                                            ;
  526.         movf phase,w                    ;
  527.         iorlw b'01110000'               ; set 25,100
  528.         movwf current2                  ;
  529.         movf phase,w                    ;
  530.         iorlw b'10110000'               ; set 55,100
  531.         movwf current1                  ;
  532.         goto pwm                                ;
  533.  
  534.         ;-------------------------
  535. st15                                            ; (6th step)
  536.         movf phase,w                    ;
  537.         iorlw b'01110000'               ; set 25,100
  538.         movwf current2                  ;
  539.         movwf current1                  ;
  540.         goto pwm                                ;
  541.  
  542. st16                                            ;
  543.         movf phase,w                    ;
  544.         iorlw b'01110000'               ; set 25,100
  545.         movwf current2                  ;
  546.         movf phase,w                    ;
  547.         iorlw b'00110000'               ; set 0,100
  548.         movwf current1                  ;
  549.         goto pwm                                ;
  550.  
  551. st17                                            ;
  552.         movf phase,w                    ;
  553.         iorlw b'00110000'               ; set 0,100
  554.         movwf current2                  ;
  555.         movf phase,w                    ;
  556.         iorlw b'01110000'               ; set 25,100
  557.         movwf current1                  ;
  558.         goto pwm                                ;
  559.  
  560.         ;-------------------------
  561.         ;-------------------------
  562.  
  563. st18                                            ; (6th step)
  564.         movf phase,w                    ;
  565.         iorlw b'00110000'               ; set 0,100
  566.         movwf current2                  ;
  567.         movwf current1                  ;
  568.         goto pwm                                ;
  569.  
  570. st19                                            ;
  571.         movf phase,w                    ;
  572.         iorlw b'00110000'               ; set 0,100
  573.         movwf current2                  ;
  574.         movf phase,w                    ;
  575.         iorlw b'01110000'               ; set 25,100
  576.         movwf current1                  ;
  577.         goto pwm                                ;
  578.  
  579. st20                                            ;
  580.         movf phase,w                    ;
  581.         iorlw b'01110000'               ; set 25,100
  582.         movwf current2                  ;
  583.         movf phase,w                    ;
  584.         iorlw b'00110000'               ; set 0,100
  585.         movwf current1                  ;
  586.         goto pwm                                ;
  587.  
  588.         ;-------------------------
  589.  
  590. st21                                            ; (6th step)
  591.         movf phase,w                    ;
  592.         iorlw b'01110000'               ; set 25,100
  593.         movwf current2                  ;
  594.         movwf current1                  ;
  595.         goto pwm                                ;
  596.  
  597. st22                                            ;
  598.         movf phase,w                    ;
  599.         iorlw b'01110000'               ; set 25,100
  600.         movwf current2                  ;
  601.         movf phase,w                    ;
  602.         iorlw b'10110000'               ; set 55,100
  603.         movwf current1                  ;
  604.         goto pwm                                ;
  605.  
  606. st23                                            ;
  607.         movf phase,w                    ;
  608.         iorlw b'10110000'               ; set 55,100
  609.         movwf current2                  ;
  610.         movf phase,w                    ;
  611.         iorlw b'01110000'               ; set 25,100
  612.         movwf current1                  ;
  613.         goto pwm                                ;
  614.  
  615.         ;-------------------------
  616.  
  617. st24                                            ; (6th step)
  618.         movf phase,w                    ;
  619.         iorlw b'10110000'               ; set 55,100
  620.         movwf current2                  ;
  621.         movwf current1                  ;
  622.         goto pwm                                ;
  623.  
  624. st25                                            ;
  625.         movf phase,w                    ;
  626.         iorlw b'10110000'               ; set 55,100
  627.         movwf current2                  ;
  628.         movf phase,w                    ;
  629.         iorlw b'11110000'               ; set 100,100
  630.         movwf current1                  ;
  631.         goto pwm                                ;
  632.  
  633. st26                                            ;
  634.         movf phase,w                    ;
  635.         iorlw b'11110000'               ; set 100,100
  636.         movwf current2                  ;
  637.         movf phase,w                    ;
  638.         iorlw b'10110000'               ; set 55,100
  639.         movwf current1                  ;
  640.         goto pwm                                ;
  641.  
  642.         ;-------------------------
  643.  
  644. st27                                            ; (6th step)
  645.         movf phase,w                    ;
  646.         iorlw b'11110000'               ; set 100,100
  647.         movwf current2                  ;
  648.         movwf current1                  ;
  649.         goto pwm                                ;
  650.  
  651. st28                                            ;
  652.         movf phase,w                    ;
  653.         iorlw b'11110000'               ; set 100,100
  654.         movwf current2                  ;
  655.         movf phase,w                    ;
  656.         iorlw b'11100000'               ; set 100,55
  657.         movwf current1                  ;
  658.         goto pwm                                ;
  659.  
  660. st29                                            ;
  661.         movf phase,w                    ;
  662.         iorlw b'11100000'               ; set 100,55
  663.         movwf current2                  ;
  664.         movf phase,w                    ;
  665.         iorlw b'11110000'               ; set 100,100
  666.         movwf current1                  ;
  667.         goto pwm                                ;
  668.  
  669.         ;-------------------------
  670.  
  671. st30                                            ; (6th step)
  672.         movf phase,w                    ;
  673.         iorlw b'11100000'               ; set 100,55
  674.         movwf current2                  ;
  675.         movwf current1                  ;
  676.         goto pwm                                ;
  677.  
  678. st31                                            ;
  679.         movf phase,w                    ;
  680.         iorlw b'11100000'               ; set 100,55
  681.         movwf current2                  ;
  682.         movf phase,w                    ;
  683.         iorlw b'11010000'               ; set 100,25
  684.         movwf current1                  ;
  685.         goto pwm                                ;
  686.  
  687. st32                                            ;
  688.         movf phase,w                    ;
  689.         iorlw b'11010000'               ; set 100,25
  690.         movwf current2                  ;
  691.         movf phase,w                    ;
  692.         iorlw b'11100000'               ; set 100,55
  693.         movwf current1                  ;
  694.         goto pwm                                ;
  695.  
  696.         ;-------------------------
  697.  
  698. st33                                            ; (6th step)
  699.         movf phase,w                    ;
  700.         iorlw b'11010000'               ; set 100,25
  701.         movwf current2                  ;
  702.         movwf current1                  ;
  703.         goto pwm                                ;
  704.  
  705. st34                                            ;
  706.         movf phase,w                    ;
  707.         iorlw b'11010000'               ; set 100,25
  708.         movwf current2                  ;
  709.         movf phase,w                    ;
  710.         iorlw b'11000000'               ; set 100,0
  711.         movwf current1                  ;
  712.         goto pwm                                ;
  713.  
  714. st35                                            ;
  715.         movf phase,w                    ;
  716.         iorlw b'11000000'               ; set 100,0
  717.         movwf current2                  ;
  718.         movf phase,w                    ;
  719.         iorlw b'11010000'               ; set 100,25
  720.         movwf current1                  ;
  721.         goto pwm                                ;
  722.                                                 ; high power table done!
  723.  
  724.  
  725.         ;-------------------------------------------------
  726.         ; next are the 4 code fragments for the low power table.
  727.         ; (no PWM is used)
  728.         ;-------------------------------------------------
  729.  
  730. lp00                                            ;
  731.         movf phase,w                    ;
  732.         iorlw b'10010000'               ; set 55,25
  733.         movwf current2                  ;
  734.         movwf current1                  ;
  735.         goto pwm                                ;
  736.  
  737. lp09                                            ;
  738.         movf phase,w                    ;
  739.         iorlw b'01100000'               ; set 25,55
  740.         movwf current2                  ;
  741.         movwf current1                  ;
  742.         goto pwm                                ;
  743.  
  744. lp18                                            ;
  745.         movf phase,w                    ;
  746.         iorlw b'01100000'               ; set 25,55
  747.         movwf current2                  ;
  748.         movwf current1                  ;
  749.         goto pwm                                ;
  750.  
  751. lp27                                            ;
  752.         movf phase,w                    ;
  753.         iorlw b'10010000'               ; set 55,25
  754.         movwf current2                  ;
  755.         movwf current1                  ;
  756.         goto pwm                                ;
  757.  
  758.         ;-------------------------------------------------
  759.  
  760.  
  761. ;------------------------------------------------------------------------------
  762.  
  763.  
  764.  
  765.  
  766. ;******************************************************************************
  767. ;  Main
  768. ;******************************************************************************
  769. ;
  770. ;------------------
  771. main                                            ; goto label
  772. ;------------------
  773.  
  774.         ;---------------------------------------------
  775.                                                 ; do initial setup for ports and ints and stuff
  776.         call setup                      ; this is our only proper call...
  777.                                                 ; it is called only once, and does not really need
  778.                                                 ; to be a function.
  779.         ;---------------------------------------------
  780.         ; main operating loop is here.
  781.         ;---------------------------------------------
  782.  
  783.         goto move_motor         ; will set the motor to step 0,
  784.                                                 ; and loop permanently from there
  785.  
  786.         ;---------------------------------------------
  787.         goto main                               ; safe loop, should never get here anyway.
  788.  
  789. ;==============================================================================
  790.  
  791.  
  792.  
  793.  
  794. ;******************************************************************************
  795. ; NEW INPUTS   input change was detected
  796. ;******************************************************************************
  797. ;
  798. ;------------------
  799. new_inputs                              ; goto tag
  800. ;------------------
  801.  
  802.         ;-------------------------------------------------
  803.         ; when we enter here:
  804.         ; * one or more PORTA inputs have just changed
  805.         ; * inputs_last contains last PORTA inputs values
  806.         ; * inputs              contains new PORTA inputs values
  807.         ;-------------------------------------------------
  808.         ; must first detect which input pins changed.
  809.  
  810.         ; ---x----      RA4     * mode bit1        ( 00=200 step        01=400 step
  811.         ; ----x---      RA3     * mode bit0             10=1200 step    11=3600 step )
  812.         ; -----x--      RA2     * power
  813.         ; ------x-      RA1     * direction
  814.         ; -------x      RA0     * step
  815.  
  816.         ; if step went hi, we move the step (step++ or step--)
  817.  
  818.         ; if step went low, ignore
  819.         ; ignore change in direction pin
  820.         ; ignore change in power pin
  821.         ; ignore change in mode pins
  822.         ; (all pins besides step are handled automatically in move_motor)
  823.         ;-------------------------------------------------
  824.  
  825.         movf inputs,w                   ; xor to compare new inputs with last values
  826.         xorwf inputs_last,f             ; now inputs_last has the diff.
  827.  
  828.         btfss inputs_last,STEP  ; test if step input changed
  829.         goto ni_end                     ;
  830.  
  831.                                                 ; step input changed!
  832.         btfss inputs,STEP               ; test if change was lo-hi or hi-lo
  833.         goto ni_end                     ; hi-lo, so ignore
  834.  
  835.         ;-------------------------------------------------
  836.         ; step input changed lo-hi!
  837.         ; now must make a step forward or back, based
  838.         ; on the state of the dir pin.
  839.  
  840.         ; here it gets complex as we have 4 operating modes,
  841.         ; determined by the state of the 2 input pins RA4 and RA3;
  842.  
  843.         ; ---00---      200 steps
  844.         ; ---01---      400 steps
  845.         ; ---10---      1200 steps
  846.         ; ---11---      3600 steps
  847.  
  848.         ; there are 4 separate code systems to handle stepping
  849.         ; in the 4 modes;
  850.         ;-------------------------------------------------
  851.                                                 ; find which of the 4 modes we are in
  852.         btfss inputs,4                  ; test hi bit
  853.         goto mode_lo                    ;
  854.  
  855. mode_hi                                 ; must be 1200 or 3600
  856.  
  857.         btfss inputs,3                  ; test lo bit
  858.         goto mode_1200                  ;
  859.  
  860.         ;-------------------------------------------------
  861. mode_3600                                       ; 3600 mode (72/1)
  862.                                                 ; each step is 1
  863.  
  864.         btfss inputs,DIR                ; test direction input
  865.         goto m36_up                     ;
  866.  
  867. m36_down
  868.         decf step,f                     ; step--
  869.         btfss step,7                    ; test for roll under <0
  870.         goto ni_end                     ; ok
  871.                                                 ; rolled under!
  872.         movlw d'71'                     ; force to top step (72-1)
  873.         movwf step                      ;
  874.         goto ni_end                     ;
  875.  
  876. m36_up
  877.         incf step,f                     ; step++
  878.         movf step,w                     ; test for roll over >71
  879.         sublw d'71'                     ; sub to test
  880.         skpwle                          ;
  881.         clrf step                               ; wgt, rolled over so force to step 0
  882.  
  883.         goto ni_end                     ;
  884.         ;-------------------------------------------------
  885. mode_1200                                       ; 1200 mode (72/3)
  886.                                                 ; each step is mod 3 (0,3,6,9,12 - 66, 69 etc)
  887.  
  888.         btfss inputs,DIR                ; test direction input
  889.         goto m12_up                     ;
  890.  
  891. m12_down
  892.         movlw d'3'                      ; amount to subtract
  893.         subwf step,f                    ; step-=3
  894.         btfss step,7                    ; test for roll under <0
  895.         goto ni_end                     ; ok
  896.                                                 ; rolled under!
  897.         movlw d'69'                     ; force to top step (72-3)
  898.         movwf step                      ;
  899.         goto ni_end                     ;
  900.  
  901. m12_up
  902.         movlw d'3'                      ; amount to add
  903.         addwf step,f                    ; step+=3
  904.                                                 ;
  905.         movf step,w                     ; test for roll over >69
  906.         sublw d'69'                     ; sub to test
  907.         skpwle                          ;
  908.         clrf step                               ; wgt, rolled over so force to step 0
  909.  
  910.         goto ni_end                     ;
  911.         ;-------------------------------------------------
  912. mode_lo                                 ; must be 200 or 400
  913.         btfss inputs,3                  ; test lo bit
  914.         goto mode_200                   ;
  915.  
  916.         ;-------------------------------------------------
  917. mode_400                                        ; 400 mode (72/9)
  918.                                                 ; note! we do special half stepping here.
  919.                                                 ; there are ONLY 8 valid steps:
  920.                                                 ; 4, 13, 22, 31, 40, 49, 58, 67
  921.                                                 ; these steps give 100,45 and 35,100 combos, good
  922.                                                 ; enough for now. (should average 100,41)
  923.  
  924.         btfss inputs,DIR                ; test direction input
  925.         goto m4_up                      ;
  926.  
  927. m4_down
  928.         movlw d'9'                      ; amount to subtract
  929.         subwf step,f                    ; step-=9
  930.         btfss step,7                    ; test for roll under <0
  931.         goto ni_end                     ; ok
  932.                                                 ; rolled under!
  933.         movlw d'67'                     ; force to top (full) step
  934.         movwf step                      ;
  935.         goto ni_end                     ;
  936.  
  937. m4_up
  938.         movlw d'9'                      ; amount to add
  939.         addwf step,f                    ; step+=9
  940.                                                 ;
  941.         movf step,w                     ; test for roll over
  942.         sublw d'67'                     ; sub to test
  943.         skpwgt                          ;
  944.         goto ni_end                     ; wle, is ok
  945.  
  946.         movlw d'4'                      ; wgt, rolled over so force to bottom step 5
  947.         movwf step                      ;
  948.  
  949.         goto ni_end                     ;
  950.         ;-------------------------------------------------
  951. mode_200                                        ; 200 mode (72/18)
  952.                                                 ; NOTE!! this has special needs as we can't use
  953.                                                 ; step 0, we need to stay on the "2 steps on" steps.
  954.                                                 ; there are ONLY 4 valid steps;  9, 27, 45, 63
  955.  
  956.         btfss inputs,DIR                ; test direction input
  957.         goto m2_up                      ;
  958.  
  959. m2_down
  960.         movlw d'18'                     ; amount to subtract
  961.         subwf step,f                    ; step-=18
  962.         btfss step,7                    ; test for roll under <0
  963.         goto ni_end                     ; ok
  964.                                                 ; rolled under!
  965.         movlw d'63'                     ; force to top (full) step (72-(18/2))
  966.         movwf step                      ;
  967.         goto ni_end                     ;
  968.  
  969. m2_up
  970.         movlw d'18'                     ; amount to add
  971.         addwf step,f                    ; step+=18
  972.                                                 ;
  973.         movf step,w                     ; test for roll over
  974.         sublw d'63'                     ; sub to test
  975.         skpwgt                          ;
  976.         goto ni_end                     ; wle, is ok
  977.  
  978.         movlw d'9'                      ; wgt, rolled over so force to bottom step 9
  979.         movwf step                      ;
  980.  
  981.         goto ni_end                     ;
  982.  
  983.         ;-------------------------------------------------
  984. ni_end
  985.         movf inputs,w                   ; save a copy of the inputs
  986.         movwf inputs_last               ;
  987.  
  988.         goto move_motor         ; go and make it all happen
  989.  
  990. ;------------------------------------------------------------------------------
  991.  
  992.  
  993.  
  994.  
  995. ;******************************************************************************
  996. ; PWM           is the fast pwm loop
  997. ;******************************************************************************
  998. ; NOTE!! we enter the code in the middle of the loop!
  999.  
  1000.         ;-------------------------------------------------
  1001.         ; the 2 target currents were set in the move_motor code.
  1002.  
  1003.         ; what this function does is spend 2 time units at current2,
  1004.         ; and 1 time unit at current1.
  1005.         ; actual is 8 clocks at current2
  1006.         ; and 4 clocks at current 1
  1007.         ; total 12 cycles, so 333 kHz with 16MHz resonator.
  1008.  
  1009.         ; this gives an average pwm current of 2/3 the way between
  1010.         ; current2 and current1.
  1011.  
  1012.         ; the routine is kept short to keep pwm frequency high, so it
  1013.         ; is easy to smooth in hardware by the ramping caps.
  1014.  
  1015.         ; IMPORTANT! is timed by clock cycles, don't change this code!
  1016.         ; it also checks for any change in input pins here
  1017.  
  1018.         ; the 8/4 code seen here was supplied by Eric Bohlman (thanks!)
  1019.         ;-------------------------------------------------
  1020. pwm_loop
  1021.                                                 ; first output current1 to motor
  1022.         movf current1,w         ; get currents and phase switching
  1023.         movwf PORTB                     ; send to motor!
  1024.  
  1025.         nop                                     ; timing delay
  1026.         nop                                     ;
  1027.                                                 ; (4 cycles)
  1028.         ;-------------------------
  1029. pwm                                             ; main entry!
  1030.                                                 ; better to enter at current2 for motor power.
  1031.  
  1032.                                                 ; now output current2
  1033.         movf current2,w         ;
  1034.         movwf PORTB                     ; send to motor!
  1035.         nop                                     ; safe wait 250nS
  1036.  
  1037.                                                 ; now test input pins
  1038.         movf PORTA,w                    ; get pin values from port
  1039.  
  1040.         xorwf inputs_last,w             ; xor to compare new inputs with last values
  1041.         skpnz
  1042.         goto pwm_loop                   ; z, inputs not changed, so keep looping
  1043.                                                 ; (8 cycles)
  1044.         ;-------------------------------------------------
  1045.                                                 ; nz, one or more input pins have changed!
  1046.         xorwf inputs_last,w             ; restore xored value back to the orig inputs value
  1047.         movwf inputs                    ;
  1048.  
  1049.         goto new_inputs         ;
  1050.         ;-------------------------------------------------
  1051.  
  1052. ;------------------------------------------------------------------------------
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059. ;******************************************************************************
  1060. ;  SETUP   sets port directions and interrupt stuff etc,
  1061. ;******************************************************************************
  1062. ; NOTE!! is the only proper funtion, is done before other activity
  1063.  
  1064. ;------------------
  1065. setup                                   ; routine tag
  1066. ;------------------
  1067.  
  1068.         ;-------------------------------------------------
  1069.         ; Note! there are added bits for the 16F628!
  1070.         ; here we set up peripherals and port directions.
  1071.         ; this will need to be changed for different PICs.
  1072.         ;-------------------------------------------------
  1073.                                                 ; OPTION setup
  1074.         movlw b'10000010'               ;
  1075.                 ;  x-------             ; 7, 0=enable, 1=disable, portb pullups
  1076.                 ;  -x------             ; 6, 1=/, int edge select bit
  1077.                 ;  --x-----             ; 5, timer0 source, 0=internal clock, 1=ext pin.
  1078.                 ;  ---x----             ; 4, timer0 ext edge, 1=\
  1079.                 ;  ----x---             ; 3, prescaler assign, 1=wdt, 0=timer0
  1080.                 ;  -----x--             ; 2,1,0, timer0 prescaler rate select
  1081.                 ;  ------x-             ;   000=2, 001=4, 010=8, 011=16, etc.
  1082.                 ;  -------x             ;
  1083.                                                 ;
  1084.         banksel OPTION_REG              ; go proper reg bank
  1085.         movwf OPTION_REG                ; load data into OPTION_REG
  1086.         banksel 0                               ;
  1087.         ;-------------------------------------------------
  1088.         ; note! check for 16F628 and do extra setup for it.
  1089.  
  1090.         IFDEF  __16F628
  1091.                 banksel VRCON           ; do bank 1 stuff
  1092.                 clrf VRCON              ; disable Vref
  1093.                 clrf PIE1                       ; disable pi etc
  1094.                 banksel 0                       ;
  1095.  
  1096.                 clrf T1CON              ; disable timer1
  1097.                 clrf T2CON              ; disable timer2
  1098.                 clrf CCP1CON            ; disable CCP module
  1099.  
  1100.                 movlw b'00000111'       ; disable comparators
  1101.                 movwf CMCON             ;
  1102.         ENDIF
  1103.         ;-------------------------------------------------
  1104.                                                 ; PORTB pins direction setup
  1105.                                                 ; 1=input, 0=output
  1106.         clrf PORTB                      ;
  1107.                                                 ;
  1108.         movlw b'00000000'               ; all 8 portb are outputs
  1109.                                                 ;
  1110.         banksel TRISB                   ; go proper reg bank
  1111.         movwf TRISB                     ; send mask to portb
  1112.         banksel 0                               ;
  1113.         ;-------------------------------------------------
  1114.  
  1115.                                                 ; PORTA pins direction setup
  1116.                                                 ; 1=input, 0=output
  1117.         clrf PORTA                      ;
  1118.  
  1119.                                                 ; NOTE!! all 5 PORTA pins are inputs
  1120.         movlw b'00011111'               ;
  1121.                 ;  ---x----             ; RA4
  1122.                 ;  ----x---             ; RA3
  1123.                 ;  -----x--             ; RA2
  1124.                 ;  ------x-             ; RA1
  1125.                 ;  -------x             ; RA0
  1126.  
  1127.         banksel TRISA                   ; go proper reg bank
  1128.         movwf TRISA                     ; send mask to porta
  1129.         banksel 0                               ;
  1130.         ;-------------------------------------------------
  1131.  
  1132.         movlw 0x00                      ; set up PCLATH for all jump tables on page 0
  1133.         movwf PCLATH                    ; (all tables are in move_motor)
  1134.         ;-------------------------------------------------
  1135.  
  1136.                                                 ; CLEAR RAM! for lower bank
  1137.         movlw RAM_START         ; first byte of ram
  1138.         movwf FSR                               ; load pointer
  1139. ram_clear_loop
  1140.         clrf INDF                               ; clear the ram we pointed to
  1141.         incf FSR,f                      ; inc pointer to next ram byte
  1142.         movf FSR,w                      ; get copy of pointer to w
  1143.         sublw RAM_END                   ; test if PAST the last byte now
  1144.         skpweq                          ;
  1145.         goto ram_clear_loop             ;
  1146.  
  1147.         ;-------------------------------------------------
  1148.                                                 ; here we can set the user variables and output pins
  1149.  
  1150.         movlw 0x00                      ; for step 0 of 0-71
  1151.         movwf step                      ; loaded ready for jump table
  1152.  
  1153.         movf PORTA,w                    ; get initial value for inputs
  1154.         movwf inputs                    ;
  1155.         movwf inputs_last               ;
  1156.  
  1157.         ;-------------------------------------------------
  1158.                                                 ; set up INTCON register last
  1159.         movlw b'00000000'               ; set the bit value
  1160.  
  1161.                 ;  x-------             ; bit7  GIE global int enable, 1=enabled
  1162.                 ;  -x------             ; bit6  EE write complete enable, 1=en
  1163.                 ;  --x-----             ; bit5  TMR0 overflow int enable, 1=en
  1164.                 ;  ---x----             ; bit4  RB0/INT enable, 1=en
  1165.                 ;  ----x---             ; bit3  RB port change int enable, 1=en
  1166.                 ;  -----x--             ; bit2  TMR0 int flag bit, 1=did overflow and get int
  1167.                 ;  ------x-             ; bit1  RB0/INT flag bit, 1=did get int
  1168.                 ;  -------x             ; bit0  RB port int flag bit, 1=did get int
  1169.  
  1170.         movwf INTCON                    ; put in INTCON register
  1171.         ;-------------------------------------------------
  1172.         return                          ;
  1173. ;------------------------------------------------------------------------------
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179. ;==============================================================================
  1180.         ; this code is only to display 1k of the memory usage chart
  1181.         ; in the absolute listing!
  1182.  
  1183.         ; page 0 256 byte block--------------------
  1184.         ;org 0x40-2
  1185.         ;nop
  1186.         ;org 0x80-1
  1187.         ;nop
  1188.         ;org 0xC0-1
  1189.         ;nop
  1190.         ;org 0x100-1
  1191.         ;nop
  1192.  
  1193.         ; page 1 256 byte block--------------------
  1194.         ;org 0x140-2
  1195.         ;nop
  1196.         ;org 0x180-1
  1197.         ;nop
  1198.         ;org 0x1C0-1
  1199.         ;nop
  1200.         ;org 0x200-1
  1201.         ;nop
  1202.  
  1203.         ; page 2 256 byte block--------------------
  1204.         org 0x240-2
  1205.         nop
  1206.         org 0x280-1
  1207.         nop
  1208.         org 0x2C0-1
  1209.         nop
  1210.         org 0x300-1
  1211.         nop
  1212.  
  1213.         ; page 3 256 byte block--------------------
  1214.         org 0x340-2
  1215.         nop
  1216.         org 0x380-1
  1217.         nop
  1218.         org 0x3C0-1
  1219.         nop
  1220.         org 0x400-1
  1221.         nop
  1222.  
  1223.  
  1224.         IFDEF __16F628
  1225.                 ; page 4 256 byte block--------------------
  1226.                 org 0x440-2
  1227.                 nop
  1228.                 org 0x480-1
  1229.                 nop
  1230.                 org 0x4C0-1
  1231.                 nop
  1232.                 org 0x500-1
  1233.                 nop
  1234.  
  1235.                 ; page 5 256 byte block--------------------
  1236.                 org 0x540-2
  1237.                 nop
  1238.                 org 0x580-1
  1239.                 nop
  1240.                 org 0x5C0-1
  1241.                 nop
  1242.                 org 0x600-1
  1243.                 nop
  1244.  
  1245.                 ; page 6 256 byte block--------------------
  1246.                 org 0x640-2
  1247.                 nop
  1248.                 org 0x680-1
  1249.                 nop
  1250.                 org 0x6C0-1
  1251.                 nop
  1252.                 org 0x700-1
  1253.                 nop
  1254.  
  1255.                 ; page 7 256 byte block--------------------
  1256.                 org 0x740-2
  1257.                 nop
  1258.                 org 0x780-1
  1259.                 nop
  1260.                 org 0x7C0-1
  1261.                 nop
  1262.                 org 0x800-1
  1263.                 nop
  1264.         ENDIF
  1265.  
  1266.         ;-------------------------------------------------------------------------
  1267.         end
  1268.         ;-------------------------------------------------------------------------
  1269.  
  1270. ;==============================================================================
  1271. ;==============================================================================
  1272. ;==============================================================================
  1273.  
  1274.  
  1275.  
  1276.         ;-------------------------------------------------
  1277.         ; NOTE!! example! below is the original (non-pwm) table for the
  1278.         ; 24x hardware 6th steps.
  1279.         ; this will be useful to code a minimum-rom microstepper
  1280.         ; if you don't need 3600 and can make do with 1200 steps.
  1281.  
  1282.         ; same system as the main code;
  1283.         ; ----xxxx      are the phase sequencing
  1284.         ; xxxx----      are the current values
  1285.  
  1286.         ; (this code table has been used and tested!)
  1287.         ;-------------------------------------------------
  1288.         ; COMMENTED OUT!
  1289.  
  1290.                 ;movlw b'11000101'              ; 0,            100,0   A+ B+   00=0            01=25
  1291.                 ;movlw b'11010101'              ; 1,            100,25  A+ B+   10=55   11=100
  1292.                 ;movlw b'11100101'              ; 2,    100,55  A+ B+
  1293.                 ;movlw b'11110101'              ; 3,    100,100 A+ B+
  1294.                 ;movlw b'10110101'              ; 4,    55,100  A+ B+
  1295.                 ;movlw b'01110101'              ; 5,    25,100  A+ B+
  1296.         ;-------------------------
  1297.                 ;movlw b'00111001'              ; 6,    0,100   A- B+
  1298.                 ;movlw b'01111001'              ; 7,    25,100  A- B+
  1299.                 ;movlw b'10111001'              ; 8,    55,100  A- B+
  1300.                 ;movlw b'11111001'              ; 9,    100,100 A- B+
  1301.                 ;movlw b'11101001'              ; 10,   100,55  A- B+
  1302.                 ;movlw b'11011001'              ; 11,   100,25  A- B+
  1303.         ;-------------------------
  1304.                 ;movlw b'11001010'              ; 12,   100,0   A- B-
  1305.                 ;movlw b'11011010'              ; 13,   100,25  A- B-
  1306.                 ;movlw b'11101010'              ; 14,   100,55  A- B-
  1307.                 ;movlw b'11111010'              ; 15,   100,100 A- B-
  1308.                 ;movlw b'10111010'              ; 16,   55,100  A- B-
  1309.                 ;movlw b'01111010'              ; 17,   25,100  A- B-
  1310.         ;-------------------------
  1311.                 ;movlw b'00110110'              ; 18,   0,100   A+ B-
  1312.                 ;movlw b'01110110'              ; 19,   25,100  A+ B-
  1313.                 ;movlw b'10110110'              ; 20,   55,100  A+ B-
  1314.                 ;movlw b'11110110'              ; 21,   100,100 A+ B-
  1315.                 ;movlw b'11100110'              ; 22,   100,55  A+ B-
  1316.                 ;movlw b'11010110'              ; 23,   100,25  A+ B-
  1317.  
  1318.  
  1319.  
  1320.         EXAMPLE! full table example here, 0-71 steps showing every step...
  1321.  
  1322.         ;-------------------------
  1323.         0       100,0   A+ B+
  1324.         1        100,8   (pwm tween)
  1325.         2        100,17  (pwm tween)
  1326.         3       100,25  A+ B+
  1327.         4        100,35  (pwm tween)
  1328.         5        100,45  (pwm tween)
  1329.         6       100,55  A+ B+
  1330.         7        100,70  (pwm tween)   
  1331.         8        100,85  (pwm tween)
  1332.         9       100,100 A+ B+   (rest of table is same, tweens not shown)
  1333.         10
  1334.         11
  1335.         12      55,100  A+ B+
  1336.         13
  1337.         14
  1338.         15      25,100  A+ B+
  1339.         16
  1340.         17
  1341.         ;-------------------------
  1342.         18      0,100   A- B+
  1343.         19
  1344.         20
  1345.         21      25,100  A- B+
  1346.         22
  1347.         23
  1348.         24      55,100  A- B+
  1349.         25
  1350.         26
  1351.         27      100,100 A- B+
  1352.         28
  1353.         29
  1354.         30      100,55  A- B+
  1355.         31
  1356.         32
  1357.         33      100,25  A- B+
  1358.         34
  1359.         35
  1360.         ;-------------------------
  1361.         36      100,0   A- B-
  1362.         37
  1363.         38
  1364.         39      100,25  A- B-
  1365.         40
  1366.         41
  1367.         42      100,55  A- B-
  1368.         43
  1369.         44
  1370.         45      100,100 A- B-
  1371.         46
  1372.         47
  1373.         48      55,100  A- B-
  1374.         49
  1375.         50
  1376.         51      25,100  A- B-
  1377.         52
  1378.         53
  1379.         ;-------------------------
  1380.         54      0,100   A+ B-
  1381.         55
  1382.         56
  1383.         57      25,100  A+ B-
  1384.         58
  1385.         59
  1386.         60      55,100  A+ B-
  1387.         61
  1388.         62
  1389.         63      100,100 A+ B-
  1390.         64
  1391.         65
  1392.         66      100,55  A+ B-
  1393.         67
  1394.         68
  1395.         69      100,25  A+ B-
  1396.         70
  1397.         71
  1398.         ;-------------------------------------------------
Título: Re: Control de motores PAP por micro pasos
Publicado por: stk500 en 10 de Abril de 2014, 10:12:36
 :D el Jefe Reviviendo Temas :D :D