595ctrl

external digital output pin control
Author: Ricard Wanderlof
License: BSD
Github: ricard/gpio/out/595ctrl.axo

Inlets

None

Outlets

None

Attributes

combo data

combo clock

combo latch

combo oe

spinner bits

Declaration
unsigned int data;
int count;
Init
palSetPadMode(attr_data, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(attr_clock, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(attr_latch, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(attr_oe, PAL_MODE_OUTPUT_PUSHPULL);
palWritePad(attr_oe, 0);    // 0 = enable outputs
palWritePad(attr_latch, 0); // latch on rising edge
palWritePad(attr_clock, 0); // clock on rising edge
data = 0;
count = (attr_bits << 1) - 1;
Control Rate
// Sequence: count runs from attr_bits<<1 - 1 down to -2
// When count is >= 0, send corresponding bit to data pin, and pulse clock
// data is clocked on the rising edge of the clock (so in the current
// implementation, data is clocked on the same phase as it is written)
// When count is -1 and -2, pulse latch to transfer data to output register
// oe is low (enabled) at all times
if (count < 0) {
  palWritePad(attr_latch, count & 1);
  if (count == -2)
    count = (attr_bits << 1) - 1;
  else
    count--;
} else {
  palWritePad(attr_data, (data >> (count >> 1)) & 1);
  palWritePad(attr_clock, !(count & 1));
  count--;
}

Privacy

© 2024 Zrna Research