ModSlaveSim help v3.06 - 4.4.4. Counters

Download manual: HTML

4.4.4. Counters

A counter is a register that is incremented each time an input changes from 0 to 1 (i.e. counters are edge triggered).

4.4.4.1. Simple counter

This counter keeps incrementing each time its Input changes from 0 to 1, until it is reset by setting the Reset input to 1.

Table 10. Simple counter

Register Address Register Name Statement
$100 Input  
$101 Last input $100
$102 Reset  
$103 Count
if $102 != 0 then 0
else if $100 != 0 && $101 == 0 then $$ + 1

4.4.4.2. Preset counter

This counter increments up to a preset Limit. When it reaches the limit, it stops counting and sets its Output to 1.

Table 11. Preset counter

Register Address Register Name Statement
$100 Input  
$101 Last input $100
$102 Limit  
$103 Reset  
$104 Output if $105 == $102 then 1 else 0
$105 Count
if $103 != 0 then 0
else if $100 != 0 && $101 == 0 && $$ < $102
then $$ + 1

4.4.4.3. Repetitive counter

This counter (like the Preset counter) counts up to a preset Limit, but when it reaches the limit it automatically resets and starts counting again.

The Output is 1 for one cycle each time the counter resets.

Table 12. Repetitive counter

Register 
Address
Register 
Name
Statement
$100 Input  
$101 Last input $100
$102 Limit  
$103 Output if $104 == $102 then 1 else 0
$104 Count
if $100 != 0 && $101 == 0 
then if $$ < $102 then $$ + 1 else 0