Jump to content
Sign in to follow this  

Ultrasonic capture echo

Recommended Posts

Dear everyone,

I am using two methods to capture echo pulse from ultra sonic sensor.

1. I config to capture both rising and falling edge without LPM mode. in ISR, I measured delta time between rising and falling edge.

 TA1CCTL0 |= CM_3 + CCIS_0 + CAP + CCIE;
   //select smclock for timer a source + make ta1ccr0 count continously up + no division
  TA1CTL |= TASSEL_2 + MC_2 + ID_0;

2. I config to use rising Interrupt and go to LMP0 , when a rising edge is detected exit LMP0, I config to detect falling edge so I measure time between to edge and calculate the result.


TA1CCTL0 =  CM_1 + CCIS_0 + CAP + CCIE + SCS; // Capture on rising edge, CCIxA, interrupt Enable
TA1CTL = TASSEL_2 + MC_2 + ID_0 + TACLR; //
TA1CCTL0 = CM_2 + CCIS_0 + CAP + CCIE + SCS;
TA1CTL = TASSEL_2 + MC_2 + ID_0; //
__bis_SR_register(LPM0_bits+GIE); // Go to sleep while waiting for trigger
measure = TA1CCR0;

//capture channel 0
#pragma vector=TIMER1_A0_VECTOR
__interrupt void Timer1A0(void)




In method 1, I recognized it is perfectly, no errors.

In method 2, I just think this i good methode, but the result was wrong, and some time it can not detect the falling edge.

So please help to explain why do method 2 is wrong? is LPM interrupt take any delay time?

Share this post

Link to post
Share on other sites

How short are the time intervals you are trying to measure?


Interrupt has a latency of 5-6 clock cycles. Then there's the latency of your commands to reconfigure the interrupt.


And then there's wake up time from LPM. I only found a number for LPM3/4, which is specified as 1.5us plus 1 clock cycle. So I guess it's 1 clock cycle for the other modes.

Share this post

Link to post
Share on other sites

That's pretty fast. Do you know why ARM is so slow compared to MSP? I usually find praises on the 12 cycles entry + 10 cycles exit

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this