Non-blocking PinCapture

Trying to figure out what the best way is to go about counting RPM pulses (approx 2ms intervals) on one pin and fuel flow on another (also roughly at 2ms intervals). Looking at PinCapture would do the trick except thread blocking is unacceptable. Would love to hear some suggestions on the best route to take.

This is one of the tings we like to add to 4.2, which is why PinCapture is not there in beta now.

Would this be the way to go?

Looks like this code only sets up to capture one port pin. How would multiple pins be set up?

What you liked is exactly the opposite from what you asked for at first. I am bit confused now.

Yes I can see the confusion. What I would like to do is count the number of pulses over a period of 1 second on each of the two pins.

oh wait! I am reading the codeshare post wrong. You are right, that post does the counting you need, my bad.

We have no set plans yet but we like to add something.

So you only need to count the pulses and do not care about the pulse size right?

Correct. Just need to count the number of pulses over one second. I’ll have a timer ISR that will fire every second to average the pulse count over a period of 5 seconds.

You would need to duplicate the “Setup GPIO” code and the GpioIsr.

But you might be better off to just set up Timer1 and Timer2 in counter mode, and then quering them every 1000ms. You should be able to do that using only the Register class. It will take a bit of studing the chip’s user manual though.

Which board are you using?

Also, PinCapture is thread blocking, so why not spawn two new threads, one for RPM and one for fuel? Then the threads can be blocked without affecting the main application…

I’m using EMX but I’m probably do some prototyping with my Panda 2.

Yes I’ve thought about looking at timers and setting everything up via the Register class but I haven’t delved into it deeply enough yet to come to any conclusions.

As I read the PinCapture docs it says it blocks all the managed threads. So I assumed everything gets blocked, not just the thread that’s doing the work. If that’s not the case then PinCapture would be an easy solution.