1

I am curious how the user input is handled in micro-controllers in way that all other work is not blocked.

For instance, I have modern gas boiler - Vaillant, boiler is running his own tasks while I can scroll in the user menu, press buttons and so on.
How this is worked out from conceptual point of view?

Is there another micro-controller which handles user input and then it pushes selected inputs to main controller?
Or there is just some type of scheduller in main controller and it is scheduling so fast so it can handle user inputs AND background tasks?
How this is handled in general so user can play around with menu and so on without blocking the main task.

Thank You

mekybsd
  • 13
  • 2
  • 1
    Most of the microcontroller has the ability to handle interrupt if you write your own Interrupt Service Routine (ISR). It's usually triggered by detecting changing voltage value on certain pins. – Da Teng Mar 15 '19 at 14:30
  • can be one processor or two or many. And if you were ever permitted to see how it was done or you started tearing apart the hardware and if you find marked parts, then you may find that some are implemented one way and some implemented the other. No reason why you have to only do it one way. – old_timer Mar 18 '19 at 03:54
  • Give 100 programmers a task and you should hope for somewhere between 1 and 100 different solutions. Answers have already described that there are various ways to solve this. When you do a design you understand the requirements and the processing power required to meet those requirements for each of your design proposals then narrow in on one. – old_timer Mar 18 '19 at 03:58
  • There may also be laws or industry standards or habits that for safety reasons may dictate how the gas boiler is managed. Just like the computer that actually runs your modern car, its not the same software that runs the stereo/clock/radio/etc display. The processors that manage the display in the back of the seat in front of you in a plane is not the same one that is flying the plane. Your computer is made up of many processors, the x86 is to some extent an also-ran. Not for safety reasons but for other reasons. – old_timer Mar 18 '19 at 04:07

2 Answers2

1

This can be handled in many different ways and, depending on the complexity of the overall application, it can be as simple as a super-loop, or as complex as a multitasking based application with several independent tasks each doing their own thing (e.g., one doing key press detection, another dealing with serial comms, another updating the [G]LCD, etc.).

Your particular example can easily be handled with the super-loop approach, although a multitasker can also be used for (IMO) simplicity in coding.

For example, with the super-loop approach, each time through the loop you call a key press detection routine which checks if a key is pressed and counts time up to some maximum as long as the key press is still present. It does not block, it exits immediately. When the count reaches a minimum to accept the key (e.g., corresponding to about 50-100 msec) you return the key pressed and zero the counter (for auto key repeat), or save the key in a temporary buffer and return it only when the key is eventually released (if no auto key repeat is desired).

The display works in a similar way. The current screen is updated depending on which state the device is in. When the UP/DOWN key (for example) is detected, the index of the scrolling item changes up or down and the screen is redrawn with the new state.

There are certain situations that a multitasker is the only reasonable way to solve such problems if you don't want your app to become a un-debuggable mess of flags, and ifs. Dealing concurrently (and smoothly) with multiple interfaces (e.g., GPS, GSM, user terminal, key/LCD) is one such example.

BTW, interrupts for key presses are IMO an overkill unless you are in some battery saving sleep mode and need a hardware way to wake up. Human key presses are always too slow by comparison to CPU speeds and can be detected reliably by simple polling.

tonypdmtr
  • 3,037
  • 2
  • 17
  • 29
0

Most CPUs have some form of interrupts (even the PC).

Basically the interrupt tells the CPU to stop what it is doing and handle some realtime event. When the interrupt handler is complete the CPU will resume its original program.

More detailed information on interrupts is available on wikipedia

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60