EmbeddedRelated.com
Forums

Frequency Measurement Using Capture

Started by nugent2007 June 18, 2007
I would appreciate a sanity check on using TimerA in capture mode. I
will be doing simple frequency measurement on a low frequency (200Hz
Max) input to a capture pin. I have set the timer to:

continous up mode
clock from ACLK (32KHz)
positive edge detect

Some questions:

The timer will interrupt both on a capture event and an overflow? If
so I suppose i have to handle over flow...

I read TAIV in the ISR to determine interrupt source? I read TAIV
into a variable now but it always reads zero..

Would it make sense to clear TAR on the first edge and the capture a
second or just record TACCRx and subtract the first from the second?

Will the timer maintain it settings through an interrupt? In other
words do I need to reset any flags or settings in the ISR?

The input signal is asynchronous, is it then necessary to set the SCS
bit in TACCTLx?

Thanks for the help

Mike

Beginning Microcontrollers with the MSP430

Hi,

> The timer will interrupt both on a capture event and an overflow? If
> so I suppose i have to handle over flow...

You will only get interrupts for enabled sources. If you leave the overflow disabled,
you don't get an interrupt (and you don't need it anyway)

> I read TAIV in the ISR to determine interrupt source? I read TAIV
> into a variable now but it always reads zero..

You only need TAIV if you use TA1 or TA2.
TAIV = 0 means "no interrupt" (or spurious INT). Are you using TA0 perhaps ?
If so, you don't need TAIV.

> Would it make sense to clear TAR on the first edge and the capture a
> second or just record TACCRx and subtract the first from the second?

Is MCLK asynchronous ? Or is it same as ACLK ?
If MCLK is different from timer clock, you can't simply read TAR. You must account for async
(it could be read wrong). Norma;lly you either read TAR until you have 2 equal reads, or you stop
TAR while you read.
I wouldn't touch TAR in any case, let it run.
Just use TACCRx and then subtract (make sure it's a _unsigned_ subtract!)

> Will the timer maintain it settings through an interrupt? In other
> words do I need to reset any flags or settings in the ISR?

The timer settings remain - that is - the configuration ones.
Since you're in continuous up mode, just let it roll.
You're only interested in the capture events.

HTH
Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of nugent2007
Sent: Tuesday, 19 June 2007 3:27 AM
To: m...
Subject: [msp430] Frequency Measurement Using Capture

I would appreciate a sanity check on using TimerA in capture mode. I
will be doing simple frequency measurement on a low frequency (200Hz
Max) input to a capture pin. I have set the timer to:

continous up mode
clock from ACLK (32KHz)
positive edge detect

Some questions:

The timer will interrupt both on a capture event and an overflow? If
so I suppose i have to handle over flow...

I read TAIV in the ISR to determine interrupt source? I read TAIV
into a variable now but it always reads zero..

Would it make sense to clear TAR on the first edge and the capture a
second or just record TACCRx and subtract the first from the second?

Will the timer maintain it settings through an interrupt? In other
words do I need to reset any flags or settings in the ISR?

The input signal is asynchronous, is it then necessary to set the SCS
bit in TACCTLx?

Thanks for the help

Mike

Yahoo! Groups Links
Kris,
Thanks for the help, I was making it too complicated. I toggle a
flag each time through the ISR. On the second trip I subract the
previous capture from TACCR0, unless the previous capture is larger
which would indicate that the timer rolled over. This works fine.

I still read TAIV as being 0x0000 when I enter the ISR, still a mystery.

Thanks again for the help.

Mike

--- In m..., "Microbit" wrote:
>
> Hi,
>
> > The timer will interrupt both on a capture event and an overflow? If
> > so I suppose i have to handle over flow...
>
> You will only get interrupts for enabled sources. If you leave the
overflow disabled,
> you don't get an interrupt (and you don't need it anyway)
>
> > I read TAIV in the ISR to determine interrupt source? I read TAIV
> > into a variable now but it always reads zero..
>
> You only need TAIV if you use TA1 or TA2.
> TAIV = 0 means "no interrupt" (or spurious INT). Are you using TA0
perhaps ?
> If so, you don't need TAIV.
>
> > Would it make sense to clear TAR on the first edge and the capture a
> > second or just record TACCRx and subtract the first from the second?
>
> Is MCLK asynchronous ? Or is it same as ACLK ?
> If MCLK is different from timer clock, you can't simply read TAR.
You must account for async
> (it could be read wrong). Norma;lly you either read TAR until you
have 2 equal reads, or you stop
> TAR while you read.
> I wouldn't touch TAR in any case, let it run.
> Just use TACCRx and then subtract (make sure it's a _unsigned_
subtract!)
>
> > Will the timer maintain it settings through an interrupt? In other
> > words do I need to reset any flags or settings in the ISR?
>
> The timer settings remain - that is - the configuration ones.
> Since you're in continuous up mode, just let it roll.
> You're only interested in the capture events.
>
> HTH
> Best Regards,
> Kris
>
> -----Original Message-----
> From: m... [mailto:m...] On
Behalf Of nugent2007
> Sent: Tuesday, 19 June 2007 3:27 AM
> To: m...
> Subject: [msp430] Frequency Measurement Using Capture
>
> I would appreciate a sanity check on using TimerA in capture mode. I
> will be doing simple frequency measurement on a low frequency (200Hz
> Max) input to a capture pin. I have set the timer to:
>
> continous up mode
> clock from ACLK (32KHz)
> positive edge detect
>
> Some questions:
>
> The timer will interrupt both on a capture event and an overflow? If
> so I suppose i have to handle over flow...
>
> I read TAIV in the ISR to determine interrupt source? I read TAIV
> into a variable now but it always reads zero..
>
> Would it make sense to clear TAR on the first edge and the capture a
> second or just record TACCRx and subtract the first from the second?
>
> Will the timer maintain it settings through an interrupt? In other
> words do I need to reset any flags or settings in the ISR?
>
> The input signal is asynchronous, is it then necessary to set the SCS
> bit in TACCTLx?
>
> Thanks for the help
>
> Mike
>
> Yahoo! Groups Links
>
> I still read TAIV as being 0x0000 when I enter the ISR, still a mystery.

