EmbeddedRelated.com
Forums

MSP430f2252 Capture time

Started by Claro Louie December 11, 2007
Hi guys,

I need some pointers on what is the best way on how to synchronize my clock with an input signal. Here's a situation. I have a relay that is connected to my microcontroller (MSP430F2252). I want to detect if the opening or closing of the relay is slower than the allotted time for it to open or close. i'm thinking of using the capture mode of the timerA of my microcontroller. Can you confirm if the settings below of the timerA are correct?
How can I capture the time for the input to change state like from 1 to 0 or 0 to 1? The pin connection is at P2.2.

WDTCTL = WDTPW + WDTHOLD;

TACTL = TASSEL_1 + ID_1 + MC_1 + TAIE;
TACCTL0 = CAP + CM_3 + CCIS_1 + SCS +CCIE;

Is there other ways that you can suggest on how to implement this effectively?

thanks and regards,

Claro

---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

Beginning Microcontrollers with the MSP430

I would use all 3 CC modules. One on compare mode and the other two on
capture. With compare you can switch the relay on and off and with
capture you can know exactly how much time the opening and closing takes.

TimerA in continuous mode.
TA0 on compare mode, output TOGGLE. (TACCR0 = 0x0001 for example)
TA1 on capture, rising edge.
TA2 on capture, falling edge.

Opening time = TACCR1 - TACCR0
Closing time = TACCR2 - TACCR0
(depending on your hardware configuration for driving and sensing the
relay)

I hope you get the idea. This is the simpliest and most exact approach
I can think of. I guess you only want to measure the time once. You
could use TA1 for both rising and falling edge if you need to
continualy measure the time and want to spare one pin.

Regards,
Michael Kusch
--- In m..., Claro Louie wrote:
>
> Hi guys,
>
> I need some pointers on what is the best way on how to synchronize
my clock with an input signal. Here's a situation. I have a relay that
is connected to my microcontroller (MSP430F2252). I want to detect if
the opening or closing of the relay is slower than the allotted time
for it to open or close. i'm thinking of using the capture mode of the
timerA of my microcontroller. Can you confirm if the settings below of
the timerA are correct?
> How can I capture the time for the input to change state like from
1 to 0 or 0 to 1? The pin connection is at P2.2.
>
>
> WDTCTL = WDTPW + WDTHOLD;
>
> TACTL = TASSEL_1 + ID_1 + MC_1 + TAIE;
> TACCTL0 = CAP + CM_3 + CCIS_1 + SCS +CCIE;
>
> Is there other ways that you can suggest on how to implement this
effectively?
>
> thanks and regards,
>
> Claro
>
>
>
> ---------------------------------
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile.
Try it now.
>
>
>
thanx for your pointers.. i'll work this out...

One Stone wrote: This isn't straight forward, since the relay contacts will bounce. You
will need to time the debounce too. if your aim is to characterise the
relay performance then the simplest way, without using alll timers is to
set Timer A to continuous mode, source the clock from high frequency,
then set the pin connected to the contact to capture on any edge. I
would arrange this to be Timer_A0 if possible as this reduces the
interrupt latency. DO NOT use a watch crystal as the timer source as
this is too slow.

Enable timer overflow interrupts and so that there is a reasonable
period between operations count N entries to the overflow ISR before
toggling the relay.

On entry to ther A0 ISR latch the pin state as the first instruction on
entry. this will tell you the activating edge. track the last edge. This
allows you to determine if a very fast transition occurrd and you missed
a bounce. Store TAR to an array. If an edge is missed then skip that
storage location. this leaves noice orderly memory logs where even word
entries are (say) rising edges, and odd word entries are falling edges.

Cheers

Al

Claro Louie wrote:

>Hi guys,
>
> I need some pointers on what is the best way on how to synchronize my clock with an input signal. Here's a situation. I have a relay that is connected to my microcontroller (MSP430F2252). I want to detect if the opening or closing of the relay is slower than the allotted time for it to open or close. i'm thinking of using the capture mode of the timerA of my microcontroller. Can you confirm if the settings below of the timerA are correct?
> How can I capture the time for the input to change state like from 1 to 0 or 0 to 1? The pin connection is at P2.2.
> WDTCTL = WDTPW + WDTHOLD;
>
> TACTL = TASSEL_1 + ID_1 + MC_1 + TAIE;
> TACCTL0 = CAP + CM_3 + CCIS_1 + SCS +CCIE;
>
> Is there other ways that you can suggest on how to implement this effectively?
>
> thanks and regards,
>
> Claro
>
>---------------------------------
>Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
>
>
>
hi guys,
May we raise additional questions regarding the capture time?

Can we use only one Timer_A capture/compare like TACCR0 only to capture successive signals? This is because were using just one pin (p2.2) of the 2252 as my input pin for the capture time of one signal. If so, how can I subtract the current capture value from the previous capture value? My understanding of subtracting the current and previous capture value is like subtracting two Timer_A capture/compare e.i. TACCR1 - TACCR0.
If the input signal is an analog signal, how can we synchronize the capture time with the analog input signal? We have an idea of letting the analog signal pass through the ADC10 module, then letting the timerA capture the signal coming from the ADC10. Can we capture the time between there is no signal yet and upon presence of the analog signal. We have read from the user guide that capture inputs CCIxA and CCIxB can be connected to internal signals by selecting the CCISx bits. Can you verify if this is effective?

thanks and regards,

claro

tintronic wrote:
I would use all 3 CC modules. One on compare mode and the other two on
capture. With compare you can switch the relay on and off and with
capture you can know exactly how much time the opening and closing takes.

TimerA in continuous mode.
TA0 on compare mode, output TOGGLE. (TACCR0 = 0x0001 for example)
TA1 on capture, rising edge.
TA2 on capture, falling edge.

Opening time = TACCR1 - TACCR0
Closing time = TACCR2 - TACCR0
(depending on your hardware configuration for driving and sensing the
relay)

I hope you get the idea. This is the simpliest and most exact approach
I can think of. I guess you only want to measure the time once. You
could use TA1 for both rising and falling edge if you need to
continualy measure the time and want to spare one pin.

Regards,
Michael Kusch
--- In m..., Claro Louie wrote:
>
> Hi guys,
>
> I need some pointers on what is the best way on how to synchronize
my clock with an input signal. Here's a situation. I have a relay that
is connected to my microcontroller (MSP430F2252). I want to detect if
the opening or closing of the relay is slower than the allotted time
for it to open or close. i'm thinking of using the capture mode of the
timerA of my microcontroller. Can you confirm if the settings below of
the timerA are correct?
> How can I capture the time for the input to change state like from
1 to 0 or 0 to 1? The pin connection is at P2.2.
>
>
> WDTCTL = WDTPW + WDTHOLD;
>
> TACTL = TASSEL_1 + ID_1 + MC_1 + TAIE;
> TACCTL0 = CAP + CM_3 + CCIS_1 + SCS +CCIE;
>
> Is there other ways that you can suggest on how to implement this
effectively?
>
> thanks and regards,
>
> Claro
>
>
>
> ---------------------------------
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile.
Try it now.
>
>
>




---------------------------------
Never miss a thing. Make Yahoo your homepage.





THESE ARE TWO SEPARTE ISSUES.

iN THE FIRST CASE YOU SIMPLY SET UP CAPTURE MODE ON THE RISING EDGE,
THEN HAVE THE isr STORE (whoops) that time and flip the edge bit so that
the next capture occurs on the falling edge.

declare a few 16 bit stores:-

