Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/15/05 15:34
Read: times


 
#99450 - problem with timming routine
the following is a program for a stress test machine i have tried running it on a simulator and it runs fine but somehow it doesn't on the real chip. if anybody out there has an 'ice' or could point out the blatent stupidity i have made i would be very obliged. I really don't know what else could be done.

following is the assembly program for the same. pls tell me if you need any more information

Thank you.

;****************General Description*************
;This is a program to control a stress test machine's treadmill

;About The machine

;The treadmill has four motors i.e
;Slow speed motor(Used only at startup to bring the treadmill to minimum speed)
;Main Motor(Used during the stress test)'
;Speed control Motor(Which accoring to the connection can increase or decrease speed)
;Elevation Motor(Used to increase or decrease elevation

; it also has four limit switches to sense the
;minimum speed, maximum speed, minimum elevation & maximum elevation
;____________________________________________________

;The exernal components to the microcontroller

;The program intends to interface six switches i.e
;Start, Stop, Speed +, Speed -,Elevation +, Elevation -, and a toggle switch

;This toggle switch is used to set the delay for which the relays will be on after
;pressing any one of the switches (e.g. If toggle is pressed twice then on pressing the
;Speed + switch the Speed + relay will be on for 10 sec. if pressed once more then the
;Motor will stay on for 20 sec)

;The toggle is inteded to be pressed first after Startup and then when the start button is
;pressed based on the selected delay (toggle) the relays will switch on and off for that long
;_______________________________________________________

;Microcontoller

;I am using an ATMEL 89c51 it belongs to the 8051 family and is flash programmable
;_______________________________________________________

;Possible errors
;The delay routine had a few bugs but it was removed and checked (i.e only the delay routine
;was put on a chip and an port pin was made to switch on and off)

;The keypress routine was checked but even the minimilistic routine(i.e. Switching on and off
;of a port pin by a keypress doesn't work)

;The keypress routine contains the following step
; The key is held high by an external pull up
; If key is pressed then it is pulled to ground
; This is checked and once this happens the corrosponding action is taken
; The is a delay for 2 Seconds after the action so that a keypress is not sampled twice

;The alternative to this routine is to check the key by manually placing the key high
;and checking if the goes low that i havent checked but i dont know why this routine
;shouldnt work

;The following program is the minimilistic routine to start the machine and to
;check the effect of starting each of the relays

;What we want to do is switch on the speed + relay for some time interval & check
;the increase in speed this way we can use this information to obtain any particular
;speed we need

;The final program should include five automated routine which each have a time interval
;During which a particular speed should be mainted at a particular elevation

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

ljmp main


org 50h
;*******Initialisation**********
main:
mov p0,#00h ;Relays operated through npn transistors
mov p1,#0ffh ;Limit Switches to indicate low and high position
mov p2,#01h ;Leds
mov p3,#0ffh ;Switches - Start, Stop, Toggle etc.
mov r0,#00h
mov tmod,#01h ;Timer 0 Mode 1 (16 bit mode)
mov tcon,#00h

;*******Min Speed Routine********
setb p0.0 ;Decrease Speed to Minimum
setb p0.3 ;Start Slow speed motor and speed decrease motor
jb p1.0,$ ;Keep them running till the sensor senses minimum speed
clr p0.3
clr p0.0

;*********Check Key press********
keysense:
jnb p3.0,toggle ;Two switches polled to see if any one is pressed
jnb p3.1,start ;One to switch the time interval for which the relay will be ON
ajmp keysense ;Second to start


toggle:

setb p3.0
;___________first press___________
cjne r0,#00h,tog1 ;1 press prog no =2 5sec delay
inc r0 ;Used to check later which delay was chosen

clr p2.0 ;Set appropriate led
setb p2.1

mov r2,#64h ;values for delay routine
mov r3,#01h
lcall keybounce ;Delay of 2 seconds so that keypress is not read twice
ljmp keysense ;Back to polling and waiting for start key
;___________________________________________
tog1: ;2 press prog no=3 10sec delay
cjne r0,#01h,tog2
inc r0
clr p2.1
setb p2.2

mov r2,#0c8h
mov r3,#01h

lcall keybounce
ljmp keysense
;___________________________________________
tog2: ;3 press prog no=4 20 sec delay
cjne r0,#02h,tog3
inc r0
clr p2.2
setb p2.3

mov r2,#0c8h ;10 x 2 sec
mov r3,#02h

lcall keybounce
ljmp keysense

;___________________________________________
tog3: ;4 press prog no=5 30 sec delay
cjne r0,#03h,tog4
inc r0
clr p2.3
setb p2.4

mov r2,#0c8h ;10 x 3 sec
mov r3,#03h

lcall keybounce
ljmp keysense

;___________________________________________
tog4: ;5 press prog no=6 60 sec
cjne r0,#04h,tog5
inc r0
clr p2.4
setb p2.5

mov r2,#0c8h ;10 x 6 sec
mov r3,#06h

lcall keybounce
ljmp keysense
;___________________________________________
tog5: ;6 press prog no=0 3 min delay
mov r0,#00h
clr p2.5
setb p2.0

mov r2,#0c8h
mov r3,#12h

lcall keybounce
ljmp keysense
;___________________________________________


;**********Main ()**********************
start:
setb p0.1 ;Start Main Motor

;******Check any key pressed************
poll: ;check if any button (Speed + , speed - etc.) is pressed
mov a,p3
orl a,#03h ;Ignoring the start and toggle button
xrl a,#ffh ;Checking by 'Xor'ing the value and checking if zero
jz poll

;___________________________________________
xrl a,#04h ;Check if Stop buttons pressed
jnz nxt1
Clr p0.1
setb p3.1 ;Stop pressed return to main
ljmp main

;___________________________________________
nxt1:
xrl a,#0ch ;Check Speed Inc 'Xor' takes care of previous 'Xor'ed value too
jnz nxt2
setb p0.2
lcall delay
clr p0.2
ljmp poll
;___________________________________________
nxt2:
xrl a,#18h ;Check Speed Dec
jnz nxt3
setb p0.3
lcall delay
clr p0.3
ljmp poll
;___________________________________________
nxt3:
xrl a,#30h ;Check elevation inc
jnz nxt4
setb p0.4
lcall delay
clr p0.4
ljmp poll
;___________________________________________
nxt4:
xrl a,#60h ;Check elevation dec
jnz nxt5
setb p0.5
lcall delay
clr p0.5
ljmp poll
;___________________________________________
nxt5:
ljmp poll


;************Key Bounce delay****************
keybounce: ;Delay of 2 seconds

mov r5,#28h
kbcntr:
mov TL0,#0afh ;Initial Values to the timer
mov TH0,#3ch ;So that it counts only 50,000 times
setb tcon.4 ;Hence delay of 0.05 seconds
jnb tcon.5,$ ;Waiting till the overflow flag is set
clr tcon.4 ;Clearing overflow flag
clr tcon.5 ;Clearing run flag i.e stopping the timer
djnz r5,kbcntr ;Repeating the routine for 60 times (0.05 x 60)
clr tcon.4
ret

;***********Actual Delay routine*************
delay:

mov a,r2
mov r5,a
mov a,r3
mov r6,a
cntr1:
mov TL0,#0afh ;Same as above except the repeat values
mov TH0,#3ch ;is given during the toggle routine
setb tcon.4
jnb tcon.5,$
clr tcon.4
clr tcon.5
djnz r5,cntr1
djnz r3,cntr2
clr tcon.4
ret
cntr2:
mov a,r2
mov r5,a
ljmp cntr1
;__________________________________________________________________

;______________________Port Connections____________________________
;p0 (relays)
;0- Slow speed motor 1- Main Motor 2- Speed Increase 3- Speed Decrease
;4- Elevation Inc 5- Elevation Dec

;p1 (Sensors)
;0 - MIn Speed Sensor 1- Max Speed Sensor
;2- Elevation min 3- Elevation Max
;

;p2 (led)
;0-5 - Led's for timer interval (R0- holds program)

;P3 (switches)
;0- tOGGLE PROGRAM 1- Start 2-stop 3- speed inc 4-speed dec 5- elevation inc 6- elevation dec
;7- Reset

List of 4 messages in thread
TopicAuthorDate
problem with timming routine            01/01/70 00:00      
   Look at values in delay subroutines            01/01/70 00:00      
   what does it do in reality?            01/01/70 00:00      
   re:problem            01/01/70 00:00      

Back to Subject List