kfactor
Trying to learn how to display a simulated piece counter on a 4 digit 7 segment display (for a cybersecurity demo lab). This is for OpenPLC runtime on a Raspberry Pi 4, where 3 of the gpio pins are connected to a single 74HC595 shift register. The 8 outputs of the 595 are connected to a common anode 7 segment LED display.
 
The CTU counter variable is stored and converted to BCD.
 
2 questions:
 
1) how do I split the BCD word into 4 nibbles and process each in a loop? can you address them as an array?
 
2) how would I send 8 bits to the shift register?
There are 3 pins used to send from the controller to the 595:
DS is the data bits
SH_CP is the shift register clock
ST_CP is the storage latch to activate the outputs all at once with the stored register
 
So the process would be as follows:
 
for each of the 8 bits
    Set DS data pin for current bit to proper value
    Set the SH_CP shift pin high
    Set the SH_CP shift pin low
after all 8 bits are sent set the ST_CP latch pin high to active new value on the outputs
set ST_CP latch pin back to low
 
Note: I realize this is basically what a 7447 IC does for you, but I don't have one and I'm trying to learn. 🙂
Also I have studied many examples from Arduino code that does this (for example SevSegShift). I understand these C or C++ examples but now how to do this in LD or ST.
 
Thanks!
 
example sending 11000011 to the 595 shift register and triggering the latch to outputs:
shift_latch595.png
 
 
example C++ code for arduino (credit and thanks to bridystone on github sevsegshift):
 
sevsegshift.png
Reply 0 0
thiagoralves
1. One approach would be write a Structured Text function block with a bunch of IF statements to convert your bcd to two nibbles.
 
2. you can’t do that in any PLC language. You need something with a more precise timing. For this you would have to write a driver in C or using PSM (python) that will handle the communication with the shift register, and then abstract that for the plc runtime. Not a straightforward task, especially for a beginner 
Reply 0 0
Reply