กลับไปหน้ารวมไฟล์
shift-registers-tutorial-3-using-timers-e4d02a-en.md

If you have arrived at this article by random means and not via its starting point, then you may find that it may not make much sense. This is because this article is one of several (six) tutorials to aid and assist in understanding the use of the ez_SIPO8_lib library in managing and controlling Serial-in/Parallel-out ICs (SIPOs) shift registers, for example 74HC595 chips.

If you wish to link to the start of the tutorial then please follow this link (Tutorial Start), otherwise, please read on...

A tutorial to consolidate understanding and use of the ez Serial-in/Parallel-out IC Library (ez_SIPO8_lib) - Tutorial 3, Using Timers. If you wish to link to the tutorial starting article then follow this link: Tutorial Start.
You can access and download the User Guide, Crib Sheet and the original ez_SIPO8_lib article by following these links below:
- ez_SIPO8_lib User Guide
- ez_SIPO8_lib Crib Sheet
- Read the full ez_SIPO8_lib article

Project Perspective

Shift Registers - Tutorial 3, Using Timers is a sophisticated exploration of digital technology and asynchronous-timing interaction. By focusing on the essential building blocks—the 74HC595 serial-to-parallel storage architecture and multi-channel non-blocking software timers—you'll learn how to communicate and synchronize logic tasks using a specialized software library and a robust manual setup.

Introduction to the Tutorial

In this third tutorial we will build on our Tutorial 1 and 2 experiences and look at how we can use the SIPO8 library timer features to control the status of SIPO IC output pins. We shall make use of the same physical SIPO IC circuit we set up in Tutorial 1.

The tutorial will configure eight SIPO8 timers, one for each of the SIPO output pins and use these to control the rate at which we wish to flash the respective connected LEDs on/off. The approach will be flexible allowing us to easily vary flash rates and output pin ordering.

Objectives

We shall concern ourselves with creating a virtual SIPO environment in which we can apply further basic principles. In particular we shall learn:

1. how we can wire up and connect a single 74HC595 IC (SIPO) to a microcontroller (see Tutorial 1, if you have not already done so)

2. how we can use in-built SIPO8 library timer functions to control and drive physical SIPO outputs

3. the further use of SIPO8 library functions

4. witness the outputs of the sketch – variable flashing LEDs and serial monitor SIPO data.

If you ran through Tutorials 1 and 2 and still have your components set up as for that tutorial, then skip to The Code/Sketch, otherwise continue as below.

Technical Implementation: Asynchronous Logic and Background Timers

The project reveals the hidden layers of simple data-to-time interaction:

  • Identification layer: The 74HC595 Register acts as a high-resolution digital memory, measuring each bitstream arrival via its serial input.
  • Conversion layer: The system uses high-speed digital Pins (Data, Clock, Latch) to receive high-speed binary pulses to coordinate mission-critical sensing tasks.
  • Temporal Interface layer: The ez_SIPO8 Library Timers provide high-resolution visual and temporal feedback for each task status check (e.g., Led-Toggle vs Loop-Cycle).
  • Communication Interface layer: High-speed Serial Terminal provides a clear and reliable visual interface for each point of telemetry logs.
  • Processing Logic: The Arduino code follows an "asynchronous-dispatch" (or timer-dispatch) strategy: it interprets task-specific intervals and matches pin states to provide safe and rhythmic digital operations without delay().
  • Communication Dialogue Loop: Timing codes are sent rhythmically to the Serial Monitor during initial calibration to coordinate status.

Hardware-Register Infrastructure

  • Arduino Uno: The "brain" of the project, managing multi-directional serial data pulses and coordinating register and timer sync.
  • 74HC595 IC: Providing a clear and reliable "Digital Link" for each point of the logic circuit.
  • LED Array (8x): Providing a high-capacity and reliable physical interface for each point of the mission.
  • Breadboard: A convenient way to prototype the first logic-electronics circuit and connect all components without soldering.
  • ez_SIPO8 Library: Essential for providing a clear and energy-efficient programming platform for each point of the register-logic.
  • Micro-USB Cable: Used to program the Arduino and provides the primary interface for the system controller.

Kit List

