Discussion in "PIC Microcontroller Discussion" started by    cestudent    Nov 10, 2008.
Mon Nov 10 2008, 11:56 AM
#1
hello guyz
how r u all?

i have a problem while testing stepper motor
i wrote an assembly code to rotate the stepper motor for a Specific number of steps and then it should stop but the stepper is still moving!!! can u tell what to do coz i want to stop the stpper motor after the count=0 .
am using pic16f84a and 6 wire stepper motor



  
; 
;******************************************************************* 
; NOTES: 
; 
; 
;       PORTBO= NORTH POLE 
;       PORTB1= EAST POLE 
;       PORTB2= SOUTH POLE 
;       PORTB3= WEST POLE 
;***************************************************************** 


PORTA      EQU     5 
PORTB                      EQU     6 
STATUS      Equ    3 
TMR0      EQU   1 
COUNT      EQU   0CH 
COUNT1      EQU   0DH 
INTCON      EQU   0BH 
COUNTD      EQU   0FH 

;****************************************************************** 
        LIST    P=16F84A 
        
        org      0 
        goto    START 

;********************************************* 
  

DELAY   CLRF   TMR0 
   MOVLW   .10 
   MOVWF   COUNT 
   BCF   STATUS,5 
WAITA   BCF   INTCON,2 
WAITB   BTFSS   INTCON,2 
   GOTO   WAITB 
   DECFSZ   COUNT,1 
   GOTO   WAITA 
   RETURN 
   RETLW   0 
;************************************** 

START 
  
   BSF   STATUS,5 ;BANK1 
   MOVLW   B'00000000'       
   TRIS   PORTB               ; b0:b3 " stepper output " 
   MOVLW   B'00000011'       
   TRIS   PORTA    
   MOVLW   B'0000001' 
   OPTION 
   BCF     STATUS,5  ; BANK0 

   CLRF   PORTB 
   MOVLW   .10 
   MOVWF   COUNTD 
    
LOOP1    
   BSF   PORTB,4 
   CALL   DELAY 

   MOVLW   .1 
   MOVWF   PORTB 

   CALL   DELAY 
    


   MOVLW   .2 
   MOVWF   PORTB 


   CALL   DELAY 
    

   MOVLW   .4 
   MOVWF   PORTB 

   CALL   DELAY 
    
    
   MOVLW   .8 
   MOVWF   PORTB 
    

   BCF   PORTB,4 
   DECFSZ   COUNTD 
    GOTO   LOOP1 

   BSF   PORTB,5 
LL   NOP 
   GOTO LL 

   END 
    


plzz help me
Mon Nov 10 2008, 05:45 PM
#2
   BCF   PORTB,4
   DECFSZ   COUNTD
;    GOTO   LOOP1
;remove this instruction and try again.

   BSF   PORTB,5
LL   NOP
   GOTO LL

   END
Mon Nov 10 2008, 07:14 PM
#3
BCF   PORTB,4
   DECFSZ   COUNTD
    GOTO   LOOP1


The DECFSZ instruction is missing an operand.
Change to...

BCF   PORTB,4
   DECFSZ   COUNTD,1
    GOTO   LOOP1
Mon Nov 10 2008, 07:27 PM
#4
thanx alot Ajay & sashijoseph
am gonna check both codes and feed back with the results
Tue Nov 11 2008, 05:58 PM
#5
the problem has been solved with disabling the watchdog timer
thanx guyz for ur help

Thu Nov 13 2008, 07:25 AM
#6
great well my answer was wrong sorry.. i did not see your program properly.

[Topic moved to PIC Microcontroller Discussion]
Thu Nov 13 2008, 09:07 PM
#7
sorry guys i have an other problem

let me tell u what i do , i am doing lift project , in this code am using the input switches as floor requests and each floor request has specific number of steps and the lift should calculate the distance and the direction

but the problem when i tested the code the distance was wrong !!

maybe because i dont know how to tell the stepper motor to move for 30 steps for example or is there any calculation to do that in a correct way
here my code

; 
;*******************************************************************
; NOTES: 
; 
;
;       PORTBO= NORTH POLE
;       PORTB1= EAST POLE 
;       PORTB2= SOUTH POLE
;       PORTB3= WEST POLE 
;*****************************************************************


