1

I currently have an Arduino Mega project that uses a relay to switch some high voltage loads. Currently, I use a scheduler library so that every 250ms I check if certain conditions are met and if so I turn off or on the relay. The relay is active when pulled down.

I'm trying to figure out how to transition this project to using a shift register. If the pin needs to be pulled low to be turned on and I want to keep it on, how do I supply a steady "low" signal using a shift register if the register is clocked to only latch every 8 clock cycles (not to mention I only run this code every 250ms). Even if every bit that gets sent by the shift register is low, do I need to no longer use the scheduling library so that every time through the Arduino loop I am sending the low signal so that the low signal can remain constant? With the standard Arduino pin once I set it to low it stays low until I switch it to high. But with a shift register can I keep it low "until I switch it high?"

1
  • This is only a problem if you have an unlatched shift-register.
    – Gerben
    Commented Feb 15, 2016 at 19:12

2 Answers 2

2

You have misunderstood how shift registers work - and one of the main reasons they exist in the first place.

Shift register ICs have a common 'latch' pin which latches the data present at the input of the cell into the cell, thus updating the output. Some ICs also offer an "output enable", which switches the outputs to a high-impedance state irrespective of the values in the cells - this might not be useful in your case, but the feature exists.

With a serial-to-parallel shift register you can shift in as many bits as you want, at whatever rate you choose, and the outputs will never change until you trigger a rising edge on the LATCH pin.


How a (latching) Shift Register works:

You have eight spaces within the register:

             ___    ___    ___    ___    ___    ___    ___    ___ 
[DATA_IN]-->|___|--|___|--|___|--|___|--|___|--|___|--|___|--|___|-->[DATA_OUT]
            BIT0                                              BIT7

The 'spaces' are chained together; at one end of the chain is the DATA_IN pin and at the other end is the DATA_OUT pin.

Every time there is a rising edge on the CLOCK pin, data is shifted down the chain from DATA_IN to DATA_OUT, one space at a time. For example, if the state of the 'spaces' is as the left hand column, then upon the rising edge of the CLOCK pin the spaces will change to the values in the right hand column:

 DATA_IN PIN = 1  ->  C  -> ?
BIT0 'SPACE' = 0  ->  L  -> 1
BIT1 'SPACE' = 1  ->  O  -> 0
BIT2 'SPACE' = 1  ->  C  -> 1
BIT3 'SPACE' = 0  ->  K  -> 1
BIT4 'SPACE' = 0  ->  E  -> 0
BIT5 'SPACE' = 1  ->  D  -> 0
BIT6 'SPACE' = 1  ->  G  -> 1
BIT7 'SPACE' = 0  ->  E  -> 1

You will see that BIT(n) changes to the value of BIT(n-1), with BIT0 changing to the value of DATA_IN. The DATA_OUT pin is used to daisy-chain multiple shift registers together. The important thing to note here is that the outputs do not change without a rising edge on the LATCH pin. You can pulse CLOCK as many times as you want, with whatever values on DATA_IN, and the outputs will not change. Ever.

When you finally trigger the LATCH pin, the value in each 'space' is latched into a second row of 'spaces' - these represent the outputs. On a latch trigger, the outputs therefore change to the values of the last eight bits that were shifted into the DATA_IN pin. For example:

OUTPUT = 11001010
                   SHIFT IN "01101111" (starting with RHS first)
                               TRIGGER RISING EDGE ON 'LATCH' PIN
OUTPUT = 01101111
                   SHIFT IN "11110000110011001100"
                               TRIGGER RISING EDGE ON 'LATCH' PIN
OUTPUT = 11110000   i.e. the LAST EIGHT BITS that were shifted in
                   SHIFT IN "10"
                               TRIGGER RISING EDGE ON 'LATCH' PIN
OUTPUT = 10111100   again the LAST EIGHT BITS that were shifted in

It is generally never the case with a serial-in-parallel-out register that you would ever shift in less that eight bits at a time, so the last example is only there to illustrate the functioning of the IC.

7
  • Thank you for your response. Indeed, I do have a misunderstanding. There's one thing I'm still missing. If a relay requires a constant voltage, and the latch triggers every 8 clock cycles. How is a 'HIGH' signal maintained when using the shift register. Another way of putting it: if I have some code that runs on a scheduler every 1 second, and that code shifts all HIGH values into the register and latches it so it pushes a HIGH signal out, will the value drop to LOW between my 1 second intervals when I'm not actively pushing data.. if it does not shift to LOW, why is the HIGH value maintained?
    – Inc1982
    Commented Feb 17, 2016 at 14:48
  • @Inc1982 I've edited the answer, I hope this helps. Commented Feb 17, 2016 at 17:26
  • 1
    Thank you so much for the response. There's one small but important piece of information I'm missing. In my understanding a HIGH signal is say 40ma on an arduino pin, while a LOW signal is 0ma. In-between latches, is the signal kept constant until it is switched again? If so, that would imply that there is some constant power coming from the Arduino that is being fed through the shift register and out the pins. This must be separate from the 8 bits being pushing into the Arduino. Is that why shift registers need a separate power supply?
    – Inc1982
    Commented Feb 19, 2016 at 7:26
  • 'High' and 'Low' signals have nothing to do with current; they refer to voltage. There is negligible current flowing between the Arduino and a shift register, at any time. The shift register provides the power to the devices it controls. Commented Feb 19, 2016 at 8:48
0

... relay ... active when pulled down ... shift register ... latch ... Arduino ...

TPIC6C595

shiftOut() and the '595

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.