Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC CCP (Capture mode) how to capture time like stopwatch?

Status
Not open for further replies.

sysysy

New Member
How to use the PIC capture mode to capture time? (ultrasonic sensor)
Hi,

I'm doing a project and have been built up the ultrasonic receiver circuit.
Also, i use my PIC to transmit the 40Khz signal go out through the ultrasonic transmitter. If there is a obstacle, the 40Khz sound wave will be reflect back.
The reflected 40khz signal will be received by the ultrasonic receiver sensor and then amplified by 1000 times, then will pass through the peak detector circuit. Finally, comparator used to recognize whether there is a 40khz signal come in or not, and then the output of the comparator will direct connect to the micro-controller (PIC 16F877A).

But, i have face some problem here.
To calculate the how much the distance between the obstacle and my sensor, i need time in the calculation (since speed of sound is around 340m/s)

So, once i transmit out the 40khz from my PIC, i should immediately start the timer and once the PIC pin trigger that the signal come in, the timer also should immediately stop. So that this period of time can be used in the calculation.

But the problem is how to capture this period of time? some ppl ask me to use ccp mode to do this. But i even dunno how to start. can anyone give me details step. Instead of setup the ccp, i really wish to know what is the concept to capture this period of time.

Thanks a lot.
 
I think you would be better off using a timer rather than the CCP module.

Basically:
> Send out your pulses
> Set a timer to count
> Either poll the comparator output or set up an external interrupt to trigger when the comparator output goes high
> When the comparator output goes high, disable the timer and read the value


Edit: you will also probably need a timeout period. i.e. if no response is received in 200 milliseconds (for example) then stop waiting for the response (no objects detected).
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top