PORTA		EQU     5
PORTB           EQU     6 
STATUS		Equ 	3
TMR0		EQU	1
COUNT		EQU	0CH 
COUNT1		EQU	0DH
INTCON		EQU	0BH
COUNTD		EQU	20H
CURRENTCOUNT	EQU	21H 
DISTANCE	EQU	22H 

;******************************************************************
        LIST    P=16F84A
        __CONFIG 0x200B 
        org   	0
        goto 	START

;*********************************************
 

DELAY	CLRF	TMR0
	MOVLW	.3
	MOVWF	COUNT
	BCF	STATUS,5
WAITA	BCF	INTCON,2
WAITB	BTFSS	INTCON,2
	GOTO	WAITB
	DECFSZ	COUNT,1
	GOTO	WAITA
	RETURN
	RETLW	0
;**************************************

START 
 
	BSF	STATUS,5 ;BANK1
	MOVLW	B'00000000'		 ; SET B0 , B1 ,B2,B3,AS OUTPUT  
	TRIS	PORTB	
	MOVLW	B'00001111'		 ; SET A0 , A1 ,A2,A3,AS INPUT SWITCHES 
	TRIS	PORTA	
	MOVLW	B'0000001'
	OPTION
	BCF  	STATUS,5  ; BANK0 

	CLRF	PORTB
	


	MOVLW	.0
	MOVWF	CURRENTCOUNT 

loop1	BTFSS	PORTA,0 	; check for a floor1 request 
	goto	check1
	MOVLW	.0
	MOVWF	COUNTD
	GOTO	MAIN
		
	
check1	BTFSS	PORTA,1		; check for a floor2 request 
	goto	check2
	MOVLW	.30
	MOVWF	COUNTD
	GOTO	MAIN



check2	BTFSS	PORTA,2		; check for a floor3 request 
	goto	check3
	MOVLW	.50
	MOVWF	COUNTD
	GOTO	MAIN
	
	
check3	BTFSS	PORTA,3		; check for a floor4 request 

	goto	check4
	MOVLW	.70
	MOVWF	COUNTD
	GOTO	MAIN

check4	goto	loop1	


MAIN 



	MOVF	COUNTD,W
	subwf	CURRENTCOUNT,W   ; distanation is w 
	MOVWF	DISTANCE
	MOVF	COUNTD,W
	MOVWF	CURRENTCOUNT 
	btfss	STATUS,0        ; test if the result is positive or negative 
	goto	UP
	goto    DOWN

	



UP 	MOVLW	.8
	MOVWF	PORTB

	CALL   DELAY
	


 	MOVLW	.4
	MOVWF	PORTB


	CALL	DELAY 
	

 	MOVLW	.2
	MOVWF	PORTB

	CALL	DELAY 
	
	MOVLW	.1
	MOVWF	PORTB
	

	CALL	DELAY  
	DECFSZ	DISTANCE,1
 	GOTO	UP
	GOTO	loop1 
	 




DOWN 	MOVLW	.1
	MOVWF	PORTB

	CALL   DELAY
	


 	MOVLW	.2
	MOVWF	PORTB


	CALL	DELAY 
	

 	MOVLW	.4
	MOVWF	PORTB

	CALL	DELAY 
	
	MOVLW	.8
	MOVWF	PORTB
	

	CALL	DELAY  
	DECFSZ	DISTANCE,1
 	GOTO	DOWN 
	GOTO	loop1 
	 

END 



	
						



waiting for ur replies guyz


[ Edited Thu Nov 13 2008, 09:23 PM ]
Fri Nov 14 2008, 02:27 PM
#8
any help ppl
Fri Nov 14 2008, 08:55 PM
#9
You have routines UP and Down which presumably move the stepper one step either way.

Do they work ?
ie if you run UP 50 times, does it move 50 steps ?
if you run UP 50 times and then Down 50 times do you end up at the same place.?

If so, congratulations your hardware works and
you have a way to measure floors , just decide how many loops of UP or Down is a floor.

The general layout of your program seems odd to me.
I would suggest something like,

Start
//Initialize variables
Main:

