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.

to calcute the pulse count from external source to timer0

Status
Not open for further replies.

VINITA DHAMELE

Newbie level 6
Newbie level 6
Joined
May 20, 2010
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,380
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.

Regards.
 
Re: to calcute the pulse count from external source to timer

thanks
i need to run timer for 1/3 second and check if a single pulse from external source has occured then set a flag.

my code is to iniitialize counter:

Code:
setup_timer_0 ( RTCC_DIV_256 | RTCC_EXT_H_TO_L);
set_rtcc ( TIMER_VALUE );     //TIMER_VALUE = 0
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);

as per this code timer0 overflows every 131ms ( internal osc 2 MHz).
but i am unable to latch that condition ( set a flag) at occurence of pulse...

please help me to write a proper code for this application.

i am using ccs c compiler in MPLAB IDE..
regards[/code]
 

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.
 
  • Like
Reactions: fotso

    VINITA DHAMELE

    Points: 2
    Helpful Answer Positive Rating

    fotso

    Points: 2
    Helpful Answer Positive Rating
Re: to calcute the pulse count from external source to timer

Thanks
Sorry for late reply.
This helped me a lot.
I have fixed my problem.

Regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top