Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Shift register problems


  • Please log in to reply
22 replies to this topic

#1 SpitfireMike

SpitfireMike

    Member

  • Members
  • PipPip
  • 17 posts
  • LocationColorado Springs, CO, USA

Posted 12 April 2012 - 02:20 AM

Not sure where else to post this...

Using a Netduino with 4.1.0.6, 74HC595 shift register, 8-channel relay board, and the past 2 months trying to get this to work.
Using the Toolbox.NETMF.Hardware.Ic74HC595 class, wiring diagram from http://netmftoolbox....dware.Ic74HC595. Code if based on the sample code from the same page, mods are only using 1 shift register and I'm writing the pin I'm setting to a separate 4-digit LED display. Power is coming from a 12V wall-wart.


When everything is connected, usually one of the relays turns on (indicator LED lights up and I hear the relay click). I see the 4-digit display increment, and very occasionally another relay will turn on. The strange thing is I can get it to work correctly by disconnecting the latch wire from the Netduino D9 pin. With the wire disconnected, it works when I'm holding the wire.

The relay board works when each pin is directly connected to the digital pins on the netduino, so I assume that the relay board is OK. I've tried 10 different 74HC595 shift registers,4 different breadboards, 2 different Netduinos and more jumper wires than I can count. It doesn't matter if the Netduino is powered by the 12V wall-wart, USB or both.

Somewhat blurry photo of the circuit is attached.
Any help is very much appreciated.


Mike

Attached Files



#2 Thomas Rankin

Thomas Rankin

    Member

  • Members
  • PipPip
  • 26 posts

Posted 12 April 2012 - 03:09 AM

Not sure where else to post this...

Using a Netduino with 4.1.0.6, 74HC595 shift register, 8-channel relay board, and the past 2 months trying to get this to work.
Using the Toolbox.NETMF.Hardware.Ic74HC595 class, wiring diagram from http://netmftoolbox....dware.Ic74HC595. Code if based on the sample code from the same page, mods are only using 1 shift register and I'm writing the pin I'm setting to a separate 4-digit LED display. Power is coming from a 12V wall-wart.


When everything is connected, usually one of the relays turns on (indicator LED lights up and I hear the relay click). I see the 4-digit display increment, and very occasionally another relay will turn on. The strange thing is I can get it to work correctly by disconnecting the latch wire from the Netduino D9 pin. With the wire disconnected, it works when I'm holding the wire.

The relay board works when each pin is directly connected to the digital pins on the netduino, so I assume that the relay board is OK. I've tried 10 different 74HC595 shift registers,4 different breadboards, 2 different Netduinos and more jumper wires than I can count. It doesn't matter if the Netduino is powered by the 12V wall-wart, USB or both.

Somewhat blurry photo of the circuit is attached.
Any help is very much appreciated.


Mike


This site illustrates about as basic a circuit you can get with the Netduino and the 74HC595 Shift Register.

http://wiki.netduino...t-Register.ashx

I always start with this to make sure I've got the base wired up correctly but I've always done it with my Arduino.

I'm getting ready to start another Shift Register project but with my Netduino this time, I'll work on wiring it up and let you know how it goes.

#3 Thomas Rankin

Thomas Rankin

    Member

  • Members
  • PipPip
  • 26 posts

Posted 12 April 2012 - 04:54 AM

I was able to successfully set up the shift register from the example link I provided. I then rewired a bit and rewrote the code to use the library that you referenced except that I changed it to use one shift register instead of two like the example, and changed the function to count in binary like the original example.



public static void Main()
        {
            Ic74HC595 IcOut1 = new Ic74HC595(SPI.SPI_module.SPI1, Pins.GPIO_PIN_D9);
            // Defines all 8 leds
            OutputPortShift[] Leds = new OutputPortShift[8];
            for (uint Counter = 0; Counter < 8; ++Counter)
            {
                // Leds on the first Ic
                Leds[Counter] = new OutputPortShift(IcOut1, (Ic74HC595.Pins)Counter, false);
            }

            // Does a ledloop
            while (true)
            {
                for (byte b = 0; b <= 255; b++)
                {
                    for (byte Counter = 0; Counter < 8; ++Counter)
                    {
                        Leds[Counter].Write(GetBit(b, Counter));
                    }
                    Thread.Sleep(50);
                }

            }
        }

        static bool GetBit(byte b, int bitNumber)
        {
            return (b & (1 << bitNumber)) != 0;
        }


#4 Thomas Rankin

Thomas Rankin

    Member

  • Members
  • PipPip
  • 26 posts

Posted 12 April 2012 - 05:10 AM

