4 Replies Latest reply on Mar 5, 2015 12:36 AM by user_343349849

    Measure high period of signal

    user_343349849

       Would there be a simple code example lurking around that would help me with the following.

         

      I have a device that I pull down a pin via a 1k resistor and the device starts sampling and then pulls the same pin (on other side of resistor) UP for a period of time equal to the result. 

         

      I have set up an Ouput to pull the pin low and an input to read the pulse width. I assume a "Timer" component would be appropriate to measure the High time?

         

      The routine needs to start counting (10us resolution) as soon as the line is detected going HIGH and then stop counting when the line goes LOW again, at which time I will pull the enable pin high to stop the reading and then read the time captured when pin was high.

         

      I have found heaps of timer references for various versions of PSOC but cannot still understand the best way to set this up and the API command to reset the timer, take the measurement and stop it, and ensure any interrupt flags are cleared.

         

      I do know how to start the timer and how to write a interrupt routine and assign it to the ISR pin, the main issue is dealing with the set of API commands for the timer to get it to do what I want as above.

         

      I am assuming on the svchematic I can simply have input pin connected to "Capture", set the clock to 1MHz and select divider of 10 (to get 10us count time) but beyond this I need some help.

         

      Thanks in advance