Notifications
Clear all

[Solved] Programmatic Master Reset of the 74HC595 Shift Register

5 Posts
2 Users
6 Reactions
2,291 Views
ron bentley
(@ronbentley1)
Member
Joined: 3 years ago
Posts: 385
Topic starter  

Programmatic Master Reset of the 74HC595 Shift Register

Have you ever done anything blindly and without giving too much thought it?  Yes, of course, we do this every day.  This is certainly true when we are developing our projects and use standard components that are wired in a standard ways – we just make the connections as we always have or as we are instructed.

I seem to have made use of the 74HC595 shift register a great deal over this past year and always get frustrated by wiring these ICs as there are so many connections, especially when they are cascaded.  It was during a recent project in which these ICs were used that I wondered why things are as they are.  I could readily understand most of the pins of the 74HC595 and what they did, but there were two for which I had no idea. The pins in question were pin 10 (SRCLR) and pin 13 (OE).  Of the two, the one that most intrigued me was IC pin 10, SRCLR.  Doing a bit of research I discovered that this is the 74HC595’s master reset pin (MR), labelled SRCLR in the diagram below.  SRCLR is a contraction of Shift Register CLeaR.

 

image

 

If we follow the traditional way of wiring up the 74HC595 IC then this pin, SRCLR, is permanently hard wired high (+5v). The following image shows a 74HC595 wired in the traditional manner, driving 8 LEDs:

 

image

 

In this configuration, there is no opportunity to use the SRCLR pin programmatically to perform a master reset of the IC.

So, I thought, this would be easy to test out – wire pin 10 of the IC to a digital output port of my board and write code to do a master reset on the push of a simply connected button switch. This is what I did; only things did not work as I thought!

I modified the above traditionally wired 74HC595 layout as below:

 

image

 

Notice now that the SRCLR pin is wired to a digital port of the microcontroller, and also there is a simply connected button switch which is used to invoke a master reset on the SRCLR pin.

My code initially wrote all 74HC595 ports high, illuminating each of 8 connected LEDs and then, when the button switch was pressed, issued a master reset signal to the IC via its pin 10 (SRCLR). But the LEDs stayed illuminated.  What was going on?

Back to the net for a little more research.  I found that the 74HC595 actually has two internal 8-bit registers – the shift register and another register - the storage/latch register.

This design allows us to send updates (bits) to the shift register and, when we are ready, latch these bits from the shift register to the storage/latch register by toggling the latch pin.  The latching process is the instruction to the 74HC595 to copy its shift register contents across to the storage/latch register.  I did not know it worked in this way when I started.

I now knew why the original code didn’t work – it did half a job, it did clear the shift register but, without the latch cycle, it did not update the storage/latch register so I could not witness the operation.  A quick change and, hey-presto, it worked and I suddenly learned a little more about the 74HC595.

My test Arduino sketch code is as below is:

 

//
// 74HC595 Programmatic Master Reset
//
// Ron Bentley, Stafford UK
// February 2022
//
// This example and code is in the public domain and may be used without
// restriction and without warranty.
//
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Example sketch - Demonstration of Programmatic Control of the
//                  74HC595 Shift Register Master Reset(MR) Function
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//
// Objective of the sketch
// ^^^^^^^^^^^^^^^^^^^^^^^
// To show the operation of the 74HC595 shift register master reset (MR)
// function.
//
// Approach
// ^^^^^^^^
// To achieve our objective, we need to bring the SIPO IC's master reset pin
// (MR, but often labelled SRCLR)under programmatic control.
// For this, we allocate a digital microcontroller pin and connect this to the
// MR (SRCLR) pin of the SIPO IC.
//
// By lowering and raising the signal level of this pin (LOW/HIGH, 0/+5v)
// we are able to produce a complete SIPO IC reset as necessary.
// To show this operation the sketch uses a simply connected button switch
// to toggle the SIPO IC's master reset function and noramal SIPO IC updates.
//
// The sketch uses two libraries:
// 1. the ez_switch_lib library to define and control a simply connected
//    button switch, and
// 2. the ez_SIPO8_lib library to define and control a single 74HC595
//    shift register.
// These libraries may be accessed and downloaded via the ARDUINO Project Hub:
//
// 1. ez_switch_lib library-
//     https://create.arduino.cc/projecthub/ronbentley1/a-switch-library-for-arduino-dfbe40?ref=user&ref_id=1455180&offset=17 
//
// 2. ez_SIPO8_li library-
//     https://create.arduino.cc/projecthub/ronbentley1/command-control-of-multiple-serial-in-parallel-out-ics-3e0b1a?ref=user&ref_id=1455180&offset=16 
//
// If you wish to read a primer for SIPO ICs/shift registers then have a look at the link below:
//     https://lastminuteengineers.com/74hc595-shift-register-arduino-tutorial/ 
//

