Period counter using shared Variable

This example shows a 1Hz period counter using Shared Variables in

QFIRE Studio

.

Introduction

If the input signal is logic low, the counter must increment by one. If not, reset the counter. But, if the counter reaches the maximum it should stop incrementing until reset.

Simulation

As a test input signal, a unit step happens at 6s. It is modeled as in figure below:

Figure 1 - Diagram of the input signal

Figure 2 shows the diagram which models the counter.

Figure 2 - Diagram for the logical conditions required

When the count value is lower than the threshold, the Shared Variable 0 receive the signals from Switch 2, otherwise it receives signals from Switch 3. Its behavior can be detailed as follows:

  • The orange block contains the diagram from Figure 1. The counter uses the Shared Variable Block; in this case, it acts as a feedback. At each step, the input Shared Variable samples its value before updating the output Shared Variable.
  • Switch 2 controls increment (input high) or reset (input is low). It works only when the count is lower than the maximum. In this example, de maximum value is the threshold value of 5.
  • Switch 3 limits the maximum value of the counter or resets the counter when input is low. Unlike switch 2, switch 3 works when the count reaches the threshold value.
  • The output of these two switches are managed by another switch connected to the Relational Operator.

The test input signal modeled in Figure 1 generates the signal in the following graphic:

Figure 3 - Test signal (unit step at 6s)

And the the count value for this simulation is represented by the following graphic (increments when input is low, decrements when input is high, and is bounded between 0 and 5):

Figure 4 - Counter output signal

At the time of 4s the counter reaches the threshold value and holds it until the time of 5s. When the input signal becomes high at 6s, the counter resets.

About MWF

MWF is a traditional Brazilian company that provides a wide range of electronic and mechatronic products for industry sectors such as automotive, agricultural machinery and aerospace.

Contact Us

Rua Doutor Siqueira, 139 / Sala 804 Campos dos Goytacazes - RJ, Brasil

contact@mwf-technologies.com

© 2018-2026 MWF. All rights reserved.