Gather together the following components:

  • 1 x Arduino UNO - The design uses an Arduino UNO, but any suitable microcontroller (Arduino or clone) will do, providing it is able to support the pin out requirements for driving the SIPO interface and power requirements
  • 1 x Breadboard - Small or large, whatever you have to hand
  • 1 x 74HC595 IC - 8-bit SIPO IC, or other clone providing it is genuinely ‘plug-compatible’
  • 8 x LEDs - Whatever you have around
  • 8 x Resistors, 220 ohm - One per LED. Use 220 ohm resisters and ignore the suggested 180 ohm values in the wiring diagrams
  • Connecting wires - Short/long or breadboard wire connectors, whatever suits

74HC595 Orientation and Pin Outs

Which end is which? Well, notice that the 74HC595 has a notch at one end, here at the top of the diagram. Pin numbering starts at 1 at the top left and continues down the left hand side and the around the bottom of the IC rising to the top right hand side to pin 16:

Pin Outs 1 - 74HC595

Microcontroller/SIPO Interface Pin Configuration

Every bank of SIPO ICs you connect to the microcontroller requires a 3-wire digital interface (3WI). As this tutorial concerns a single SIPO IC then we shall only need one x 3WI. The table below suggests pin mapping between the microcontroller and the SIPO IC for this tutorial, but you may choose what microcontroller digital pins you wish. If you do choose different pins then be sure to alter the sketch function create_bank call in setup().

  • UNO pin 8 to SIPO pin 14 - SIPO Data Pin
  • UNO pin 9 to SIPO pin 12 - SIPO Latch Pin
  • UNO pin 10 to SIPO pin 11 - SIPO Clock Pin
  • UNO pin +5v to SIPO pins 10, 16 - Power to the SIPO
  • UNO GND pin to SIPO pins 8, 13 - Return ground (0v)

Connecting It All Together

Using the following diagram, wire up all of the components, taking care to get the output/input connections correct:

Wiring Scheme 1- Single SIPO IC, 8 outputs

Notice that the only 74HC595 IC pin not to have anything connected is pin 9, QH’. This is used as the serial output pin to connect to the serial input pin, 14SER, of the next SIPO 74HC595 in a cascade.

Timing Hub Automation and Interaction Step-by-Step

The shift-register timing process is designed to be very efficient:

  1. Initialize Workspace: Correctly seat your 74HC595 register and the LEDs inside your breadboard and connect them properly to the Arduino pins as shown in the wiring diagram above.
  2. Setup Output Sync: In the Arduino sketch, initialize my_SIPOs.begin() and define the timer intervals (e.g., 500ms) in setup().
  3. Internal Dialogue Loop: The station constantly performs high-performance digital loops and updates the pin status in real-time based on your background settings.
  4. Visual and Data Feedback Integration: Watch your LED dashboard automatically become a rhythmic status signal, pulsing and following your logic settings from a distance.

The Code/Sketch

Now that’s done, let’s look at a sketch using timers to control variable flashing LEDs, download the sketch, compile and upload.

//
// Tutorial 3 - use of ez_SIPO8 library,
// 1x physical SIPO, and use of SIPO8 timers to control SIPO outputs with time
//
// Ron D Bentley, Stafford, UK
// April 2021
//
// This example and code is in the public domain and
// may be used without restriction and without warranty.
//
#include <ez_SIPO8_lib.h>
#define Max_SIPOs 1 // one virtual SIPO for this tutorial
#define Max_timers 8 // 8 timers required to map a complete 8bit SIPO
// initiate the class for Max SIPOs/timers required
SIPO8 my_SIPOs(Max_SIPOs, Max_timers);
int bank0_id; // used to keep the SIPO bank id
//
// setup pin/LED flash data
uint8_t timer;
uint32_t timer_intervals[Max_timers] = {
300, 400, 500, 600, 700, 800, 900, 1000 // millisecond elapse timer values
};
uint8_t timer_pins[Max_timers] = {
0, 1, 2, 3, 4, 5, 6, 7 // SIPO output pin absolute addresses
};
void setup() {
Serial.begin(9600);
// create bank, params are:
// data pin, clock pin, latch pin, number of SIPOs this bank
bank0_id = my_SIPOs.create_bank(8, 10, 9, 1);
if (bank0_id == create_bank_failure) {
Serial.println(F("\
failed to create bank"));
Serial.flush();
exit(0);
}
// print the bank data for confirmation/inspection
my_SIPOs.print_SIPO_data();
}
void loop() {
// start by setting all SIPO outputs to low (off)
my_SIPOs.set_all_array_pins(LOW);// set all declared virtual output pins LOW/off
my_SIPOs.xfer_array(LSBFIRST); // move virtual pin statuses to real SIPO output pins
//
// start all timers
for (timer = 0; timer < Max_timers; timer++) {
my_SIPOs.SIPO8_start_timer(timer);
}
timer = 0; // start checking at first timer
do {
// check each timer for elapse and, if elapsed, invert the timer's output pin
// and reset the timer
if (my_SIPOs.SIPO8_timer_elapsed(timer, timer_intervals[timer]) == elapsed) {
my_SIPOs.invert_array_pin(timer_pins[timer]); // invert the pin associated with this timer
my_SIPOs.xfer_array(MSBFIRST);// update physical SIPO outputs
my_SIPOs.SIPO8_start_timer(timer);// reset/restart the current timer
}
timer++; // move on to next timer
if (timer >= Max_timers) timer = 0; // wrap around to beginning
} while (true);
}