ORG RAMSTART
Old Time DS 2
Mark DS 2
Space DS 2
Period DS 2
TIMERA0_ISR:
BIC #CCIFG,&CCTL0 ;'CLEAR INTERRUPT
MOV &CCR0,R4 ;COPY CAPTURED TIME
SUB &OldTime,R4 ;CALCULATE TIME
DIFFERENCE
XOR #CM_3,&CCTL0 ;FLIP THE NEXT EDGE SENSE
MOV &CCR0,&OldTime ;SAVE THE LATEST READING
BIT #CM0,&CCIE ;SEE WHICH EDGE ACTS NEXT
JZ WAS_RISING ;WE GOT HERE ON A
RISING EDGE
MOV R4,&Mark ;WE GOT HER ON A
FALLING EDGE
JMP TA0_EXIT
WAS_RISING:
MOV R4,&Space
MOV R4,&Period
ADD &Mark,&Period ;DUTY CYCLE = MARK/PERIOD*100
TA0_EXIT:
RETI

You could also set the interrupt to trigger on either edge, but then you
risk losing the triggering edge on a very fast pulse, b cause it has to
be explicitly determined from the pin state. Ok tis can be done through
the CCTlx register but I think the method above is clear and complete.
Asd for synchronising analog and capture times you have two basic
options. Either trigger the ADC conversion from the timer, as described
in the FUG, or use the ADC isr and grab the value of TAR immediately on
entry to the ADC ISR. Not quite as accurate since latency has a 6 cycle
jitter on it, but simpler for some operations.

Cheers

Al

Claro Louie wrote:

>hi guys,
> May we raise additional questions regarding the capture time?
>
> Can we use only one "Timer_A capture/compare" like TACCR0 only to capture successive signals? This is because we're using just one pin (p2.2) of the '2252 as my input pin for the capture time of one signal. If so, how can I subtract the current capture value from the previous capture value? My understanding of subtracting the current and previous capture value is like subtracting two "Timer_A capture/compare" e.i. TACCR1 - TACCR0.
> If the input signal is an analog signal, how can we synchronize the capture time with the analog input signal? We have an idea of letting the analog signal pass through the ADC10 module, then letting the timerA capture the signal coming from the ADC10. Can we capture the time between there is no signal yet and upon presence of the analog signal. We have read from the user guide that capture inputs CCIxA and CCIxB can be connected to internal signals by selecting the CCISx bits. Can you verify if this is effective?
>
> thanks and regards,
>
> claro
>
>tintronic wrote:
> I would use all 3 CC modules. One on compare mode and the other two on
>capture. With compare you can switch the relay on and off and with
>capture you can know exactly how much time the opening and closing takes.
>
>TimerA in continuous mode.
>TA0 on compare mode, output TOGGLE. (TACCR0 = 0x0001 for example)
>TA1 on capture, rising edge.
>TA2 on capture, falling edge.
>
>Opening time = TACCR1 - TACCR0
>Closing time = TACCR2 - TACCR0
>(depending on your hardware configuration for driving and sensing the
>relay)
>
>I hope you get the idea. This is the simpliest and most exact approach
>I can think of. I guess you only want to measure the time once. You
>could use TA1 for both rising and falling edge if you need to
>continualy measure the time and want to spare one pin.
>
>Regards,
>Michael Kusch
>--- In m..., Claro Louie wrote:
>
>
>>Hi guys,
>>
>>I need some pointers on what is the best way on how to synchronize
>>
>>
>my clock with an input signal. Here's a situation. I have a relay that
>is connected to my microcontroller (MSP430F2252). I want to detect if
>the opening or closing of the relay is slower than the allotted time
>for it to open or close. i'm thinking of using the capture mode of the
>timerA of my microcontroller. Can you confirm if the settings below of
>the timerA are correct?
>
>
>>How can I capture the time for the input to change state like from
>>
>>
>1 to 0 or 0 to 1? The pin connection is at P2.2.
>
>
>>WDTCTL = WDTPW + WDTHOLD;
>>
>>TACTL = TASSEL_1 + ID_1 + MC_1 + TAIE;
>>TACCTL0 = CAP + CM_3 + CCIS_1 + SCS +CCIE;
>>
>>Is there other ways that you can suggest on how to implement this
>>
>>
>effectively?
>
>
>>thanks and regards,
>>
>>Claro
>>
>>---------------------------------
>>Be a better friend, newshound, and know-it-all with Yahoo! Mobile.
>>
>>
>Try it now.
>
>
>>
>>
>>
>>
>
>
>---------------------------------
>Never miss a thing. Make Yahoo your homepage.
>
>
>
>
>
A couple of things:
- You either use timer-hardware-capture and a digital input signal, OR
you use the ADC10 and timer-software-capture.
- The capture signal for the timer is a "digital input". It does not
see an analog signal. It's either read as a 0 or as a 1. The capture
will occur on the transition between these two levels.
- If you put the signal through the ADC10, what you will get is not a
digital signal, but a 10-bit value. No way to feed it into the timer's
capture, except by software.
-It's not that CCIxA and CCIxB can be connected to internal signals,
but that this two signals are hardwired to specifically internal
signals, depending on the specific device you are using.

