Using a smart pin to get frequency of a pin

in Propeller 2
I'm trying to use a smart pin to get the number of pulses in a given amount of time.
_pinstart(pin, P_EVENTS_TICKS, 2000, 0) while (_pinr(pin) == 0); t = _rdpin(pin);
The docs say that it will run for 2000 clicks and tell me how many ticks it saw in that time frame.
It never gives an answer.
Mike
Comments
The Y parameter is determines whether you want to count the number of rises, edges, or the amount of time the pulse is high.
Chris beat me to it, by my test is similar (w/o the float stuff). I used a PWM pin to generate a frequency and connected to it with p_minus1_a.
I tested with several frequencies and the results are very close to the ideal.
Guess it's this in silicon docs:
Would be nice if the silicon docs also mentioned the Spin2 names for the modes...
Also, with Y=0, seems it should have reported time that input was high for 2000 clocks, right?
The documentation is still rather sparse, but seems like that should be...
There's also the high precision example that Chip posted - https://forums.parallax.com/discussion/170882/reciprocal-counter-demo/p1
Yes, it would provide the average high time during that
count
of input pulses, which is like measuring PWM. EDIT: Err, maybe, I'm not sure now. It's written like it counts the sysclock ticks.The next modes down the smartpin mode list all do similar function. Here's my quick reference list:
Yes, it would.
Is there a reverse of this. I would like to have it do 2000 clock ticks and tell me how many pulses there were. That way if the pin stalls it would report zero instead of freezing things up.
Mike
Yep, that's the latter three modes: P_COUNTER_TICKS, P_COUNTER_HIGHS, P_COUNTER_PERIODS. Chip's example code uses them.
This works:
The answer in the terminal was 1000 (was using a 10kHz signal into the pin).
To be fair, this is a bit of a cheat -- I'm only counting the rising edge of each cycle, but that gives you what you want, right?
Oh, good point. Jon's choice is the right one. It doesn't need any pulses to have occurred to give a reading of zero.
Chip's example still needs at least one pulse to give a reading.
Seems we have great hardware but not a whole lot of examples of how to use it…
Maybe Ai can step in and fix this ?
AI mostly relies on examples already existing. It'll go splat with any code that needs crafted to hit new metal, me thinks.
I'll be impressed if it can correctly glue together a low-level program by just reading multiple datasheets for both a new instruction set and new custom eccentric devices. The objective doesn't have to be complex but it needs to be able to work from just the technical manuals without having already trained on examples for that same equipment.