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.

PWM width measurement in PIC16F877A

Status
Not open for further replies.

tinto

Junior Member level 2
Joined
Mar 23, 2011
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Kerala, India
Activity points
1,413
I am a beginner in PIC. I need to measure the width of a pulse coming from an ultrasonic sensor using the capture mode. The duration of the pulse vary from 0 to 30ms. How can I do that? I am using PIC16F877A and microC compiler.
 

You need not really use the CAPTURE mode. Poll the input line for low or high going edge, clear TMR1 and start the TMR1. Next poll for the other edge and stop the timer. If you need more than 16 bits. enable TMR1 overflow interrupt and have another 8 bits register increment in the interrupt. This will give you 24 bits resolution.

Cheers

Ravi
 
  • Like
Reactions: tinto

    tinto

    Points: 2
    Helpful Answer Positive Rating
Thank you. It works. But which method is the best? Polling or the capture method? Which metod will give better accuracy?
 

Thank you. It works. But which method is the best? Polling or the capture method? Which metod will give better accuracy?

It all depends on the overhead that you have. If the PICmicro is busy doing other tasks, use capture method. If it has enough free time, use polling methog.

Cheers

Ravi
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top