View previous topic :: View next topic |
Author |
Message |
McCray D Guest
|
Programming the Timer1 on the PIC16F877 |
Posted: Thu Apr 10, 2003 2:44 pm |
|
|
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
|
Re: Programming the Timer1 on the PIC16F877 |
Posted: Thu Apr 10, 2003 2:53 pm |
|
|
:=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 |
Posted: Sat Apr 12, 2003 6:13 pm |
|
|
:=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 |
|
|
|