To Notice:

1. that we automatically configure the eight timers we need for our purposes (one per output port/LED) as a part of the SIPO8 class instantiation (second parameter, here 8). We can create up to255 timers if desired, but that’s a lot!

2. we declare and preset two arrays to define the flash rate intervals (in milliseconds) and the associated absolute output pin numbers we wish to control –

uint32_t timer_intervals[Max_timers], and

uint8_t timer_pins[Max_timers]

These arrays allow us to easily vary flash rates and change the order of output pins as we desire

3. there are three SIPO8 library functions that allow us to utilise and control SIPO8 timers, these being:

  • SIPO8_start_timer (timer)
  • SIPO8_timer_elapsed(timer, timer_intervals[timer]) and
  • SIPO8_stop_timer (timer)

Each timer function takes an initial parameter which is the timer number we wish to reference. However, in the case of SIPO8_timer_elapsed then this function has a second parameter which is the elapsed time interval we wish to check against for elapsed time (milliseconds), here it is the interval for the timer to run before it expires. Note that this second parameter is an unsigned 32 bit variable, so watch how you define these values in your sketches.

The sketch does not use the SIPO8_stop_timer function, but it is fully documented in the User Guide and

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "1x Arduino IDE"
  - "1x ez_SIPO8 Library"
author: "ronbentley1"
category: "Computer & PC, Lab Stuff"
components:
  - "1x Arduino UNO"
  - "1x 74HC595 Shift Register"
  - "8x LEDs (for visualization)"
  - "8x Resistors 220 Ohm"
  - "10x Jumper wires (generic)"
  - "1x Mini Breadboard"
  - "1x Micro-USB Cable"
description: "A professional and advanced digital logic tutorial that teaches you how to implement high-precision background timing in 74HC595 shift register circuits using the ez_SIPO8 library and non-blocking asynchronous timers."
difficulty: "Intermediate"
documentationLinks: []
downloadableFiles:
  - "https://projects.arduinocontent.cc/5b7e3579-0933-4a34-87a9-cc027d42a5db.ino"
  - "https://projects.arduinocontent.cc/5b7e3579-0933-4a34-87a9-cc027d42a5db.ino"
encryptedPayload: "U2FsdGVkX1/q7lC9Fz7iXejq6qFuJLr+B47HLlXKm5Li0NLdMYZhzSwQe1brjwc6+1SfFMdr3gaqAV5zrrXyJgz7nl59cqc7uoLBf8GMvT0="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/shift-registers-tutorial-3-using-timers-e4d02a_cover.jpg"
lang: "en"
likes: 0
passwordHash: "efba31563485bbea51266692a877fd540455efd142a5f2a375b4d75e7d945b8b"
price: 299
seoDescription: "An advanced and playsomely interactive Shift-Register-Timing-Tutorial for beginners interested in Arduino non-blocking-logic and register-to-timer projects."
tags:
  - "shift-registers-tutorial"
  - "74hc595-timing"
  - "asynchronous-logic"
  - "ez-sipo8-library"
  - "arduino-uno"
  - "advanced"
title: "Shift Registers - Tutorial 3, Using Timers"
tools: []
videoLinks: []
views: 3125