Because of the angle on the picture I can't tell if everything is wired up correctly, although everything looks generally right. Netduino Pin 13 - Shift Register Pin 11 Netduino Pin 11 - Shift Register Pin 14 Netduino Pin 9 - Shift Register Pin 12 Shift Register Pin 16 - Vcc Shift Register Pin 13 - Gnd Shift Register Pin 10 - Vcc Shift Register Pin 8 - Gnd Shift Register Pin 9 - Open The rest of the Shift Register Pins should go to your LEDs or Relays

#5 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 12 April 2012 - 09:53 AM

Hi

Without seeing your code I assume you are using SPI to communicate with your shift register?

If so how are you writing to the shift register, are you sending each byte individually

//Should turn each pin on sequentially
SPI.Write(new byte[]{0x01});
SPI.Write(new byte[]{0x02});
SPI.Write(new byte[]{0x04});
SPI.Write(new byte[]{0x08});
SPI.Write(new byte[]{0x10});
SPI.Write(new byte[]{0x20});
SPI.Write(new byte[]{0x40});
SPI.Write(new byte[]{0x80});

Or are you trying to write an array?

//Should turn each pin on sequentially by writing an array to the shift register(s)
SPI.Write(new byte[]{0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80});

If you are trying to write an array at once then the issue is that the latch enable is only triggered at the end of writing the array, where as what you want is for the the latch to be triggered after each byte is written.


If the above describes your problem then their are several solutions to it:

The easiest solution is to write each byte individually to the register as the latch pin is toggled during each write cycle.

If you need to write arrays of bytes at a time, then you either need to modify the firmware to latch after each byte (I have done this in order to get a SPI serial device working correctly and at high speed (256000 baud)), or provide additional hardware to cause the correct triggering of your latch.

Mario Vernari has a couple of excellent posts on his blog about how to achieve this by adding some additional logic devices here

#6 SpitfireMike

SpitfireMike

    Member

  • Members
  • PipPip
  • 17 posts
  • LocationColorado Springs, CO, USA

Posted 12 April 2012 - 04:52 PM

Yes, I'm trying to use SPI with the Ic74HC595Chain and Ic74HC595 classes from the http://netmftoolbox.codeplex.com/. SPI seemed to be the way to do it with the Netduino. I'll try the manual technique from http://wiki.netduino...t-Register.ashx tonight.

The confusing part to me is why this works when the latch is not receiving the signal from the Netduino and I'm holding or close to the latch wire.

#7 SpitfireMike

SpitfireMike

    Member

  • Members
  • PipPip
  • 17 posts
  • LocationColorado Springs, CO, USA

Posted 12 April 2012 - 07:54 PM

Here's a video of what's happening. Loud clicks are the relays turning on. Relay board on the left, green LEDs when the relay is on. 4-char 7-segment LED at top left shows which relay should be on. Yellow wire is the latch wire, first connected to pin 9, then disconnected. You can see/hear that the correct relay turns on only when it is not connected and my hand is close to or touching the yellow disconnected wire.

Hey...did I just stumble across an undocumented capacitive activation feature?<g>

1 minute video



(edited link)

#8 SpitfireMike

SpitfireMike

    Member

  • Members
  • PipPip
  • 17 posts
  • LocationColorado Springs, CO, USA

Posted 13 April 2012 - 01:57 AM

OK, using the code and wiring diagram from http://wiki.netduino...t-Register.ashx, everything is working. The clicking relays are very melodic, true music to my ears<g>

For what I'm going to be doing, this will probably work. I'll be using the relays to enable/disable circuits in my '69 Triumph Spitfire, I won't be toggling the relays rapidly, don't require micro-second response times, etc.

This leads me to believe that there's something wrong with either the SPI implementation in the Netduino or in the Ic74HC595 classes from Toolbox.NETMF. I stripped out the LED display, everything except the Netduino, shift register, relay boards and jumper wires. Exact same symptoms using SPI, does not work when the latch wire is connected to the latch pin (GPIO9 in my case), works when that wire is disconnected and I'm either holding the wire or have my hand within an inch or so.

Of course, I'd like to use SPI, code is easier to read, heavy lifting is done elsewhere, etc, but it's good to have a fallback plan.

Here's the code for both SPI and !SPI, comment/uncomment the UseSPI define at the top to switch between them. Wiring is different, connections to the shift register are in the comments.


