Stepper Motor and Pic Micocontroller

Discussion in 'Embedded Systems and Microcontrollers' started by Razeksk, Jun 5, 2012.

  1. Razeksk

    Thread Starter New Member

    Jun 5, 2012
    I am currently working on a project that uses a stepper motor and a PIC16F887 micro controller to run it. The motor is rated for 7V and I have a 7V supply to the motor and the driver circuit. The Micro controller is run off 5V. I wrote a simple program for troubleshooting that should just step the motor every 5 seconds. I also output the value to my LED's on my board so I can tell that the correct sequence is being outputted to the motor. The problem is, the LED's are showing the correct output but nothing is happening with the motor. I am reading the voltage across the output wire to the breadboard from the microcontroller and when high it is only 3.5V instead of the 5V it should be. Then at my last FET, the voltage across the output is only .4V when high. I have been trying to troubleshoot this for a while and I am stuck. I attached a picture of my driver circuit... and my assembly language program is below. Any help or suggestions would be greatly appreciated. The part I finished was for a school project, but this is more for personal use now and I don't have much experience in troubleshooting circuits like this yet. Thanks in advance.

    It is my troubleshooting code so there is not much organization.

    list p=16f887 ; list directive to define processor
    #include <> ; processor specific variable definitions

    ; '__CONFIG' directive is used to embed configuration data within .asm file.
    ; The labels following the directive are located in the respective .inc file.
    ; See respective data sheet for additional information on configuration word.


    cblock 0x20

    Direction ; Motor Direction (Left/Right)

    Delay1ms ; 1ms Delay
    Delay250ms ; 250ms Delay
    Delay1s ; 1s delay
    Delay30s ; 30s delay



    ;Index1 equ b'1001' ; Stepper motor pos1
    ;Index2 equ b'1100' ; Stepper motor pos2
    ;Index3 equ b'0110' ; Stepper motor pos3
    ;Index4 equ b'0011' ; Stepper motor pos3

    Index1 equ b'00001001'
    Index2 equ b'00001010'
    Index3 equ b'00000110'
    Index4 equ b'00000101'

    ORG 0 ; processor reset vector
    goto Main ; go to beginning of program


    bcf STATUS,RP1 ; Select register bank 0
    bcf STATUS,RP0

    clrf PORTC
    clrf PORTD

    bsf STATUS,RP0 ; Bank Select 1

    clrf TRISC ; Set PORTC as outputs (For motor)
    clrf TRISD

    bcf STATUS,RP0 ; Back to bank 0
    bcf STATUS,RP1

    movlw Index1
    movwf PORTC
    movwf PORTD
    call Delay5

    movlw Index2
    movwf PORTC
    movwf PORTD
    call Delay5

    movlw Index3
    movwf PORTC
    movwf PORTD
    call Delay5

    movlw Index4
    movwf PORTC
    movwf PORTD
    call Delay5

    goto Main

    decfsz Delay11,f ; Waste time.
    goto OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
    decfsz Delay22,f ; The outer loop takes and additional 3 instructions per lap * 256 loops
    goto OndelayLoop ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
    ; call it two-tenths of a second.

    ;4999993 cycles
    movlw 0x2C
    movwf d1
    movlw 0xE7
    movwf d2
    movlw 0x0B
    movwf d3
    decfsz d1, f
    goto $+2
    decfsz d2, f
    goto $+2
    decfsz d3, f
    goto Delay_0

    ;3 cycles
    goto $+1

    ;4 cycles (including call)
  2. Razeksk

    Thread Starter New Member

    Jun 5, 2012
    ps I forgot the end in my code that I copied..
  3. John P

    AAC Fanatic!

    Oct 14, 2008
    The first thing I would try is disconnect the MOSFET gates from the processor, and try connecting them in turn to +5V. What you should see is the motor twitching, and in fact if you get the sequence right, you can cause the motor to turn in a consistent direction. If applying 5V to the FET gates moves the motor, then you know your wiring of the FETs and motor is OK, and the problem is with the processor. If there's no motion, then you aren't powering the motor, or the FETs aren't working.

    Also, try putting LEDs not just on the output of the processor, but in parallel with the motor coils (each LED with a resistor in series, of course). Again, this proves whether the FETs are controlling current.
  4. Razeksk

    Thread Starter New Member

    Jun 5, 2012
    Ok so I tested it by putting 7V to the gate and there was pulsing of the motor and it held when I gave voltage to two phases like it should have. It did the same when I applied 5V, but the holding power was not as great as it was with 7V (Naturally). I am assuming it is something wrong with my microcontroller, I know the right sequence is being outputted, but there is no response from the motor. When I measured the voltage at the gate at the first FET it was something like 3.5V and at the last FET when set high was only like .4V
  5. shortbus

    AAC Fanatic!

    Sep 30, 2009
    You don't say what mosfet your using, is it a "logic" level mosfet? A normal mosfet takes ~10V to turn on. Don't use the "threshold voltage" to pick your mosfets, that is really the 'turn-off' voltage. Threshold voltage is usually only needed when using the mosfet in an amplifier.

    Why the resistors on the gates going to ground? Those are pulling the gate voltage down when trying to switch the mosfet on.
  6. Markd77

    Senior Member

    Sep 7, 2009
    You could do with 300Ω resistors from the PIC pins to the gates. The gates are like capacitors so without resistors you will exceed the maximum safe current for the outputs.