// declare SIPO IC data

#include <ez_SIPO8_lib.h>

SIPO8 my_SIPOs(1, 0); // configure for one SIPO IC, no timers for this sketch

uint16_t bank_id;

#define data_pin     8
#define latch_pin    9
#define clock_pin   10
#define IC_MR_pin   11

bool IC_MR_status;
//
// Declare switch data

#include <ez_switch_lib.h>

Switches my_switch(1); // establish just one switch for this sketch

int switch_id;

#define my_switch_pin 12

void setup() {
  //
  // Set up switch - a button switch, simply wired without a pulldown resistor
  switch_id =
    my_switch.add_switch(button_switch, my_switch_pin, circuit_C2); // add & configure the switch

  //
  // Deal with initialisation of the MR reset pin
  pinMode(IC_MR_pin, OUTPUT);
  IC_MR_status = HIGH; // start with a HIGH signal, ie IC active status, ready for data
  digitalWrite(IC_MR_pin, IC_MR_status);

  //
  // Set up the SIPO - one SIPO IC in this bank on these control pins:
  bank_id =
    my_SIPOs.create_bank(data_pin, clock_pin, latch_pin, 1);

  // Now set all of the IC's output pins HIGH (LEDs on)
  my_SIPOs.set_all_array_pins(HIGH);
  my_SIPOs.xfer_array(MSBFIRST);
}

void loop() {
  do {
    // Only process if the button switch has been toggled.
    // Alternative switch presses perform direct programmatic IC shift
    // register master resets and normal IC updates, respectively
    if (my_switch.read_switch(switch_id) == switched) {
      // Button switch actuated
      IC_MR_status = !IC_MR_status;    // invert current IC_MR_status and process
      if (IC_MR_status == LOW) {
        // Request to programmatically reset the SIPO IC via the MR pin, so reset the
        // IC shift register and ensure output ports also reflect cleared status by
        // toggling latch pin
        digitalWrite(IC_MR_pin, LOW);  // reset IC - drop MR reset pin +5v signal
        digitalWrite(IC_MR_pin, HIGH); // set IC back to active status
        digitalWrite(latch_pin, LOW);  // indicate an update from shift register to output required
        digitalWrite(latch_pin, HIGH); // action transfer of register reset state to the outputs
      } else {
        // Normal update, set all outputs HIGH
        my_SIPOs.set_all_array_pins(HIGH);
        my_SIPOs.xfer_array(MSBFIRST); // send update to all output ports
      }
    }
  } while (true);
}

 

If you wish to have a fuller explanation with the Arduino code, diagrams, a short video then have a look at the tutorial for this research on the Arduino Project Hub by following this link.

Is this useful? Well, have a read of the tutorial and I will give you my thoughts.

By the way, I hear you asking, what about pin 13 (OE)?  Maybe one day I will have a look at this also.

 

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
Quote
(@davee)
Member
Joined: 4 years ago
Posts: 1924
 

Hi @ronbentley1,

   I am aware these shift registers are quite popular and I think a number of forum users will find your explanation extremely helpful.

