hi all,
i am using pic16f887 timer0 in my program.
i want to calculate the pulse ( from external source ) to timer 0. i want to know the c code to configure the timer0 as counter.
Re: to calcute the pulse count from external source to timer
Well the code to configure timer 0 for counter mode is quite easy. But you have to be more specific about your requirements.
All that you have to do is to configure the OPTION register.
e.g
OPTION=0X28;
1.will configure the TIMER 0 for external counter mode but without any prescaler.
2.The external signal will have to be applied to T0CKI (RA4) pin.
3.The counter will increment on the LOW-HIGH transition of the external signal.
OPTION=0X38;
4.will configure the TIMER 0 for external counter mode but without any perscaler.
5.The external signal will have to be applied to T0CKI (RA4) pin.
6.The counter will increment on the HIGH-LOW transition of the external signal.
Similarly you can also configure the timer in prescaled counter mode by assigning the prescaler to the TIMER0. i.e
OPTION=0X30;
All of this information can be found on Pages 53 and 54 of the data sheet.
Hope this helps you.
If still in doubt feel free to ask questions.
Re: to calcute the pulse count from external source to timer
Here is the project to detect an external pulse within a specified time. The code operates in a cyclic manner and each time a pulse is detected within the specified time a flag is set, otherwise it is cleared. The Proteus file for simulating the project is also included.
Regards.