CIF 3

Timers

Each of the workstations has three timers that are available to measure elapsing of time. They can for instance be used to model timeouts, or to delay certain operations. The workstations don’t have physical timers available as hardware. Instead, timers are modeled in CIF, as virtual hardware. This page further explains how to use such timers.

Basic and optional behavior

Three timers are available for each workstation. The following table lists the events used by the timers:

Name Event names (mandatory) Event names (optional)
Timer1 Timer1.c_start, Timer1.u_timeout Timer1.c_cancel, Timer1.c_pause, Timer1.c_resume
Timer2 Timer2.c_start, Timer2.u_timeout Timer2.c_cancel, Timer2.c_pause, Timer2.c_resume
Timer3 Timer3.c_start, Timer3.u_timeout Timer3.c_cancel, Timer3.c_pause, Timer3.c_resume

The simulation model used for simulation, has timer automata that model the behavior of the timers. For supervisory controller synthesis, plants will need to be modeled for the timers. This ensures that synthesis will know about the uncontrolled behavior of timers. Requirements may then restrict the controllable events of the timers, respond to uncontrollable events of the timers, etc. Obviously, plants should only be added for timers that are actually used.

Basic behavior

The basic behavior of timers, is that they can be started, and will give a timeout after a certain amount of time. After the timeout, the timer can be started again, etc. For the first timer, this basic behavior can be modeled as follows, for the purpose of synthesis:

plant Timer1:
  controllable c_start;
  uncontrollable u_timeout;

  location Idle:
    initial; marked;
    edge c_start Running;

  location Running:
    edge u_timeout goto Idle;
end

Optional behavior

Timers also optionally support cancellation, and pausing/resuming. Both features are optional. It is possible to use neither, only one of them, or both of them. This choice can be made per timer. For instance, it is possible to use only the basic behavior for the first timer, use the basic and cancellation behavior for the second timer, and the basic and pause/resume behavior for the third timer.

Cancellation behavior

For the first timer, cancellation behavior can be added as follows:

plant Timer1:
  controllable c_start, c_cancel;
  uncontrollable u_timeout;

  location Idle:
    initial; marked;
    edge c_start Running;
    edge c_cancel;

  location Running:
    edge u_timeout goto Idle;
    edge c_cancel goto Idle;
end

In every location, it is possible to cancel the timer. If you wish, you may also use a slightly more restrictive version of the cancellation behavior:

plant Timer1:
  controllable c_start, c_cancel;
  uncontrollable u_timeout;

  location Idle:
    initial; marked;
    edge c_start Running;

  location Running:
    edge u_timeout goto Idle;
    edge c_cancel goto Idle;
end

Here, it is only possible to cancel a timer while it is running. Once again, the modeler may choose which version of the cancellation behavior to use.

Pause/resume behavior

For the first timer, the pause/resume behavior can be added as follows:

plant Timer1:
  controllable c_start, c_pause, c_resume;
  uncontrollable u_timeout;

  location Idle:
    initial; marked;
    edge c_start Running;

  location Running:
    edge u_timeout goto Idle;
    edge c_pause goto Paused;

  location Paused:
    edge c_resume goto Running;
end

While the timer is running, it can be paused. While it is paused, it can be resumed.

Complete behavior

For completeness, here is a plant with the full behavior, including all optional features (for the first timer):

plant Timer1:
  controllable c_start, c_cancel, c_pause, c_resume;
  uncontrollable u_timeout;

  location Idle:
    initial; marked;
    edge c_start Running;
    edge c_cancel;

  location Running:
    edge u_timeout goto Idle;
    edge c_cancel goto Idle;
    edge c_pause goto Paused;

  location Paused:
    edge c_cancel goto Idle;
    edge c_resume goto Running;
end

Once again, the c_cancel edge in the Idle location is optional. It may be removed to have more restricted cancellation behavior.

Simulation and visualization

The simulation model that is part of the 4K420 course files includes automata that model the behavior of the timers. The simulation model supports the basic as well as all the optional features. There is no need to adapt the simulation model for different scenarios. Unused optional features are automatically disabled by the scripts that are part of those same course files.

The course files also provide visualizations that are used for simulation. The state of the timers are visualized as well, using a rectangle per timer. Each timer has a label that identifiers the timer (Timer 1, Timer 2, Timer 3). The duration of the timer (in seconds) is also indicated. Different colors are used to indicate the status of the timers:

Visualization Status
img-timer-idle Idle
img-timer-running1 Running, no time has elapsed
img-timer-running2 Running, some time has elapsed
img-timer-running3 Running, all time has elapsed
img-timer-paused1 Paused, no time has elapsed
img-timer-paused2 Paused, some time has elapsed
img-timer-paused3 Paused, all time has elapsed

As time elapses, the timer becomes more and more filled, from left to right, to indicate the part of the time that has already elapsed.

Implementation

The hardware mapping model that is part of the 4K420 course files includes automata that model the behavior of the timers, similar to the simulation model. The hardware mapping model supports the basic as well as all the optional features. There is no need to adapt the hardware mapping model for different scenarios. Unused optional features are automatically disabled by the scripts that are part of those same course files.

Configuration

The durations of the three timers that are provided, can be configured. That is, you can decide the durations of the each of the timers. To change the durations, open the config.cif file (also part of the 4K420 course files), and change the values of the appropriate constants. Make sure the read the comments that explain the allowed values.

If you change the configuration, the changes will automatically be applied to subsequent simulations, as well as for the next PLC code generation for implementation.