Monitoring a pin for quick read on T3.2

greg

Well-known member
Hi, in my application using Teensy 3.2, I need to read a signal from an external hardware into my c++ application (Windows 10). We agreed with the hardware vendor that they would close a contact on a pair of wires I give them.

So, I give them 2 wires: one connected to common GND, and a pin 16, which I pull up, and read.

I'm using Paul's USBHid library. On windows c++ code side, I call rawhid_recv() from an infinite loop as fast as I can, and as soon as I get a 0 - I know there has been contact closure.

It all works fine, but this application is intended to run for months and years, and there are other devices on that USB hub, and I just don't know if having a thread in windows that runs a tight loop like this 24/7 (100s or even 1000s of times a sec) is a good idea. Is it possible to do this somehow w/o polling? E.g. trigger an event in windows somehow when a pin value is set in Teensy? I can't dedicate the whole MCU to this one task, though, it must perform other things, like driving stepper motors.

Thanks!
 
It's not good to run time critical systems on Windows since Windows itself does pre-emptive multi-tasking.
I.e. it could be doing other things when you want it to deal with your input signal.

Some many years ago National Instruments (NI) embarked on some research with Microsoft to see if Windows could be used for control systems.
The outcome from this research was that it could NOT and NI developed their own PCI Bus plug in cards with their OWN on board operating system for the real time control element.
 
It's not good to run time critical systems on Windows since Windows itself does pre-emptive multi-tasking.

Agree 100%, however, this is not about being true real-time as much as it is about being safe from 24/7 operation perspective and "Close enough" to realtime. E.g. 10-20 ms delay might be fine, but we would still not want to poll 100s of times per second over USB to make it happen.
 
Any thoughts? Is high-frequency polling the only way to monitor a pin from a windows program using USB HID?
 
@defragster, very interesting, thanks, but pardon an ignorant question - what would be the teensy-side code that would raise an event that would raise this WM_IMPUT in windows?

E.g. I would love to be able to use something like USB Keyboard, I suppose, as described here https://www.pjrc.com/teensy/td_keyboard.html, but not sure this would work, as I am also driving steppers and other things on that MCU.
 
If the HID message transfer from Teensy is working to Windows and can be polled and read? Assumed that was working - just not the desired behavior sitting in a tight loop watching for the next input?

Once that is working it seemed that link would allow 'WM_INPUT message from windows' as HID input arrive so it would require polling until after that WM_INPUT message indicated HID input had been received.
 
... it would require polling until after that WM_INPUT message indicated HID input had been received.
Sorry, not sure I understand what you mean here. The HID read is working, we write back with RawHID.send(sendBuffer, 0). After one read, we want to react to more signals (contact closures) from the sensor. So, ideally would not want to poll at all, just get notified in window code when .send() is issued from firmware.
 
Back
Top