function count
input Integer val "Current value of counter";
input Integer preset_val "Preset value";
input Boolean S "Set signal at time t";
input Boolean S_old "Set signal at time t-1";
input Boolean CU "CountUp signal at time t";
input Boolean CU_old "CountUp signal at time t-1";
input Boolean CD "CountDown signal at time t";
input Boolean CD_old "CountDown signal at time t-1";
input Boolean R "Reset signal at time t";
input Integer Max "module of the counter";
output Integer NVal "Current up to date value of the counter ";
output Boolean Q "Output logic value";
end count;