Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Measuring time on a pic16f628a

Status
Not open for further replies.

normad

Member
Hey, i need to measure the time an input is high.. im using an external clock on pins RA6 and RA7.. i know how to use timer0 module but the maximum prescalar is 32.. can someone give me some hints..
 
Hey, i need to measure the time an input is high.. im using an external clock on pins RA6 and RA7.. i know how to use timer0 module but the maximum prescalar is 32.. can someone give me some hints..

hi,
What time periods are you measuring?
eg: msec, secs, mins
 
anything from .1 second to .5 should be fine.. im using a 4Mhz crystal.. andmy code is written using hitech c free version bundled with mplab..
 
and could you explain how the timer modules actually function? do they work directly from the clock signal? or does timer1 depend on timer0 and likewise? datasheets say something about them needing to be synchronized if you're using an external clock.. im quite lost :S please help :(
 
and could you explain how the timer modules actually function? do they work directly from the clock signal? or does timer1 depend on timer0 and likewise? datasheets say something about them needing to be synchronized if you're using an external clock.. im quite lost :S please help :(

hi,
I dont use the 'C' language.
If you can follow assembler coding I could post a sample program, which you could convert to 'C'.
 
oh its alryt :) thanks anyways.. i figured out most of my questions from a book.. could you please tell me if theres a bit configuration where i can have timer0 as the source of timer 1 or 2? or any other way i can scale down the 4Mhz clock signal to the mili second level without software interference(using timers)
 
oh its alryt :) thanks anyways.. i figured out most of my questions from a book.. could you please tell me if theres a bit configuration where i can have timer0 as the source of timer 1 or 2? or any other way i can scale down the 4Mhz clock signal to the mili second level without software interference(using timers)

As you may know the 4mHz clock is divided by 4 in the PIC to create a 1mHz [1uSec] internal clock
Usually timer1 or timer2 are used for software division to give a lower clock rate.
Iwould use timer1, set the prescaler to 1:8 so the prescaled clock would be 125kHz [8uSec] and then preload timer2 to give interruputs upto as long as 0.524secs.

If you want to do it in external hardware you could use a 32.768kHz external crystal on timer0 as the osc/counter.
 
thanks :) i think i got it to work.. i figured that timer 1 is 16 bit so you can scale down the interrupt a lot. i used prescalar 8 and set the timer to 53036 so it generates interrupt every .1s.. and im using timer0 for some other purpose.. is there any restriction in using both the timers at the same time?
 
thanks :) i think i got it to work.. i figured that timer 1 is 16 bit so you can scale down the interrupt a lot. i used prescalar 8 and set the timer to 53036 so it generates interrupt every .1s.. and im using timer0 for some other purpose.. is there any restriction in using both the timers at the same time?

hi,
The Timers can be used at the same, but if you use timers for interrupts [ISR] you will need to test the flags to determine which timer is causing the interrupt.
In my post #8, this should have said,,,and then preload timer1 to give interruputs, not timer2, just a typo
 
Status
Not open for further replies.

Latest threads

Back
Top