Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me fix this code for rotating 6 wire unipolar stepper motor

Status
Not open for further replies.

Thayas

Newbie level 6
Joined
Jun 22, 2007
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,389
Hey all,
I got a code to rotate 6 wire unipolar stepper motor from the internet..
It works fine in PROTEUS Simulator(All four ( RBO,RB1,RB2,RB3) pins gives output)
When i tried it in bread board.Only two pins(RB0,RB1) give the out put.I did not get any signals from RB2,RB3.
coding

LIST p=16F84 ; PIC16F844 is the target processor
#include "P16F84.INC" ; Include header file
CBLOCK 0x10 ; Temporary storage
pos
dc1
dc2
ENDC
LIST p=16F84 ; PIC16F844 is the target processor

#include "P16F84.INC" ; Include header file

CBLOCK 0x10 ; Temporary storage
ENDC

ORG 0
entrypoint goto start

ORG 4
intvector goto intvector

start
clrw ; Zero.
movwf PORTB ; Ensure PORTB is zero before we enable it.
bsf STATUS,RP0 ; Select Bank 1
movlw 0xF0 ; Set port B bits 0-3 as outputs
movwf TRISB ; Set TRISB register.
bcf STATUS,RP0 ; Select Bank 0
movlw 3 ; Initialize the motor position
movwf pos
movwf PORTB
call delay
clrf PORTB ; Motor drive off
;RETURN

PUSH BTFSC PORTA,0
CALL STOP
BTFSC PORTA,1
CALL stepcw
CALL stepccw
RETURN
;Rotate one step clockwise

stepcw
bcf STATUS,C ; Clear the carry flag
btfsc pos,3 ; Set carry if this bit set
bsf STATUS,C
rlf pos,W ; Pick up and rotate the motor's current position
andlw 0x0F ; Mask to lower nibble
movwf pos
movwf PORTB ; Drive the outputs
call delay ; Wait
clrf PORTB
call delay
CALL delay
; Clear the output

CALL PUSH
return

STOP CLRF PORTB
GOTO PUSH



;Rotate one step counter clockwise
stepccw
bcf STATUS,C ; Clear the carry flag
btfsc pos,0
bsf pos,4
rrf pos,W ; Pick up and rotate the motor's current position
andlw 0x0F ; Mask to lower nibble
movwf pos
movwf PORTB ; Drive the outputs
call delay ; Wait
clrf PORTB ; Clear the output
call delay
CALL delay
goto PUSH

; This routine implements the delay between steps,
; and thus controls the motor speed.
delay movlw 18 ; Outer loop iteration count
movwf dc1
dl1 clrf dc2 ; Initialize inner loop
dl2 nop
nop
decfsz dc2,F
goto dl2
decfsz dc1,F
goto dl1
return

END

Plc any one help me soon..........
 

Please help me.....

The PIC cannot drive the stepper motor directly, you need a driver like the ULN2803.
Post your schematic.
 

Re: Please help me.....

or you can use a simple transistor circuit to drive.
 

    Thayas

    Points: 2
    Helpful Answer Positive Rating
Re: Please help me.....

Yes,Thats correct.
I used ULN2003A IC.
My prob is "Pic did not give any output from RB1,RB2.
Only RB0 and RB1 gives the output.
what's the error in the coding..
But it's working proberly in PROTEUS simulator.
Thanks

Regards
Thaya
 

Re: Please help me.....

Your code has no config specs. In the Proteus simulation example you refer to, the config word is set with WDT is off, LP Osc and PWRTE enabled (not the default settings). If the Watchdog is on you will see resets during program execution which will cause funnies.

However, there is no reason why you shouldn't be able to drive PORTB <2:3> unless you have a dud PIC. Are you *sure* that is what is happening ?

Iain.
 

Please help me.....

Also there is no such thing as a 16F844, and why do you specify a 16F84 but comment 16F844 ?

What is the target chip?
 

Re: Please help me.....

Yes,That is typing mistake.
My target processor is (PIC)16F84A.
 

Please help me.....

your code is a mess... and dont forget to clear de WDTEN

in the start rutine you RETURN!!!!! whats that??? and the stepcw & stepccw end diferent.... I think you use the RA0 pin to determine if it will go clock-wise or counter clock_wise... so stepcw & stepccw should end with the goto push

I think it should be
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top