If you are using TACCRO then you don't need TAIV, as below.
TAIV is only needed when you use a vector for multiple sources : TACC1, TACCR2, overflow.
TA0 is a separate interrupt vector from TA1/TA2/OVF.

Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of nugent2007
Sent: Wednesday, 20 June 2007 8:56 AM
To: m...
Subject: [msp430] Re: Frequency Measurement Using Capture

Kris,
Thanks for the help, I was making it too complicated. I toggle a
flag each time through the ISR. On the second trip I subract the
previous capture from TACCR0, unless the previous capture is larger
which would indicate that the timer rolled over. This works fine.

I still read TAIV as being 0x0000 when I enter the ISR, still a mystery.

Thanks again for the help.

Mike

--- In m..., "Microbit" wrote:
>
> Hi,
>
> > The timer will interrupt both on a capture event and an overflow? If
> > so I suppose i have to handle over flow...
>
> You will only get interrupts for enabled sources. If you leave the
overflow disabled,
> you don't get an interrupt (and you don't need it anyway)
>
> > I read TAIV in the ISR to determine interrupt source? I read TAIV
> > into a variable now but it always reads zero..
>
> You only need TAIV if you use TA1 or TA2.
> TAIV = 0 means "no interrupt" (or spurious INT). Are you using TA0
perhaps ?
> If so, you don't need TAIV.
>
> > Would it make sense to clear TAR on the first edge and the capture a
> > second or just record TACCRx and subtract the first from the second?
>
> Is MCLK asynchronous ? Or is it same as ACLK ?
> If MCLK is different from timer clock, you can't simply read TAR.
You must account for async
> (it could be read wrong). Norma;lly you either read TAR until you
have 2 equal reads, or you stop
> TAR while you read.
> I wouldn't touch TAR in any case, let it run.
> Just use TACCRx and then subtract (make sure it's a _unsigned_
subtract!)
>
> > Will the timer maintain it settings through an interrupt? In other
> > words do I need to reset any flags or settings in the ISR?
>
> The timer settings remain - that is - the configuration ones.
> Since you're in continuous up mode, just let it roll.
> You're only interested in the capture events.
>
> HTH
> Best Regards,
> Kris
>
> -----Original Message-----
> From: m... [mailto:m...] On
Behalf Of nugent2007
> Sent: Tuesday, 19 June 2007 3:27 AM
> To: m...
> Subject: [msp430] Frequency Measurement Using Capture
>
> I would appreciate a sanity check on using TimerA in capture mode. I
> will be doing simple frequency measurement on a low frequency (200Hz
> Max) input to a capture pin. I have set the timer to:
>
> continous up mode
> clock from ACLK (32KHz)
> positive edge detect
>
> Some questions:
>
> The timer will interrupt both on a capture event and an overflow? If
> so I suppose i have to handle over flow...
>
> I read TAIV in the ISR to determine interrupt source? I read TAIV
> into a variable now but it always reads zero..
>
> Would it make sense to clear TAR on the first edge and the capture a
> second or just record TACCRx and subtract the first from the second?
>
> Will the timer maintain it settings through an interrupt? In other
> words do I need to reset any flags or settings in the ISR?
>
> The input signal is asynchronous, is it then necessary to set the SCS
> bit in TACCTLx?
>
> Thanks for the help
>
> Mike
>
> Yahoo! Groups Links
>

Yahoo! Groups Links