counter3 minmax

cyclic up down counter with minmax input up/down input
Author: philoop
License: BSD
Github: phi/logic/counter3 minmax.axo

Inlets

bool32.rising trigger

bool32.rising reset

int32 max

int32 min

bool32 updown

Outlets

int32 output

int32 l

bool32.pulse carry pulse

Declaration
int ntrig;
int rtrig;
int dtrig;
int count;
Init
count = 0;
ntrig = 0;
rtrig = 0;
dtrig = 0;
Control Rate
outlet_c = 0;
if ((inlet_trig > 0) && (inlet_updown < 1) && !ntrig) {
  count += 1;
  if (count >= ((inlet_min) + (inlet_max - inlet_min))) {
    count = (inlet_min);
    outlet_c = 1;
  }
  ntrig = 1;
} else if (!(inlet_trig > 0))
  ntrig = 0;

if ((inlet_trig > 0) && (inlet_updown > 0) && !dtrig) {
  count--;
  if (count < inlet_min) {
    count = inlet_max - 1;
    outlet_c = 1;
  }
  dtrig = 1;
} else if (!(inlet_trig > 0))
  dtrig = 0;

// reset
if ((inlet_r > 0) && !rtrig) {
  count = 0;
  rtrig = 1;
} else if (!(inlet_r > 0))
  rtrig = 0;

outlet_o = count;
outlet_l = (inlet_max - inlet_min);

Privacy

© 2024 Zrna Research