Measure high period of signal

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 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

0 Likes
4 Replies
lock attach
Attachments are accessible only for community members.
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 I have attached the project. From what I can determine, this should be close to what I need. I have the hardware pin attached to capture pin and trigger pin. I have set Trgger at high going and capture at low going. I am not getting any values from the counter, there is something not correct with the use of the Timer API.

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 By the way, the debug pin I put on Capture Out is pulsing when I see the Signal go low on the logic analyser. It appears the hardware is runnig  but I am not initiating or reading the counter properly?

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Here is a simple project that measures PW and period. Minimum

   

resources.

   

 

   

Regards, Dana.

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 Dana,

   

Which are the variables delaing with the high time only?

   

I see PulsePeriodHigh appears to be when the PWM goes high. I can see pulse period start and end but not sure which is representing end of the high period.

   

Once I do have the start and end time of the high pulse, do I subtract difference from 65535 to get number of micorseconds?

   

I suppose I need to go through the generated files to see what is happening with the interrupts?

   

I need to measure with resolution of 1us, I suppose I should speed up the clock to 1MHz? Maximum high time will be 40,000 us in my application.

0 Likes