monitor digital inputs in C# without CPU polling possible?

Good evening to everyone,

I have a really fundamental question, maybe stupid, but I couldn’t find a concrete answer:

Short: Can I use an Arduino connected with USB to my single board computer to monitor digital inputs and inform my host program about pressed buttons in case, without the need of CPU polling all the time?

Long: At the moment I am using a single board computer with Vortex86 CPU, an additional 48bit digital I/O and a program written in C# to send midi commands in the end. While polling all the digital inputs the CPU load reaches 100% and the whole OS and program are reacting quite slowly. Reducing the polling speed will decrease CPU load but adds latency from pressing a button until sending a midi command.

That’s the point as I searched for different hardware and found the Arduino. As I understand the arduinos are equipped with own microcontrollers and can even be used standalone (some models I guess).

So can I use an Arduino connected with USB to my single board computer to monitor digital inputs and inform my host program about pressed buttons in case, without the need of CPU polling all the time?

Thanks and best regards, Gandlz

The answer is probably yes.

As you haven't given details of the 48 bit digital I/O device I can't say if it would work with an Arduino. And Arduino Uno only has a max of 18 digital I/O pins but a Mega has 54.

Another important question is how often you need to poll the pins? If you organize your wiring so that you can read 8 pins from a single I/O port then you can read 8 at one time using direct port manipulation which should help to speed things up.

And then there is the question of how many bytes of data per second need to be sent over the Serial / USB connection to your Vortex86 CPU.

...R

PS I will leave it as a homework question for you to contemplate how an Arduino could do this but a (presumably) much more powerful computer can not.

Hello Robin2 and thanks for your answer!

I am sorry, but I do not write program code, a friend does it. So maybe that’s why I do not really understand what you mean.

Our current hardware: http://buy.advantech.eu/3-5-Embedded-Board/3-5-Embedded-Board/model-PCM-9343F-S6A1E.htm http://buy.advantech.eu/PCI-104-and-PC-104-Modules/PC-104-Modules/model-PCM-3724-AE.htm

So in our case, as I understood, we have to use the CPU to poll all digital inputs for a possible pressed button all the time and also very fast to react without latency on a pressed button. That’s why our CPU reaches 100% load.

I found some different I/Os which are capable of sending interrupts (some called change-of-state interrupts). These ones should interrupt the CPU as a button gets pressed and the CPU only polls one time than. Some of these interrupts can contain port information so that only 8 pins have to be polled and not all 48. However these I/Os are very expensive and I try to find something different.

Arduino has its one microcontroller and as I understand most programs are written directly to the Arduino so it also can work standalone without computer connection. I read about direct port manipulation which can make the Arduino reading inputs faster but this does not speed up the way left from the Arduino to the computer.

But concerning on the information I found today I think the following should be the case: The Arduino communicates via serial port (could be USB in fact) to the computer. So the CPU has not to poll all inputs but only needs to monitor the COM-port which should not result in heavy CPU load without bad latency. So what’s left to program directly on the Arduino would be defining the single pins as input or output and a string or binary code for each pin which should be sent to the computer in case of a pressed button. For a digital output it’s quite the same just the other direction.

So I am sorry, as far as I do not understand much about programming I can only talk in this basic way.

Thanks a lot.

gandlz: I am sorry, but I do not write program code, a friend does it. So maybe that’s why I do not really understand what you mean.

I think the best thing is to get your friend to take over your questions here. Working through you as an intermediary is just not practical.

...R

I am sorry, but I do not write program code, a friend does it. So maybe that’s why I do not really understand what you mean.

So what sort of answer are you expecting that you could understand, given that you are posting in a programming forum?

Any polling will use 100% of the CPU if all you do is to pole. Even if you use interrupts you still have to pole the interrupt flag to do anything useful with the information.

You have to decide on how often you want to pole and what latency you can tolerate and what else you want the processor to do as well.

Well, my friend is very busy and I am thankful that he is even programming for me. However, I don’t want you to give me code or something like this. (Maybe the wrong forum that’s right) I just want to know if the Arduino hardware can save me from CPU polling.

So is there a short answer for this question: Does the CPU have to poll all inputs, or could this be done by the Arduino itself while it informs the computer via serial connection about these inputs?

Would be great if I can go with something more than "probably yes".

could this be done by the Arduino itself while it informs the computer via serial connection about these inputs?

Yes.

I think using an Arduino to interface between your I/O board and your Single Board Computer would be adding lots and lots of unnecessary complexity.

As I understand it, polling this I/O board is extremely fast. It's direct I/O. According to the documentation, you should be able to poll all 48 ports in about 20 microseconds. Just interfacing with the Arduino would take longer than that.

My back-of-the-envelope calculations indicate that you should be able to get decent user input response times (1/30th of a second) polling all 48 I/O's with a utilization of less than 0.1%. If you're maxing out utilization with polling, something else is the problem.

This is assuming that the operating system you're using is Windows CE, that you're yielding the processor properly between polls, and that you aren't running any processor hog applications.

TanHadron: I think using an Arduino to interface between your I/O board and your Single Board Computer would be adding lots and lots of unnecessary complexity.

As I understand it, polling this I/O board is extremely fast. It's direct I/O. According to the documentation, you should be able to poll all 48 ports in about 20 microseconds. Just interfacing with the Arduino would take longer than that.

My back-of-the-envelope calculations indicate that you should be able to get decent user input response times (1/30th of a second) polling all 48 I/O's with a utilization of less than 0.1%. If you're maxing out utilization with polling, something else is the problem.

This is assuming that the operating system you're using is Windows CE, that you're yielding the processor properly between polls, and that you aren't running any processor hog applications.

Long Story Short - the friend who understands programming needs to participate here.

Or maybe s/he doesn't understand programming as well as s/he claims :)

...R

@Grumpy_Mike: thanks for this simple „yes”! I think I will order some Arduino for testing this.

@TanHadron: I do not want to add the Arduino to my current setup. I would like to replace the I/O with an Arduino. I think it has to be the Arduino Mega to supply enough I/Os. But it sounds interesting what you talk about the current setup. We use Windows XP at this time. Could this be the problem? We tried to add some delay after each poll. I think it were 50ms. This reduces CPU load very much and the whole system behavior was great again. But sometimes when pressing a button then, there was unacceptable latency until the corresponding command got sent.

I also read about, that the Vortex86 is not a real x86 CPU but has to emulate an x86 environment. Could this also be a problem?

Thanks!

Windows XP is better than Windows CE. You should have the capability to do this either way. If you choose the Arduino Mega route, you should be able to easily get it to send you data when you press buttons. However, you're adding complexity. You will have to not only program the PC, but you'll have to program the Arduino as well. It will need to detect button presses, and you'll need to design a protocol to send those button presses to the PC. The program on the PC will have to be re-designed to accept messages from the Arduino, and you'll probably want to arrange for it to block pending USB/serial input. Which will avoid the problem of CPU utilization due to polling. I'm not sure exactly what kind of response time you'll get, but I have some doubts that this will actually solve your problem.

With Windows XP you should be able to easily poll those 48 I/O ports and yield up the processor to avoid excessive CPU utilization. 50 milliseconds is only a 20th of a second. I expect the unacceptable latency you're talking about is much greater than that, so there must be something else going on. How certain are you that you won't have the same things going on with the Arduino?

Well, I will talk to my friend concerning on your information to look if we can reach what we want and what you think should be possible with the current setup before changing everything to Arduino.

Thanks a lot for this input! Gandlz