Read button:
call Check for button pressed //routine to read buttons..set new floor
call Calculate Distance and direction //routine to... guess what..
call Up_ Down loops //do a set number of loops
go to Read button. //Go round again




Use Calls and returns and less GOTOs


[ Edited Fri Nov 14 2008, 09:04 PM ]
Sun Nov 16 2008, 02:11 PM
#10
thanx ExperimenterUK for ur help and advice
i have a question when I output .1 this means that the stepper has to move one step right ?


[ Edited Sun Nov 16 2008, 04:47 PM ]

Get Social

Information

Powered by e107 Forum System

Conversation

ExperimenterUK
Thu Nov 20 2014, 06:00 PM
@Mehboob.. I don't think you can do that.
Sat Nov 15 2014, 06:41 AM
Mehboob
Pls can you send me code in c of PWM generation using UART/serial port in 8051.
Fri Nov 14 2014, 02:51 PM
mohammad aqil
NEED A BOOK ON MICROPROCESSOR AND INTERFACING BY D.V.HALL. RIGHT NOW, I SHALL BE VERY THANK FULL TO U....
Thu Nov 13 2014, 02:15 PM
m
please code hex project avr blood pressure monitor
Thu Nov 13 2014, 05:56 AM
Lambo
hi mate, whats the ajay-bhargav? tell us more pls
ExperimenterUK
Wed Nov 12 2014, 12:56 AM
@tmtm000.. have you been able to join ?
ExperimenterUK
Wed Nov 12 2014, 12:54 AM
@Alice..become a member,then send a PM to ajay_bhargav the site owner.
Tue Nov 11 2014, 03:58 AM
Abhishek Bansal
Thanks a lot for your informative tutorials!
Mon Nov 10 2014, 09:03 AM
Alice
Hello, This is Alice from a PCB rototype manufacturer. Our company is interested in your website contents, and wonder if we can advertise our company with payment on your website. There are two ways to advertise: first, if we an get a instant quote section on your main site columns; second, whether we can get a advertising section if you have any avaliable one. If any of above ways avaliable, please contact me with your detailed scheme and advertising charge. Thanks. Alice
Sat Nov 08 2014, 11:58 AM
Mohamed_123sd
Signals and Systems, 2nd Edition by Alan V. Oppenheim Alan S.willsky with S.Hamid Nawab?

Downloads

Comments

dpkraju
Wed Nov 26 2014, 02:18 PM
sankalp_s
Tue Nov 25 2014, 05:13 PM
dodul
Mon Nov 24 2014, 10:08 PM
VikiPeter
Tue Nov 18 2014, 09:13 AM
gentlboy
Sun Nov 16 2014, 11:13 PM
philipeastbourne
Wed Nov 12 2014, 05:32 AM
astra91
Mon Nov 10 2014, 08:11 AM
francise
Thu Nov 06 2014, 02:55 AM

Online

Guests: 67, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37550
Newest member: dpkraju
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Nov 26 2014, 06:36 PM
I never tried sending SMS messages at a high rate,...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Nov 26 2014, 06:23 PM
connected my modem with Laptop via serial2usb cabl...
dodul Avatar
Posted By dodul
Wed Nov 26 2014, 04:30 PM
Hi,Thanks a lot for your reply. Yes i was referrin...
nomi77 Avatar
Posted By nomi77
Wed Nov 26 2014, 07:30 AM
@ajayAnother option is this if i can do void stor...
nomi77 Avatar
Posted By nomi77
Wed Nov 26 2014, 07:05 AM
@ajayI did same procedureconnected my modem with L...
ajay_bhargav Avatar
Posted By ajay_bhargav
Wed Nov 26 2014, 04:47 AM
Are you manually trying to input data via virtual ...
ajay_bhargav Avatar
Posted By ajay_bhargav
Wed Nov 26 2014, 04:39 AM
Uart is totally different peripheral. Look at seri...
ajay_bhargav Avatar
Posted By ajay_bhargav
Wed Nov 26 2014, 04:37 AM
I see three different components in your design bu...
ajay_bhargav Avatar
Posted By ajay_bhargav
Wed Nov 26 2014, 04:33 AM
Are you bound to use assembly? if yes then there w...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Nov 26 2014, 02:33 AM
I assume you mean CMMS as in AT+CMMS, something to...