Stepper Motor and Pic Micocontroller

Thread Starter

Razeksk

Joined Jun 5, 2012
7
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 <p16f887.inc> ; 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.

__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V


cblock 0x20

Direction ; Motor Direction (Left/Right)

Delay1ms ; 1ms Delay
Delay250ms ; 250ms Delay
Delay1s ; 1s delay
Delay30s ; 30s delay
Delay11
Delay22
d1
d2
d3

temp

endc

;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


Main:


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

OndelayLoop:
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.
return


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

;3 cycles
goto $+1
nop

;4 cycles (including call)
return
 

Attachments

John P

Joined Oct 14, 2008
2,068
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.
 

Thread Starter

Razeksk

Joined Jun 5, 2012
7
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
 

shortbus

Joined Sep 30, 2009
10,049
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.
 

Markd77

Joined Sep 7, 2009
2,806
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.
 
Top