Knowledge Base

Example: Numeric data entry function with gear shift

This programming example addresses the issue of providing a user interface that permits the user to set numeric parameter values. This might be for example a target weight on a batch weighing system or a temperature setpoint on a furnace control. Sometimes such parameters need to be adjustable over a wide range of numeric values, but they must also be constrained within permitted minimum and maximum values. In for instance a batch weighing system permissible values may range from 0.20kg to 20.00kg in steps of 10g (0.01kg).

With controller like the MMi200 we are faced with the restriction that the off the shelf product does not have a numeric keypad. How then do we give a user the ability to enter a number like 19.87kg? One answer would in fact be to interface a numeric keypad, and write a suitable driver. That is perfectly possible, but it is not the solution we will pursue here (the classic tutorial in the SPLat/PC help file has an example of just that).

The solution in this example uses just 4 of the 5 front panel push buttons on the MMi200. They are used (designated) as “Up”, “Down”, “Yes” and “No” (the latter 2 could also be called “Accept” and “Reject”).

What it does is to use the Up and Down buttons to increment or decrement a number with auto-repeating of the button as long as it is held down. However, the amount by which it changes is variable, with an automatic “gear change” feature that takes place while the Up (or Down) button is held down. With the gear change, as a particular digit position has been incremented and rolls over to zero, focus shifts to the next highest position which in turn gets incremented.

For example, assume the number starts at 0 and is initially incremented by one. Providing the Up button is held on, the number will go through the following sequence:

    0,    1,    2,    3, ....    8,    9,
   10,   20,   30,   40, ....   80,   90,
  100,  200,  300,  400, ....  800,  900

etc. If the user releases the button at 900 and then presses it again, the function will shift back down to the lowest gear and resume counting by ones:

  901,  902,  903,  904, ....  908,  909,
  910,  920,  930,  940

etc.

The function allows you to set the initial value, the initial increment and the minimum and maximum allowable values. It actually turns out to be an advantage not having a full keypad, because this method makes it impossible for a user to go outside the min/max limits. With a keypad this becomes much harder.

The example is written as a function that can be incorporated quite readily into a larger program. You can download the examples collection from our website in the File Resources area. The code for this example is called FSETNMVS.SPT. This is an old example, written to be compatible with the Suspend/Resume method of writing multitasking programs, which has been superseded by MultiTrack. The code provided includes test/demo code.