Reading your text, a couple of points came to mind:

Your pinout diagram is slightly misleading ... For comparison, I have copied the Texas Instrument datasheet one 

( for the full datasheet see:    https://www.ti.com/lit/ds/symlink/sn74hc595.pdf )

image

You may notice Pin 13 has a bar over 'OE' and Pin 10 has a bar over 'SRCLR'.

The bar is equivalent to 'NOT' ... that is to make the pin action 'happen', you take the pin Low (0V).

(Sorry, I haven't figured out how to show the bar in this text ... I'll write '(not)SRCLR' a reminder of the bar. )

 

For example, as you eloquently explain and demonstrate, taking the (not)SRCLR clears the shift register ... for 'usual operation', this pin is held high.

Correspondingly, your mystery pin 13 'OE' stands for Output Enable. It is 'usually' held low, to enable the Outputs Qa...Qh, so that they can output High or Low,  according to the value held in the internal latch.

Taking (not)OE pin 13 high, disables those outputs to a 'high impedance' state (AKA tri-state).

In your circuit diagram, pin 13 is connected to the Arduino ground pin, and hence the Qx outputs are always enabled.

--------

As an aside, you say that:

I now knew why the original code didn’t work – it did half a job, it did clear the shift register but, without the latch cycle, it did not update the storage/latch register so I could not witness the operation.

This suggests a reason why pin 10 might be labled "(not)SRCLR", instead of "(not)MR".

"MR" (Master Reset) might be interpreted as the pin that resets the whole chip .... but as you thoughtfully explain, the outputs do not change until you update the latches.

 

Hope this is of interest and helpful. Best wishes, Dave


   
ReplyQuote
ron bentley
(@ronbentley1)
Member
Joined: 3 years ago
Posts: 385
Topic starter  

@davee 

Hi Dave

many thanks for your post and observations.

Interesting - the image of the 74HC595 pin outs in my post do not show the bar symbol over OE and SRCLR as you have noted.  Strange, as my Arduino Project Hub article on this (see link in my post above) does indeed show these bars!

I can only assume I picked up an incomplete image for the IC from somewhere when I put the post together, don't know where, but I will be alert to check for completeness in future.

If you see my Project Hub post you will see that I came to the conclusion that programmatic control of the SRCLR pin is of dubious value and I would, perhaps, prefer to have the digital pin back for other uses.

As for the OE pin then I would again struggle to see a programmatic use for this pin also.

I hope my post extends the understanding of interested parties in using these very useful ICs and thank you for noting the error in the 74HC595 image and your explanation of the OE pin functionality.

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
DaveE and Inst-Tech reacted
ReplyQuote
(@davee)
Member
Joined: 4 years ago
Posts: 1924
 

Hi @ronbentley1,

  Thanks for taking the trouble to prepareyour explanationa and of replying to my comments.

  I thought it was strange that your image had lost its overbars as well ...  just an everyday hazard of the Internet where copying something is a trivial operation.

I guess the 595 was designed in a different era, before the proliferation of low cost microcontrollers, when it would have been part of main controlling mechanism in its own right, and clearing the shift register might have been a useful function.

Similarly, the OE output enable is presumably to allow two or more 595s to have their outputs paralleled in tri-state bus fashion, with the OE of each being used to select which device is driving the bus at any one time.

Given that the Texas Instrument 74 series dates back to around 1970, it seems remarkable (to me) that the same functions, albeit in CMOS technology, are still around, even if they are limited to playing a support role, with some of their functionality being 'a solution looking for a problem'.

Best wishes, Dave


   
ron bentley reacted
ReplyQuote
ron bentley
(@ronbentley1)
Member
Joined: 3 years ago
Posts: 385
Topic starter  

@davee 

Thanks for feedback.

I had similar thoughts about the age of the design.

I like your observation about the use of the OE pin, I will have to give that a bit of thought about how useful it may be (or not).

Cheers for now

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
DaveE reacted
ReplyQuote