//#define UseSPI
using System.IO.Ports;
using System.Threading;
using Microsoft.SPOT.Hardware;
using Toolbox.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoApplication1
{
    public class Program
    {
        // wire colors from [url="http://netmftoolbox.codeplex.com/wikipage?title=Toolbox.NETMF.Hardware.OutputPortShift"]http://netmftoolbox.codeplex.com/wikipage?title=Toolbox.NETMF.Hardware.OutputPortShift[/url]
#if UseSPI
        // C595 11 - GPIO 13 (Orange)
        // C595 12 - GPIO 9  (Yellow)
        // C595 14 - GPIO 11 (Blue)
        public static OutputPortShift[] relayPins = new OutputPortShift[8];
        public static void Main()
        {
            Ic74HC595Chain shiftRegisterChain = new Ic74HC595Chain(SPI.SPI_module.SPI1, Cpu.Pin.GPIO_Pin9, 1);
            Ic74HC595 shiftRegister = new Ic74HC595(shiftRegisterChain, 0);

            for (int relayInit = 0; relayInit < 8; relayInit++)
                relayPins[relayInit] = new OutputPortShift(shiftRegister, (Ic74HC595.Pins)relayInit, false);

            while (true)
            {
                for (int counter = 0; counter < 8; counter++)
                {
                    // turn the relay on
                    relayPins[counter].Write(true);
                    Thread.Sleep(1000);
                    // turn it off
                    relayPins[counter].Write(false);
                }
            }
        }
#else // don't use SPI
        // C595 11 - GPIO 3 (Orange)
        // C595 12 - GPIO 4 (Yellow)
        // C595 14 - GPIO 2 (Blue)
        static OutputPort data = new OutputPort(Pins.GPIO_PIN_D2, false);
        static OutputPort clock = new OutputPort(Pins.GPIO_PIN_D3, false);
        static OutputPort latch = new OutputPort(Pins.GPIO_PIN_D4, false);

        public static void Main()
        {
            int delayTime = 50;

            while (true)
            {
                for (int i = 0; i < 256; i++)
                {
                    updateLEDs(i);
                    Thread.Sleep(delayTime);
                }
            }
        }

        static void updateLEDs(int value)
        {
            latch.Write(false);

            for (int i = 0; i < 8; i++)
            {
                int bit = value & 0x80;
                value = value << 1;
                if (bit == 128)
                {
                    data.Write(true);
                }
                else
                {
                    data.Write(false);
                }

                clock.Write(true);
                Thread.Sleep(1);
                clock.Write(false);
            }
            latch.Write(true);
        }
#endif
    }
}



#9 Thomas Rankin

Thomas Rankin

    Member

  • Members
  • PipPip
  • 26 posts

Posted 14 April 2012 - 01:42 AM

Not that I think that it should make any difference, but the only real difference I see between your execution with the driver and mine is that you use the chain, and I bypassed it altogether because I only had one shift register. I still used the driver, but not the chain class.

#10 SpitfireMike

SpitfireMike

    Member

  • Members
  • PipPip
  • 17 posts
  • LocationColorado Springs, CO, USA

Posted 15 April 2012 - 03:47 AM

