Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 3 > PSoC 3 Timer Interrupt for ultrasonic sensor

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



PSoC 3 Timer Interrupt for ultrasonic sensor
Moderator:
RKRM

Post Reply
Follow this topic



PSoC 3 Timer Interrupt for ultrasonic sensor

Graeme44 posted on 01 Jun 2011 2:03 PM PST
Member
2 Forum Posts

 Hi.

I've built a circuit which transmits and recieves ultrasonic waves. It has an input (controlling the tx - normally pulsed at 40kHz), and an output (logic high or low - if reflected pulse detected).

I am driving the tx from a PWM(1) at 40kHz, I am then controlling the on time of PWM(1) with a second PWM(2).

ie, PWM(1) is outputting 40kHz for 0.5ms and is off for 64.5ms.

Now, I would like to time the time taken for the reflected signal to occur. I've thought about using an interupt and then reading the PWM value and converting it into a time, or using a timer.

Please could you point me in the right direction, as I am unsure wheather this is best treated in software or hardware (trigger and capture pins on the timers/pwms).

Many Thanks




Re: PSoC 3 Timer Interrupt for ultrasonic sensor

Gautam Das posted on 02 Jun 2011 03:28 AM PST
Cypress Employee
742 Forum Posts

Hi Graeme44,

 

You can use another Timer for measuring the time taken for the signal to reach back after reflection.

1) The Timer has to be used in Capture mode.

2) Hardware Trigger should be enabled for this Timer. When the PWM(1) starts Transmission, trigger the Timer so that the Timer starts Counting.

3) The output pin (reflected pulse indicator) should be connected to the Capture input.

4) When the reflected signal is received, the Timer's value is Captured. This can be read using an ISR. The counts elapsed will give an indication of the time taken by the wave to reach the receiver after reflection.

5) If the Clock used for Timer is of reasonably high frequency, better accuracy can be obtained. Eg, If Clock = 1MHz, and it takes 100 counts for the relected wave to reach back, then the time taken is 100 micro second.

 

Distance travesred can be calculated as the speed of sound in air is known.



Re: PSoC 3 Timer Interrupt for ultrasonic sensor

Graeme44 posted on 03 Jun 2011 01:39 AM PST
Member
2 Forum Posts

 Thank you, I will try that.

I still think I may be able to just read the PWM count values instead of using a timer - Will try both ways.

Standard interupts don't interupt PWM and timer modules, is there anyway of interupting them during a isr?

Thanks



Re: PSoC 3 Timer Interrupt for ultrasonic sensor

U2 posted on 10 Jun 2011 10:21 PM PST
Cypress Employee
589 Forum Posts

Using ISR is also a possibility. But note that for the ISR code execute, there is certain amount of delay due to the PUSH and POP of various registers. And hence the PWM or Timer read out value may not be precise and accurate. As long as you can afford to have lower accuracy this is fine. As told by dasg in post 2, using the Timer capture mode is more accurate way of implementing this. In this case the output from the Ultrasonic module will trigger a Timer capture in hardware and the value captured is stored irrespective of ISR being executed or not. You can later read this value from a ISR or your normal firmware and get the accurate timing information. Also as was told in comment 2 by dasg, higher the frequency of the Timer input clock, better will be the precision of the timing.



Re: PSoC 3 Timer Interrupt for ultrasonic sensor

U2 posted on 10 Jun 2011 10:34 PM PST
Cypress Employee
589 Forum Posts

Using ISR is also a possibility. But note that for the ISR code execute, there is certain amount of delay due to the PUSH and POP of various registers. And hence the PWM or Timer read out value may not be precise and accurate. As long as you can afford to have lower accuracy this is fine. As told by dasg in post 2, using the Timer capture mode is more accurate way of implementing this. In this case the output from the Ultrasonic module will trigger a Timer capture in hardware and the value captured is stored irrespective of ISR being executed or not. You can later read this value from a ISR or your normal firmware and get the accurate timing information. Also as was told in comment 2 by dasg, higher the frequency of the Timer input clock, better will be the precision of the timing.






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: KXP; Secondary Owner: VWA; Sunset Date: 01/01/20