Discussion in "8051 Discussion Forum" started by    davethok    Nov 3, 2007.
Sat Nov 03 2007, 09:04 pm
#1
Hi, my name is David. I have a question about AT89S52 controlling motor to move a crane. I want to control that motor just moving up the crane then moving down the crane and stop. The space for moving up and down is fixed. In the bottom and top the space, i put a limit switch. So, the work is just like this,
1. First, the crane is in the bottom and touch the bottom limit switch (BLS).
2. The motor then moving up the crane until touch the top limit switch (TLS).
3. Suddenly, when TLS touched by the crane, the motor moving down the crane until touch BLS
4. When BLS touched by the crane, the motor stop to work. Operation stop

I hope is there anybody can help me to make program in assembler for this operation. I have already try it but still not work. Here is the latest try
;====================================================
$mod51
Org 00h
jmp start
org 100h

M1	bit p1.0	; motor (+) sign
M2	bit p1.1	; motor (-) sign
TLS	bit p1.2	; TLS = top limit switch
BLS	bit p1.3	; BLS = bottom limit switch
HOP    bit p1.4	;

start:	jb HOP,start1	; if HOP = 1, goto start1
	   jmp start	       ; else, goto start

start1:	jnb TLS,up	; if BLS = 0, goto up
	   jmp start1	     ; else wait

up:	setb M1		; 
	   clr M2		; crane going up
	   jb TLS, down
	   jmp up

down:	jnb BLS, down1	; if BLS = 0, goto down1
	     jmp down

down1:	setb M2	
	      clr M1		; crane going down
	      jb BLS, stop	; if BLS = 1, goto stop
	      jmp down1

stop:	clr M1		; stop the motor
	   clr M2
	   ret
end
;====================================================


[ Edited Sun Jan 20 2008, 11:49 pm ]
Sat Nov 03 2007, 09:51 pm
#2
Ok first... correct me if the sequence is not right...ok

first motor starts moving up!
then when crane touches the TLS
motor start moving down..
when crane touches the BLS
motor stops

So for this.. you need four routines..
main, up, down, stop

in main you just wait for right switch to be pressed and then jump to do the work.. ok!
now before i go further i need to know what is the on and off position for BLS and TLS. i mean..
when motor start and crane moves up what is the level of BLS and when crane touches TLS what is the new level of TLS
and what kind of switches you are using for TLS and BLS.. are they simple push buttons?
please give the above details so i can help you with the coding.. because i actually got confused from your code.. regarding the working of TLS and BLS.
Sun Nov 04 2007, 03:51 pm
#3
Thanks Ajay. The sequence is right and how to make the routines ?

For the switches, i use a limit switch that have 3 pad: NC, NO and C. NC connected to GND, NO connected to VCC and C connected to microcontroller (correct me, if i have wrong connection).
1. The crane is in the bottom and touched BLS (NO=1 so C=1)
2. The crane is moving up because TLS have state C=0 (NC=0)
3. When the crane touched TLS, TLS state changing to C=1(NO=1). And the BLS have new state C=0 (NC=0)
4. Suddenly, the crane is going down until touched BLS. When BLS have state C=1(NO=1), the crane is stop. The operation is finished

I'm sorry if you confused with my word because i'm not good in English. Thanks for your help
Sun Nov 04 2007, 08:52 pm
#4
Hi
so as per your explanation.. HOP is the switch to start the whole operation.. hope i am right..

so.. i tell you it will be this way.. test it..

start: jnb HOP,start ; if HOP = 1, goto start1
sjmp start1 ; else, goto start

start1:
;start motor up code
;some nop here
;to give some delay
tlssw: jnb TLS, tlssw
;start motor down code
;some nop here
;to give some delay
blssw: jnb BLS, blssw
;stop motor code
;some nop here
;to give some delay
sjmp start
Mon Dec 24 2007, 05:56 pm
#5
Ajay, i have fix my program like the code below. But the problem now is the motor/crane can't going down simultaneously unless if i pressed the start(hop) button.
$mod51	;crane program
org 00h
jmp start
org 100h

m1	bit p1.0
m2	bit p1.1
tls	bit p1.2
bls	bit p1.3
hop	bit p1.4

start:	clr m1
	clr m2
	jb hop,$
	call up
	jmp start

up:	setb m1
	jb tls,up
	clr m1 ;the problem is happenned in here

down:	setb m2 ;or in here
	jb bls,down
	clr m2
	ret
end

Description:
1. I pressed the start button then crane i going up until hit the TLS, it's stop.
2. The crane cannot going down regarding to the program and my simulation. The crane only going down if i pressed the start button again
Sun Jan 20 2008, 08:18 pm
#6
is this u want davethok

$mod51  ;crane program	Problem resolved by afta niaz
org 00h
jmp start
org 100h

m1       bit p1.0
m2       bit p1.1
tls        bit p1.2
bls       bit p1.3
hop     bit p1.4

start:  clr m1
           clr m2
           clr hop	
           clr tls
           clr bls
hop_sw:	   
	jb hop,up
   	jmp hop_sw 					
        ret
		
up:     
	jb bls,m_1
	jmp up
m_1: 	setb m1  	
			
sw_tls:       
	jb tls,down
	jmp sw_tls
        clr m1 				
	jmp sw_tls
	ret

down:   
	clr m1
	setb m2 			

sw_bls:        
	jb bls,stop
	jmp sw_bls
        ret

stop:	
	clr m2
	clr m1
	jmp start
	ret
end



[ Edited Sun Jan 20 2008, 08:24 pm ]
Mon Jan 21 2008, 12:00 am
#7
Hi aftab, there are small errors in your program..
in start routine you are clearing hop, tls and bls which makes them output port so reading them will always give you 0. so you should not clear them in the starting..

@davthok
I already gave you the overview of how to write your program..

m1       bit p1.0
m2       bit p1.1
tls        bit p1.2
bls       bit p1.3
hop     bit p1.4
org 0H
clr m1
clr m2
start: jnb hop,start ; if HOP = 1, goto start1
sjmp start1 ; else, goto start

start1:
;start motor up code
;some nop here
;to give some delay
setb m1
clr m2
tlssw: jnb TLS, tlssw
;start motor down code
;some nop here
;to give some delay
clr m1
setb m2
blssw: jnb BLS, blssw
;stop motor code
;some nop here
;to give some delay
clr m1
clr m2
sjmp start

I hope you have understood..

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ArktiTic
Sun May 05 2024, 07:06 pm
CesslasyNear
Sun May 05 2024, 02:58 pm
chimichmedic1204
Sun May 05 2024, 11:06 am
Jamiegob
Sun May 05 2024, 10:11 am
Gregoryjed
Sun May 05 2024, 10:02 am
Mariocax
Sun May 05 2024, 08:51 am
WilliamErync
Sun May 05 2024, 02:35 am
Danielnof
Sat May 04 2024, 11:12 pm