write timer, read timer for C18

Status
Not open for further replies.

chansiuming

New Member
I am using 18F4550 series with C18 to find out the pulse. I got a sensor SRF04 which connected the Trigger to RD6 and Echo to RD7. The RD6 will send 10us pulse to Trigger and Echo will send back the pulse(distance) to RD7. Now my question is how can i count the Echo pulse? i found a post which is similar to my question but i dun understand at allhttps://www.electro-tech-online.com/threads/period-calculation-with-pic18-using-c18.107671/
I have to use Write timer and read timer? i have done the first part for opentimer:

OpenTimer0(Timer_INT_OFF &
T0_8BIT &
T0_source_INT &
T0_PS_1_1);

The Echo pulse will be between 100us to 25ms. And i am using 1MHz internal osc. I am confusing on write timer, read timer after i look through the data sheet and c compiler library... how can it function and how can i get it work to count the pulse?
 
You are wanting to measure the time between the sending and the receiving of the pulse right? Use a button to send the pulse and start the timer. Enable an external interrupt and when it is detected, turn the timer off and read the registers. If you want to see how to work with the timer library in the C18 compiler, check out my signature. But keep in mind using libraries will have some infact on your measurements.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…