3 Replies Latest reply on Jun 14, 2017 5:26 AM by user_1377889

    Timer Capture Error

    user_490750787

      I'm trying to get basic project working to measure flight time between ultrasonic transmitter and receiver. I'm using the -050 psoc 5lp dev kit.

         

      The receiver signal goes through a PGA to a comparator. The signal coming out of the PGA looks fine and the Comparator output is as expected too. The comparator output connects to the timer capture input. An interrupt is triggered on timer capture which reads capture value and shuts down the timer and comparator. The measurement I'm getting is between 480-490 microseconds but you can see on the attached oscilliscope the real time between PWM start and Comparator high is actually ~440 microseconds.

         

      Attached program has sync component between the comparator and timer. I've also tried without sync component and with sync option on comparator. Same result for all.

         

      I've also tried just sending a test signal to the timer input by driving a pin low-high with a delay of 400us. With the test signal I get a correct value from the timer capture and also matches oscilliscope.

         

      Is there something I'm missing here?

         

      Thanks

         

      Aaron

        • 1. Re: Timer Capture Error
          user_1377889

          I can see two reasons causing the issue:

             

          The reset signal is synchronous in nature, thus needing a clock low to high transition while it is asserted. The code you use to reset with a control register will execute much too fast. Fortunately you do not need reset. You can write in your interrupt handler the starting value into the timer when it is stopped.

             

          For the capture signal applies the same. I would suggest to use a "Pulse Converter" component which will ensure the required length of the capture input. Syncing the comparator output can be done by the component itself: configure sync and provide a clock to sync to.

             

           

             

          Bob

          • 2. Re: Timer Capture Error
            user_490750787

            Bob,

               

            Appreciate your feedback. Those are helpful tips.

               

            I figured out a few things i was neglecting.

               

            1. I overlooked that the PWM was right aligned so my oscilloscope measurement neglected the first half of the first PWM period

               

            2. Using the slower clock for the PWM created a delay that i wasn't accounting for

               

            3. I used the 1 MHz clock for the PWM to remove delay from #2. Things were better but then realized that I needed to reset the PWM counter value each time to get consistent results.

               

            Does that all make sense? Things appear to be working to my satisfaction at this point.

               

            Thanks again

               

            Aaron

            • 3. Re: Timer Capture Error
              user_1377889

              When something works as expected it proves that you are right ;-)

                 

               

                 

              Bob