PDA

View Full Version : Time Measuring



peterson
- 10th May 2006, 22:07
Hello
I have bought a hall effect sensor (UGN3113).I want to measure with PIC16F628 the time between hall sensor triggers.How I can do that?
Can anyone help me about time measuring with TMR?
I wait for helpfull suggestions.
Thanks alot.

ErnieM
- 17th May 2006, 21:50
How long is the interval? Microseconds? Seconds? Hours? Years?

As the time gets longer, it gets easier as the accuracy issues tend to go to zero.

For short intervals, I've done things like clear the timer counter (TMRx) internal to the PIC on the first pulse, interupt or poll for the 2nd pulse and at that time read the TMRx value. I'll feed TMRx with the PIC clock so its an accurate count of time.

For long intervals, make a loop of a length suitable (seconds, hours, ect) and check inputs as above, keep the time in a register.

J. Mark Wolf
- 18th May 2006, 13:00
I've implemented tachometers with Hall effect sensors, using the PULSIN command. Works very well.

peterson
- 20th May 2006, 16:41
Dear ErnieM
Thanks alot for replying my qyestion. I am going to use ugn3113 for measuring the time of every complete wheel revolution.I use this time for controlling the other section of plant.The maximum time of interval is about 0.8 sec.Can you help me for writing basic code for this part of my program?

peterson
- 20th May 2006, 16:55
Hi dear J. Mark Wolf

thanks alot
thr pulsin command is very good for use but i have a question.Does this instruction work in the background of main program? This means that can PIC execue other instructions in main program when the PULSIN command is executed at the same time.

mister_e
- 20th May 2006, 17:22
If you need something running in background, you need to use internal Timer or CCP module or something like that. Now it works in background.

With interrupts it will work great. Start a timer on rising edge of your signal and stop it on the next. OR, use a prescaller to get some sample of it, then divide it by the prescaller value. That way you may avoid some odd results.

read the following document
http://ww1.microchip.com/downloads/en/DeviceDoc/41214a.pdf