Using Timer 1

Started by p_dubinsky April 26, 2004
Howdy folks,

I'm experimenting with an app that measures pulse widths. I'm using
the Pulsein command but the drawback is the interference with the
basicx real time clock. I'd like to use the processor's timer1 as a 16
bit timer but I have a few questions.

1. Do I understand correctly that the clock for the processor is
32.768 khz?

2. If so, does that mean that when the timer1 prescaler is set to ck
that each increment of the timer1 low register is equal to 0.0000305
seconds (1/32768)?

3. The idea is to wait for a state change on an input pin, check the
value of the timer1 counter, wait for the state to change back to the
original state, check the value of the timer1 counter again, calculate
the count delta, multiply by (1/32768) and get the elapsed time with a
1/32768 resolution. Any hope that this might work?

It seems that the only place that timer1 is used is with the PWM ops
and I have none of them.

Comments and/or guidance please.

TIA,
Paul



> ... Do I understand correctly that the clock for the processor is
32.768 khz?

No, that's incorrect. Only the Atmel 8535's Timer2 is able to use a
32KHz crystal, although that option is not available in its
implementation on the BX-24. Timer1's clock can be selected to be the
processor clock frequency (7.3728MHz), several divisions of it from
921.6KHz to 7.2KHz, or an external source on T1 (which is fed by ATN,
BX-24 pin 3). CK is 7.3728MHz on the BX-24.

> ... Any hope that this might work?

Sure, you should be able to get close using your method. You can also
start and stop the counter. Tom
Tom Becker
--... ...--
www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700



At 06:53 PM 4/26/2004, you wrote:

> > ... Do I understand correctly that the clock for the processor is
>32.768 khz?
>
>No, that's incorrect. Only the Atmel 8535's Timer2 is able to use a
>32KHz crystal, although that option is not available in its
>implementation on the BX-24. Timer1's clock can be selected to be the
>processor clock frequency (7.3728MHz), several divisions of it from
>921.6KHz to 7.2KHz, or an external source on T1 (which is fed by ATN,
>BX-24 pin 3). CK is 7.3728MHz on the BX-24.
>
> > ... Any hope that this might work?
>
>Sure, you should be able to get close using your method. You can also
>start and stop the counter.

Thanks for the clarification. This approach is working quite well. I'm
currently experimenting with different prescaler divisors but that's just
fine tuning.

I've only found one gotcha - get the low register (Register.TCNT1L) BEFORE
you get the high register (Register.TCNT1H) or the results are as they say
"unpredictable". The Atmel doc specifically states that the low register
must retrieved before you get the high register. I had missed that in the
doc and the counter values were all over the lot.

All in all, everything looks good. I get my pulse width with a resolution
well below 1 ms AND the rtc doesn't get hammered in the process.

Thanks, again,
Paul ===========================================================
"We have the power to do any damn fool thing we want to do,
and we seem to do it about every ten minutes."
J. William Fulbright , quoted in Time (New York, Feb. 4, 1952).
===========================================================

---------- ---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.665 / Virus Database: 428 - Release Date: 4/21/2004



There is an application note on using Timer1, too, I neglected to
recall, in the BX-24 documentation Appnotes, Paul. Tom
Tom Becker
--... ...--
www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700



Is there a way to use the timer 1 to get a constant square wave at 2175 Hz
on one pin and let the BX24 run the program also ?

This is for a repeater controller for a voted ham repeater.

I need a tone and will filter the square wave to a sine wave but need the
stamp to handle cos, pl, ptt and, other things at the same time.

I'm new to this Micro stuff so be gentle !

Thanks in advance,

Robert Mitchell / KD4PBC