0
\$\begingroup\$

I have this stepper motor:

enter image description here

enter image description here

I write the code below for a PIC16F877 microcontroller for a continuous movement in stepper motor:

    LIST P=16F877A
include "P16F877A.INC"
__CONFIG _RC_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF & _BODEN_ON & _LVP_OFF  & _CPD_OFF & _DEBUG_OFF;
ERRORLEVEL -302

cblock 0x020
    d1
    d2
endc    

    org         0x00
    goto        start
    org         0x04
    retfie

start
    bcf         STATUS,RP0              ;BANK 0
    bcf         STATUS,RP1
    clrf        PORTB


    bsf         STATUS,RP0
    bcf         STATUS,RP1              ;BANK 1
    clrf        TRISB
    bcf         STATUS,RP0              ;BANK 0

    call move

move
    movlw   b'00001010'
    movwf   PORTB
nop
    call    delay
nop 
    movlw   b'00000110'
    movwf   PORTB
    call    delay

    movlw   b'00000101'
    movwf   PORTB
    call    delay

    goto    move
return



delay
    movlw   0xFF
    movwf   d1
delay_0
nop
nop
nop
nop
    nop
    nop
    nop
    decfsz  d1,f
    goto delay_0
    nop
    return



idle_loop
    goto        idle_loop

end

But the stepper motor isn't working. I connect: red:RB0, green:RB1, yellow:RB2 , blue: RB3 and i have a ULN2003A darlington transistor.

Is there an alternative way to test it to see if it is not work properly?

\$\endgroup\$
  • \$\begingroup\$ I have add the wiring diagram to my description. You are right i am going to call multiple times the move procedure. If i put 4 states and call again the first stare is going to be a double state, this is alright? \$\endgroup\$ – 20317 Mar 24 '13 at 15:48
  • \$\begingroup\$ Use banksel to change banks, it's much easier than messing about with status bits. \$\endgroup\$ – Leon Heller Mar 24 '13 at 17:51
2
\$\begingroup\$

The stepper motor you have needs a bridge driver, not a unipolar drive like a Darlington transistor.

Also, the "move" loop needs 4 steps, changing the state of one winding at a time. Yours only has 3 steps; so at "goto move" you reverse both windings which will stall the motor.

The driver you have can pull one end of a coil down to 0V. Which works fine if you can permanently wire the other end to 5V (or other V+) This is the way steppers with 4 separate coils are wired.

But a bridge driver can pull to either 0V or 5V - and you can see that you have to do this - if red is 0V, green must be 5V, and vice versa. One example op a bridge driver is the L293D which is used on the AdaFruit motor shield among other places. "Figure 2" in that datasheet shows one way to use it (with inverters generating 2 of the 4 input bits, where you are using 4 port bits).

Four step switching sequence :
move:
10 10
01 10
01 01
10 01
goto move

Hopefully this is enough information to get you started.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thanks, so i need to buy a bridge driver and change my code. What is the difference between a bridge driver and a unipolar drive? \$\endgroup\$ – 20317 Mar 24 '13 at 16:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.