Microcontroller › 8051 › how to start timer by software and stop by external hardware and then taking resultant value of time?
- This topic has 6 replies, 3 voices, and was last updated 13 years, 6 months ago by
ZOBI.
-
AuthorPosts
-
July 12, 2011 at 10:54 am #1129
ZOBI
Participanti want to start a timer in 89c51 after a 10 usec pulse is given by pin p1.1 then timer wil continue to count the time and stop when it gets low on pin p1.2 , basicaly pin p1.2 is initialy LOW i want to stop the timer when it goes from low to HIGH and then again low after that i want to stop the timer and also i want to use that TIMER value for further process
plz can any buddy help me out for the source code of that
thanks in advance
July 20, 2011 at 7:40 am #6470Anonymous
Guestyaa it is very easy just check the count down timer project in 8051 microcontroller tab here at engineers garage
and you can achieve this thing by using timer interrupt, external interrupt of controller but you have to set the priority bits in interrupt priority table.
July 20, 2011 at 3:14 pm #6474ZOBI
Participanti hav read a lot about how timers ,interupts are enabled or start and stoped
but i cant understand that is there possible to load DECIMAL values in counter 0?
like
mov TL0,#0000
mov TH0,#0000July 21, 2011 at 2:20 pm #6482dagakshay
Participanthi zobi
try this it migh work out
mov TL0,<decimal value>
no need of pond”#” sign or to right ‘h’ at the end….
note: max value can go to 255 since TL0 is a 8 bit register
just let me know if it works???
July 21, 2011 at 8:09 pm #6487ZOBI
Participantok i will chek it out
basically i want this in my program
i want to use 16 bit timer then these steps in my prog.
1. pin p1.0 gives high for 10 microsecond then goes LOw, on its falling edge Timer 0 starts to count UP(with the help of INT0 timer start)
2. Then Timer will be stopped when pin P1.1 goes from high-to-LOW means on its falling edge(with the help of INT1 timer stop)
3. Then the TIMER value at which timer is stop ,will be save on Accumulator “A” or any register
4. then i will use that value for to compare between a range of diffrent values , the prog. will check whether the value is in between
166 microsecond to 1660 microsecond volt 1
1661 microsecond to 3320 microsecond volt 2
3321 microsecond to 4980 microsecond volt 3
4981 microsecond to 6640 microsecond volt 4
.
.
.
.
.
.
.
.
5. Then after a series of comparing/checking TIMEr value from these RANGES ,when TIMEr value comes in these any of range microcontroller will send a CODE to DAC0808 to produce a voltage of respective code like on volt 1 it will send a code to DAC0808 to produce more voltage and on sending a code of volt 2 it will send a code to DAC0808 to produce less voltage as copmared to volt and and so on..
basically i m designing a project Using ultrasonic range finder SRF04,89C51 ,DAC0808
when any object will come in front of sensor it will reflect back a the ultrasound waves which wass emited by sensor on reciving that a pin goes from high to LOw after that controller will calculate the time how much time does the wave has taken in air then it will give code to DAC0808 to produce voltages which will vibrate a motor according to the distance
here is the code which I have made to which makes pin p1.0 high for 10 usec ,start stop the timer 0 and then the VALUE of timer TL0 & TH0 will be added and will be saved in “A” but I don’t know is this correct or not.plz chek it
org 0000h
ljmp main
ORG 0003H
setb tr0
ORG 0013H
clr a
mov r4,tl0
mov a,th0
add a,r4
ORG 0030H
MAIN:
setb tcon.3
setb tcon.1
mov Ie,#10000101b
mov tmod,#10011001b
mov tl0,#0000
mov th0,#0000
setb p1.0
call delay
delay:
l1:mov r0,#1
djnz r0,l1
nop
nop
clr p1.0
end
July 21, 2011 at 9:19 pm #6489ZOBI
Participanti m makeing a project for blind person navigation
When any obstacle come in front of Ultrasonic range finder SRF04 ,they sends signal to 89C51 controller n controller vibrates the vibration motors attached to any particular area where the circuit is attached so a blind can understand that he or she is close to any obstacle , n the closer the obstacle the more vibration produce, means vibration should be inversely proportional to distance between person and obstacle,i hav made major part of the programing of this project but still want help from u people to tell me is this source code have some mistakes or not
org 0000h
ljmp main
ORG 0003H ; INT0 ISR
setb TR0 ; starts timer 0 (pin p3.2 will be connected with the pin which is giving 10 usec pulse)
ORG 0013H ; INT1 ISR
clr TRO ;stops timer 0(pin p3.3 will be connected with ECHO OUTPUT PULSE PIN of SRF04)
mov DPL,TL0 ;save the TL0 values to lower DPTR portion
mov DPH,TH0 ;save the TH0 values to upper DPTR portion
LJMp RANGE_CHECKER ;from here the DPTR value will be shifted to furhter part of this remaining programe
ORG 0030H
MAIN:
setb tcon.3 ; make INT1 edge triggerd(high-to-low) interrupt
setb tcon.1 ;make INT0 edge triggerd(high-to-low) interrupt
mov Ie,#10000101b ;enable external INT0,ITN1
mov tmod,#10011001b ;make timr to strt/stop by EXTRNAL HARDWARE,MODE 1,16 bit timers
mov tl0,#0000 ;load initial values in timer TLO
mov th0,#0000 ;load initial values in timer THO
setb p1.0 ;make pin P1.0 HIGH
call delay ;this delaywill HIGH pin P1.0 for 10 usec
delay:
l1:mov r0,#1
djnz r0,l1
nop
nop
clr p1.0
end
July 21, 2011 at 9:54 pm #6490ZOBI
Participantplz tell me that is this program is correct or it needs some more addition or correction. all the details are written in front of every command after “;” sign
ORG 0013H ; INT1 ISR
clr TR0 ;stops timer 0(pin p3.3 will be connected with ECHO OUTPUT PULSE PIN of SRF04)
mov DPL,TL0 ;save the TL0 values to lower DPTR portion
mov DPH,TH0 ;save the TH0 values to upper DPTR portion
LJMP RANGE_CHECKER ;from here the DPTR value will be shifted to furhter part of this remaining programe
RANGE_CHECKER:{{{{{{here i will write further program}}}}}}
ORG 0030H
MAIN:
setb tcon.3 ; make INT1 edge triggerd(high-to-low) interrupt
setb tcon.1 ;make INT0 edge triggerd(high-to-low) interrupt
mov Ie,#10000101b ;enable external INT0,ITN1
mov tmod,#10011001b ;make timr to strt/stop by EXTRNAL HARDWARE,MODE 1,16 bit timers
mov tl0,#0000 ;load initial values in timer TLO
mov th0,#0000 ;load initial values in timer THO
setb p1.0 ;make pin P1.0 HIGH
call delay ;this delay will HIGH pin P1.0 for 10 usec
delay:
l1:mov r0,#1
djnz r0,l1
nop
nop
clr p1.0
end -
AuthorPosts
- You must be logged in to reply to this topic.