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.

How to calculate time between two interrupts in ms

Status
Not open for further replies.

Amalinda

Banned
Joined
Sep 25, 2012
Messages
104
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,298
Activity points
0
I am using a laser connected to some logic circuit to make a 1--> 0--> 1 in the logic when a person goes in between the laser and the LDR.

I am counting the time till the second person comes in. That means when the second person comes in the timer must stop. i.e. when the output of the external circuit goes again from 1-->0 ---> 1.

I want to calculate the time between these events using a PIC16f77A or 18F.

I would prefer a 16F877A.

Please if anyone knows how to do the coding to this I would really appreciate.

I would prefer if the coding is in micro C Pro for PIC version.
but even if its in Assembly I can totally understand.

thank you a lot in advance.
 

Essentially you are timing the duration of a pulse created by the beams interruption.

Using a timer in capture mode would probably be the most effective method.

**broken link removed**


BigDog
 

hi, i think you can use the portB and timer0 interrupts for this. your external circuit will trigger the port b interrupt and you can activate a software timer when this happens. timer0 can then be used to increment a variable at a constant rate, from which you can calculate the time which has elapsed since the software timer was activated. you can check the data sheet on how to configure timer0. for example, if you configure timer0 to cause an interrupt and increment a variable every 10ms, you calculate the time which has elapsed by multiplying the value of the variable by 10ms. when port b changes state again (person has already passed through the sensor), the software timer stops/resets.

i just saw bigdogguru's post as I was about to post this, i think his idea is better :grin: haven't really used the capture mode so it didn't occur to me immediately :lol: but i think the concept is the same, you calculate the actual time by scaling a counter variable
 

my ***. This forum is amaizing. You people are amaizingly helpfull. This is exactly what i wanted. I will try definitely try both these methods. Thank you. I appreciate the two different approaches. It's more experience.

- - - Updated - - -

thank you. It's my first time receiving help from this forum and it feels amaizing. You guys rock helping out. Simply i love both methods mentioned. I will try both. Thanks.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top