I do not quite understand what you are trying to do. I think you need
to organize your thoughts a little bit and then write a description.

Regards,
Michael Kusch


--- In m..., Claro Louie wrote:
>
> hi guys,
> May we raise additional questions regarding the capture time?
>
> Can we use only one "Timer_A capture/compare" like
TACCR0 only to capture successive signals? This is because we're using
just one pin (p2.2) of the `2252 as my input pin for the capture time
of one signal. If so, how can I subtract the current capture value
from the previous capture value? My understanding of subtracting the
current and previous capture value is like subtracting two "Timer_A
capture/compare" e.i. TACCR1 - TACCR0.
> If the input signal is an analog signal, how can we
synchronize the capture time with the analog input signal? We have an
idea of letting the analog signal pass through the ADC10 module, then
letting the timerA capture the signal coming from the ADC10. Can we
capture the time between there is no signal yet and upon presence of
the analog signal. We have read from the user guide that capture
inputs CCIxA and CCIxB can be connected to internal signals by
selecting the CCISx bits. Can you verify if this is effective?
>
> thanks and regards,
>
> claro
>
> tintronic wrote:
> I would use all 3 CC modules. One on compare mode and the
other two on
> capture. With compare you can switch the relay on and off and with
> capture you can know exactly how much time the opening and closing
takes.
>
> TimerA in continuous mode.
> TA0 on compare mode, output TOGGLE. (TACCR0 = 0x0001 for example)
> TA1 on capture, rising edge.
> TA2 on capture, falling edge.
>
> Opening time = TACCR1 - TACCR0
> Closing time = TACCR2 - TACCR0
> (depending on your hardware configuration for driving and sensing the
> relay)
>
> I hope you get the idea. This is the simpliest and most exact approach
> I can think of. I guess you only want to measure the time once. You
> could use TA1 for both rising and falling edge if you need to
> continualy measure the time and want to spare one pin.
>
> Regards,
> Michael Kusch
> --- In m..., Claro Louie wrote:
> >
> > Hi guys,
> >
> > I need some pointers on what is the best way on how to synchronize
> my clock with an input signal. Here's a situation. I have a relay that
> is connected to my microcontroller (MSP430F2252). I want to detect if
> the opening or closing of the relay is slower than the allotted time
> for it to open or close. i'm thinking of using the capture mode of the
> timerA of my microcontroller. Can you confirm if the settings below of
> the timerA are correct?
> > How can I capture the time for the input to change state like from
> 1 to 0 or 0 to 1? The pin connection is at P2.2.
> >
> >
> > WDTCTL = WDTPW + WDTHOLD;
> >
> > TACTL = TASSEL_1 + ID_1 + MC_1 + TAIE;
> > TACCTL0 = CAP + CM_3 + CCIS_1 + SCS +CCIE;
> >
> > Is there other ways that you can suggest on how to implement this
> effectively?
> >
> > thanks and regards,
> >
> > Claro
> >
> >
> >
> > ---------------------------------
> > Be a better friend, newshound, and know-it-all with Yahoo! Mobile.
> Try it now.
> >
> >
> >
>
>
>
>
>
>
> ---------------------------------
> Never miss a thing. Make Yahoo your homepage.
>
>
>