CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Programming the Timer1 on the PIC16F877

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
McCray D
Guest







Programming the Timer1 on the PIC16F877
PostPosted: Thu Apr 10, 2003 2:44 pm     Reply with quote

I am trying use the timer1 on the pic to count the amount of time that passes when a certain pin goes high then low. I need the timer to start when the pin goes high and stop when the pin goes low. This timing program will be used to time the pulse coming from a SRF04 ultrasonic sensor.
thanks for any help.
mccray d
___________________________
This message was ported from CCS's old forum
Original Post ID: 13592
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Programming the Timer1 on the PIC16F877
PostPosted: Thu Apr 10, 2003 2:53 pm     Reply with quote

:=I am trying use the timer1 on the pic to count the amount of time that passes when a certain pin goes high then low. I need the timer to start when the pin goes high and stop when the pin goes low. This timing program will be used to time the pulse coming from a SRF04 ultrasonic sensor.
------------------------------------------------------------

The CCP module will do the edge detection and capture of the
Timer1 value for you. It's done in hardware, instead of by
code. See the CCS example file EX_CCPMP.C.
This file is in the c:\Program Files\Picc\Examples folder.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13593
Rollo
Guest







Re: Programming the Timer1 on the PIC16F877
PostPosted: Sat Apr 12, 2003 6:13 pm     Reply with quote

:=I am trying use the timer1 on the pic to count the amount of time that passes when a certain pin goes high then low. I need the timer to start when the pin goes high and stop when the pin goes low. This timing program will be used to time the pulse coming from a SRF04 ultrasonic sensor.
:=thanks for any help.
:=mccray d

If you don't want to use CPP to do the job, you might want to look at doing it in a simpler way, depending on your needs. You'd have to initialize the timer1, but something like this does work. I use it to measure the pulsewidth time elapsed on a light sensor.


while( input(PIN_B7));
while(!input(PIN_B7));
while( input(PIN_B7)); // if going from down to up.

set_timer1(0); // set timer to zero
enable_interrupts(GLOBAL);

while(!input(PIN_B7)); // if low now.. wait
while( input(PIN_B7)); // when it gets high again, count time.

disable_interrupts(INT_TIMER1);

tiks = get_timer1(); // get the time elapsed

Depends as well on the range of times you'd wish to measure, as it is possible you might need an interrupt routine to measure the number of timer1 overflows. That would allow you to measure longer times.

later,
Rol
___________________________
This message was ported from CCS's old forum
Original Post ID: 13632
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group