I'm thinking that I just have a few bad Netduinos. I got the two I tested with at the same time, maybe there's someting subtle in the chip, traces, etc. A Netduino that I got last month seems to work OK, the the Netduino Mini seems to be OK also (but I didn't try that with the relays, just LEDs). I think I'll stick with the manual technique so I don't have to worry about which board I'm using. The Ic74HC595 class from Toolbox.NETMF.Hardware creates the chain internally and uses that, so the chain is implied if not explicit.

#11 V64

V64

    Member

  • Members
  • PipPip
  • 20 posts

Posted 26 December 2012 - 04:56 PM

 there  appears to be some conclusion in the above

 

Exact same symptoms using SPI, does not work when the latch wire is connected to the latch pin (GPIO9 in my case), works when that wire is disconnected and I'm either holding the wire or have my hand within an inch or so.

 

I have just spent Xmas coming to the same conclusion - namely that there is some kind of problem with the Toolbox SPI implementation in the Netduino or in the Ic74HC595 classes from Toolbox.NETMF.

 

Would one of the experts please care to comment/deny/confirm?

 

Thank-you



#12 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 December 2012 - 05:11 PM

Hi V64,

 

On the Netduino Plus 2, there seem to be some SPI issues. on the other netduino models the code is tested and should be fine. Only pin D4 had some issues but the code has a workaround for that built in.


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#13 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 26 December 2012 - 06:06 PM

 there  appears to be some conclusion in the above

 

Exact same symptoms using SPI, does not work when the latch wire is connected to the latch pin (GPIO9 in my case), works when that wire is disconnected and I'm either holding the wire or have my hand within an inch or so.

 

I have just spent Xmas coming to the same conclusion - namely that there is some kind of problem with the Toolbox SPI implementation in the Netduino or in the Ic74HC595 classes from Toolbox.NETMF.

 

Would one of the experts please care to comment/deny/confirm?

 

Thank-you

If you are using the "old" Netduino (even Plus), the SPI works fine: there are some minor problems, but the ability of drive one or more 74HC595 has been proven many and many times. However, there are several reasons for a so simple circuit not working as expected.

Just some considerations:

  • the wiring of the SPI should be pretty short (10-15 cm), and the length of the wires should be almost the same;
  • in a wired circuit as the users normally do, the SPI frequency should not exceed 1-2 MHz: higher frequencies yields lots of problems;
  • if your circuit involves loads need current (e.g. relays or so), the power wiring is important;
  • when you leave an input floating (without pull-up, as most of the chips is) you may experience an unpredictable behavior.

 

Suggestions:

  • provide a *good* grounding, from the Netduino board to the HC595 circuit (and everything else).
  • supply the HC595 with the Netduino +5V or +3.3V (depending on your circuit), but tend to supply special loads as above described with a separate supply.

 

Hope it helps.

Cheers


Biggest fault of Netduino? It runs by electricity.

#14 V64

V64

    Member

  • Members
  • PipPip
  • 20 posts

Posted 26 December 2012 - 07:22 PM

Stefan and Mario

 

Thank-you for your comments - I have connected the Netduino via.  a Powered Hub - and use 5v to power the LCD etc - and checked for ground/power loops.

There are no other connections my Netduino (recently purchased).

Reduced the length of connections between the Netduino and the Shift Register

Reduced the clock to 100 when instantiating the shift register

I am running only one Shift Registsre to Pin 9 is not connected.

 

I am running the code from the Toolbox library samples ( unaltered except for the clock rate). SR Pin 11 to Net Pin 13,  SR pin 14 to Net Pin 11, SR Pin 12 floating it works.

 

If I plug the Shift Register Pin 12 into Net pin 10 the display either freezes or runs hesitantly with incorrect display.

 

The LCD leds are on a 580ohm.

 

No problems if I drive the LCD manually on Arduino, or Netduino (i.e. not through Toolbox).

 

I would be amazed if this is some kind of Software problem in the Toolbox - but I am equally shocked to find that it does not work - flakey hardware with something this simple is not something I can cope with! I have tried multiple SRs and LCDs (of the same brand)

 

Maybe this a timing issue (I am using a YSD-160AR4B-8 which does not conform to the normal pin outs, and maybe different in other unspecified ways)

 

Thanks again for your responses.



#15 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 28 December 2012 - 04:22 AM

V64, could you post a picture of your circuit? I mean the real wiring...

My guess is about the power supply of the 74HC595, which alters the SPI signals.

Cheers


Biggest fault of Netduino? It runs by electricity.

#16 V64

V64

    Member

  • Members
  • PipPip
  • 20 posts

Posted 28 December 2012 - 08:59 PM

Here is a photo - I hope it is legible.

 

SR Pin12 wire is left floating. SR Pin 13 to Ground, SR Pin 10 to +5v

 

Net P13 to SR Pin 11, Net P11 to SR Pin14.

 

All on the Net 5v supply.

 

If the lead to SR Pin12 is removed the display freezes, as it does if it connected to Net P10.

 

Thank-you for your interest

 

David

Attached Files



#17 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 29 December 2012 - 05:03 AM

I experienced troubles when the power supply is particularly "dirty" of noise. That is mostly related to laptops or desktops pc adapters.

Please, try one (or both) of the followings:

  • supply the whole breadboard circuit using the +3.3V instead of the +5V (no matter if the display shines lesser);
  • keeping the BB supply at +5V, power the Netduino with an additional adapter through the barrel jack.

Do you see any improvement?


Biggest fault of Netduino? It runs by electricity.

#18 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 29 December 2012 - 12:34 PM

iam having some kind of register problem too, its a small glitch.

iam using the 595 and i see "shadows" on my led matrix. latch and everything is connected correct.

like that:

xxxx

x00x

xxxx

 

the x are the "bright" turned on leds, but the 0'S are also kinda on (i barley can see that, but when its dark and i watch closly, there is definitv a little light)

 

i have 100nf capacitor at + <> gnd.

shall i place more caps somewhere else? latch maybe?

iam using very basic code, i just send out data normal as byte[] per spi at 10mhz (same effect at 1mhz)

 

thats my spi config:

SPI.Configuration(Pins.GPIO_PIN_18, false, 0, 0, false, true, 10000, SPI_Devices.SPI1)



#19 V64

V64

    Member

  • Members
  • PipPip
  • 20 posts

Posted 29 December 2012 - 12:37 PM

Mario,

 

Using 3.5v makes no difference, nor does running the Net from a powered hub (as opposed to the power from theMac USB port. I do not have a Barrel supply to try.

 

This version (below) works fine - abeit it just counts its way round the bars - rather than displaying digits.

 

Is it a timing problem with the SS clock edge arriving too early?

 

//namespace test //{ //   public class Program //   { //   private static SPI SPIBus; //   public static void Main() //   { //   // Defines the first SPI slave device with pin 10 as SS //   SPI.Configuration Device1 = new SPI.Configuration( //   Pins.GPIO_PIN_D10, // SS-pin //   false, // SS-pin active state //   0, // The setup time for the SS port //   0, // The hold time for the SS port //   true,   // The idle state of the clock //   true,   // The sampling clock edge (this must be "true" for the 74HC595) //   2000,   // The SPI clock rate in KHz //   SPI_Devices.SPI1 // The used SPI bus (refers to a MOSI MISO and SCLK pinset) //   ); //   // Initializes the SPI bus, with the first slave selected //   SPIBus = new SPI(Device1); //   DoWorkSlow(); //   //DoWorkFast(); //   } //   /// //   /// Send 8 bytes out to the SPI (one byte at once) //   /// //   private static void DoWorkSlow() //   { //   //set-up a one-byte buffer //   byte[] buffer = new byte[1]; //   while (true) //   { //   for (int i = 0; i < 256; i++) //   { //   Thread.Sleep(1000); //   buffer[0] = (byte)i; //   SPIBus.Write(buffer); //   } //   Thread.Sleep(5000); //   } //   } //   } //}



#20 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 29 December 2012 - 01:20 PM

iam having some kind of register problem too, its a small glitch.

iam using the 595 and i see "shadows" on my led matrix. latch and everything is connected correct.

like that:

xxxx

x00x

xxxx

 

the x are the "bright" turned on leds, but the 0'S are also kinda on (i barley can see that, but when its dark and i watch closly, there is definitv a little light)

 

i have 100nf capacitor at + <> gnd.

shall i place more caps somewhere else? latch maybe?

iam using very basic code, i just send out data normal as byte[] per spi at 10mhz (same effect at 1mhz)

 

thats my spi config:

SPI.Configuration(Pins.GPIO_PIN_18, false, 0, 0, false, true, 10000, SPI_Devices.SPI1)

 

Well, I won't bet a cent on 10MHz, unless everything is *very* well wired.

Are you sure about GPIO_PIN_18 ???

If you have a 100nF, then you'll never do a bad thing by placing across the 74HC595 supply. However, I would not add any other cap unless a valid reason for placing it.

Is it a standard Netduino the your's?

 

 

Mario,

 

Using 3.5v makes no difference, nor does running the Net from a powered hub (as opposed to the power from theMac USB port. I do not have a Barrel supply to try.

 

This version (below) works fine - abeit it just counts its way round the bars - rather than displaying digits.

 

Is it a timing problem with the SS clock edge arriving too early?

 

//namespace test //{ //   public class Program //   { //   private static SPI SPIBus; //   public static void Main() //   { //   // Defines the first SPI slave device with pin 10 as SS //   SPI.Configuration Device1 = new SPI.Configuration( //   Pins.GPIO_PIN_D10, // SS-pin //   false, // SS-pin active state //   0, // The setup time for the SS port //   0, // The hold time for the SS port //   true,   // The idle state of the clock //   true,   // The sampling clock edge (this must be "true" for the 74HC595) //   2000,   // The SPI clock rate in KHz //   SPI_Devices.SPI1 // The used SPI bus (refers to a MOSI MISO and SCLK pinset) //   ); //   // Initializes the SPI bus, with the first slave selected //   SPIBus = new SPI(Device1); //   DoWorkSlow(); //   //DoWorkFast(); //   } //   /// //   /// Send 8 bytes out to the SPI (one byte at once) //   /// //   private static void DoWorkSlow() //   { //   //set-up a one-byte buffer //   byte[] buffer = new byte[1]; //   while (true) //   { //   for (int i = 0; i < 256; i++) //   { //   Thread.Sleep(1000); //   buffer[0] = (byte)i; //   SPIBus.Write(buffer); //   } //   Thread.Sleep(5000); //   } //   } //   } //}

 

As far I know, only the Netduino Plus 2 has a bug on the SPI, not the old versions.

Anyway, even the newest Netduino works fine if you use the settings that you have used in your snippet.

So, let me wrap up: what's the current status of your project? Is it not working with the Toolbox libraries, or is it anything else?


Biggest fault of Netduino? It runs by electricity.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.