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.

[51] duration b/w two interrupts

Status
Not open for further replies.

niteshtripathi

Member level 3
Joined
Oct 11, 2013
Messages
59
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
429
hi friends gdmng, i am working on project named "HIGHWAY SPEED CHECKER", i am using 8051 and c language, i have use two obstacle detector using IR whose o/p i have connected at INT0 and INT1, i have used timers 0 in MODE1, as first interrupr is detected i have started the timer, after the detection of second interrupt i have stopped the timer, now i have to calculate the total time, how can i calculate the total count means TH0 and TL0, may be in b/w both interrupts TH0 and TL0 overflows then hows???
 

Hi write a Timer interrupt and increment a another variable there.... with your known crystal frequency you can easily calculate the time elapsed, with time in hand you can easily calculate the speed as well....
 

getting prob...pls help

Hi write a Timer interrupt and increment a another variable there.... with your known crystal frequency you can easily calculate the time elapsed, with time in hand you can easily calculate the speed as well....
 

TIMER_FREQ = XTAL_FREQ / 12;
time = ( timer_ovf_variable * (TH0<<8 | TLO) ) / (float)TIMER_FREQ; time in sec (float)
distance = known; in mtrs
speed = distance / time; //in mps
speed = speed * 3600 / 1000; // in kph

for more assistance post your full code
 

and you cannot judge the time between two interrupt bcoz when interrupt occur that time high priority interrupt get serviced and low priority intrrupt get hold. so there is no time and if you are using timer interrupt then intrupt will continuelly occur.
 

hw do you calculate this duration in micro c using PIC 16f877 with a 20mhz oscillator
 

Timer Delay Calculations used
1. Crystal Source Frequency Fosc (
2. Timer Frequency Ftimer = Fosc / 4
3. Using a Prescalar , then
Ftimer = Ftimer / scalar value
4. Time Interval Ttimer = 1/Ftimer
5. To calculate the value to be filled in Timer rolling over
register to generate 1 sec delay :
No of count for 1 sec delay = 1 s / Ttimer
6. So the value to be filled in Timer’s 16 bit register
 

suppose your timer interrupt is for 500 ms then use a counter and increment it on every timer interrupt

When sensor1 detects vehicle start timer

when sensor2 detects vehicle stop timer


now let us assume counter value is 3 then it means 3 * 500 = 1500 ms has passed

now the remaining time after 3 timer interrupt should be calculated from the remaining value of TMRH and TMRL registers. You should get that in sec and add it to 3 * 500 ms.

lets say you get 1700 ms = 1.7 sec then if distance between two pairs of sensors is 10 meters

then speed = distance / time = 10 m

Fosc = 4 MHz
TMR OSC = Fosc /4 = 4 MHz / 4 = 1 MHz
Prescalar = 1:1

TMR OSC = TMR OSC / Prescalar = 1 MHz / 1 = 1 MHz

Timer interval = 1 / TMR OSC = 1 / 1 MHz = 10 us

every 10 ms the timer value decrements

lets say timer value was 65200, so, timer counts 65200 and then overflows to 0 and timer interrupt occurs. After that timer is reloaded with 65200 for another count.


If remaining count in TMR register is 36128 then

1 tick = 10 us
65200 - 36128 = 29072

29072 * 10 us = 290720 us = 0.29072 sec = approx 290 ms

so, 3 * 500 ms + 290 ms = 1500 ms + 290 ms = 1790 ms.eters / 1.7 sec = 5.882352941176471 meters/sec
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top