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

Any help on a ParallelIn SerialOut Bitshifter?


  • Please log in to reply
39 replies to this topic

#1 Stefan

Stefan

    Moderator

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

Posted 30 March 2011 - 09:15 PM

Hello :) Okay, here's a thing. SerialIn/ParallelOut is easy, I tested a few IC's, all according to plan. Now I want to reverse the progress. I've been testing with terry helping the whole evening but I can't seem to get it working. Anyone has experience with this and can give me a simple code and/or schematic to set up? We tried quite some configurations, but without any luck :( I tried these IC's with 8 pushbuttons: 74HC597 74HC165
"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

#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 31 March 2011 - 07:14 AM

Stefan, did you test the 'HC165 also? I am wondering why that is so hard to drive. Please, be sure to check what on the chip is the exact model: it must be 74HC165. Note that the very important marks are "HC" and 165. Other models could be LS, ALS, HCT, etc. They *DO NOT* works with the Netduino electric levels! "HC" is an acronym for "High-speed Cmos", that is versatile like a CMos and fast as a TTL. Let's check (about the 'HC165): - ground and supply (+5V) to 8 and 16, respectively - inputs connected to whatever you need (e.g. buttons); - /CE (15) to ground - Q7 (9) to MISO - CP (2) to SPI clock - /PL (1) to any output port of Netduino - /Q7 (7) left open That won't work? Remember to drive the /PL "manually" via software, not via the SPI API. Some questions: - what are you reading via software as inputs? - are the bits totally uncorrelated to the buttons? - are you sure the buttons (i.e. the 165 inputs) are swinging from 0 to 5V upon a key pressure? - the /PL input should be normally high (true), then tied low just before the reading, finally restored high. Are you doing so? - try this: connect a led between ground and the /PL pin, through a 2-5K resistor. It will light a few, but just to see the level. Now insert a 500ms sleep *before* and *after* the /PL setting. Do you notice everything correct? - if you have a multimeter (e.g. measure the voltage), I'd check the voltages across various point of the circuit. I'll going to buy a couple of 165 also on the next weekend, but you may try to check these points in the mean time. Cheers
Biggest fault of Netduino? It runs by electricity.

#3 Stefan

Stefan

    Moderator

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

Posted 31 March 2011 - 07:37 AM

Hi Mario,

I starting to really really like you :D
I didn't posted that on purpose because sometimes it just helps to unplug everything and start over again with a clean mind (in my experience).

The numbers I got were all but consistent to what I pushed. I tried push buttons with and without pull resistor (according to this schematic) and some other stuff, but nothing helped much.

I see you do "- /CE (15) to ground".
I can't recall I had two black cables to my IC, going to try that out tonight.

I'll going to buy a couple of 165 also on the next weekend, but you may try to check these points in the mean time.

LOL! I did the same, just ordered a couple of HC IC's (yep, the real CMos versions) just to toy with. they're cheap and fun (if it works!) :D


Thanks (again) for the help so far! Tu sei buono! :)
"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

#4 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 31 March 2011 - 10:01 AM

I tried push buttons with and without pull resistor

You must add the pullup resistor by using any external IC. The "internal pullup" feature is particular of certain MCUs, not ordinary logic.

Take care about avoid confusion.
The term "pullup" means resistor connected to the positive voltage (e.g. +5V), while pulldown is toward ground. If you choose to connect your buttons from +5V and the IC's input, you must use pulldowns.
However, it is most common habit to keep the reference to the ground. So connect pullups and buttons shorting to the ground. The logic is inverted, but it has electrical advantages.

Thanks (again) for the help so far! Tu sei buono!

Thanks for that, but I am just applying what you have sad: "It's never too late to learn". As far I may teach something to anyone, I'll learn something else. (That is the case of C native programming)
Cheers
Biggest fault of Netduino? It runs by electricity.

#5 Stefan

Stefan

    Moderator

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

Posted 31 March 2011 - 10:35 AM

Yea sometimes there is some truth in what I say :) Just to be sure, my push buttons have 4 pins, lets nummerate them: Pin 1 & 2 are connected inside, Pin 3 & 4 are connected inside. When pushed, all pins are connected to each other. Sooo, for the pullup principle as you describe it, I should connect it like this: Pin 1: Gnd Pin 2: Unused Pin 3: Resistor -> Vcc Pin 4: The IC Is that correct? 10kΩ should do?
"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

#6 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 31 March 2011 - 11:43 AM

That should be correct. 10K would fit perfectly, the value isn't absolutely critical. Your buttons should be the same model I have too. Their four pins are mainly useful for mechanical reasons. Anyway, the circuit is very simple. You should be able to check every single point of the wiring, to ensure the correct voltages. I cannot count how many times, looking for a problem, I was convinced to search in the most complex section. The real meaning is that I hadn't switched the power on. Cheers
Biggest fault of Netduino? It runs by electricity.

#7 Stefan

Stefan

    Moderator

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

Posted 31 March 2011 - 11:46 AM

Your buttons should be the same model I have too. Their four pins are mainly useful for mechanical reasons.

Indeed, with only 2 pins, it would be hard to press them without pushing them aside.

I cannot count how many times, looking for a problem, I was convinced to search in the most complex section. The real meaning is that I hadn't switched the power on.

Haha sounds slightly familiar I must confess.

Going to retry tonight!
"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

#8 Stefan

Stefan

    Moderator

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

Posted 31 March 2011 - 05:59 PM

I connected everything exactly like I got from this thread. Here is a picture of it:
Posted Image
(click for the bigger picture)

this is the code:
SPI spi = new SPI(new SPI.Configuration(
        Cpu.Pin.GPIO_NONE,
        false,
        0,
        0,
        false,
        true,
        1000,
        SPI_Devices.SPI1
));
OutputPort latch = new OutputPort(Pins.GPIO_PIN_D10, true);

byte[] wb = new byte[1];
byte[] rb = new byte[1];
uint i = 0;

while (true)
{
    ++i;
    latch.Write(!latch.Read());
    spi.WriteRead(wb, rb);
    latch.Write(!latch.Read());
    Debug.Print(i.ToString() + ":" + rb[0].ToString());
    Thread.Sleep(500);
}
And this is the output:

1:255
2:255
3:255
4:255
5:255
6:255
7:255
8:0
9:0
10:0
11:255
12:255
13:255

I pressed all buttons, nothing changed, until I pressed button 8. Then it went to 0. I pressed ONLY button 8, so I would expect 254 or 127, depending on the bit sequence.
"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

#9 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 31 March 2011 - 06:26 PM

Hmmm... Have you any tool to read the voltage across the buttons? A multimeter (better) or some led?
Biggest fault of Netduino? It runs by electricity.

#10 Stefan

Stefan

    Moderator

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

Posted 31 March 2011 - 06:29 PM

I got a multimeter, what do you want to know?
"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

#11 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 31 March 2011 - 06:36 PM

Huh!...That's my fault, maybe!
The /PL line should pulsed low *before* the beginning of the SPI transfer.

The /PL line, when low, copies the inputs status to the shift register: as long the /PL is low the buttons are copied to the shifter. That's because by pressing the 8' button, you read all zeroes!...The SPI clocks correctly, but the latest latch is always refreshed by the /PL!

Correct the loop as follows:

while (true)
{
    ++i;
    latch.Write(false);
    latch.Write(true);
    spi.WriteRead(wb, rb);
    Debug.Print(i.ToString() + ":" + rb[0].ToString());
    Thread.Sleep(500);
}
Cheers
Biggest fault of Netduino? It runs by electricity.

#12 Stefan

Stefan

    Moderator

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

Posted 31 March 2011 - 06:44 PM

Same result with this code:
SPI spi = new SPI(new SPI.Configuration(
        Cpu.Pin.GPIO_NONE,
        false,
        0,
        0,
        false,
        true,
        1000,
        SPI_Devices.SPI1
));
OutputPort latch = new OutputPort(Pins.GPIO_PIN_D10, true);

byte[] wb = new byte[1];
byte[] rb = new byte[1];
uint i = 0;

while (true)
{
    ++i;
    latch.Write(!latch.Read());
    latch.Write(!latch.Read());
    spi.WriteRead(wb, rb);
    Debug.Print(i.ToString() + ":" + rb[0].ToString());
    Thread.Sleep(500);
}

I placed my multimeter in this setting:
Posted Image

When I push the button the meter shows (almost) zero. the same counts for all buttons.


Ps, I'm in the chat, if you like ;)
"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 31 March 2011 - 06:49 PM

I'd check the /PL line: it should measure +5V normally, then 0V during the pulsing. Also add a Sleep(1000) between the latch writings, then a shorter Sleep just before the SPI ReadWrite. Try to check the voltage, that should move accordingly to the code.
Biggest fault of Netduino? It runs by electricity.

#14 Stefan

Stefan

    Moderator

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

Posted 31 March 2011 - 07:58 PM

Mario and I came very close during a chat session, so far I'm stuck here with the 165:

Schematic:
Posted Image

Code:
SPI spi = new SPI(new SPI.Configuration(
        Pins.GPIO_NONE,
        true,
        0,
        0,
        false,
        false,
        1000,
        SPI_Devices.SPI1
));
OutputPort latch = new OutputPort(Pins.GPIO_PIN_D10, true);

byte[] wb = new byte[1];
byte[] rb = new byte[1];
uint i = 0;
string binpresentation = "";

while (true)
{
    ++i;
    latch.Write(false);
    latch.Write(true);
    spi.WriteRead(wb, rb);
    binpresentation = "";
    for (var PinCount = 0; PinCount < 8; ++PinCount)
    {
        binpresentation = binpresentation + (((rb[0] & (1 << PinCount)) != 0) ? "1" : "0");
    }
    Debug.Print(i.ToString() + ":" + binpresentation);

    Thread.Sleep(500);
}

Problem:
Buttons 1 and 2 are sometimes malfunctioning (not due to wiring, and multimeter readings are fine);

When nothing pressed it gives 01111111 or 11111111
When button 1 pressed, same result
when button 2 pressed: 00111111
when button 3 pressed: 11011111
when button 4 pressed: 11101111
when button 5 pressed: 11110111
when button 6 pressed: 11111011
when button 7 pressed: 11111101
when button 8 pressed: 11111110

Almost there!

Now I'm going to try something with the 597, while Mario is asleep ;)
"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

#15 Stefan

Stefan

    Moderator

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

Posted 31 March 2011 - 08:26 PM

CW2 just walked into the chat and he solved it by only changing code:
SPI spi = new SPI(new SPI.Configuration(
        Pins.GPIO_PIN_D10,
        true,
        0,
        0,
        true,
        false,
        1000,
        SPI_Devices.SPI1
));

byte[] wb = new byte[1];
byte[] rb = new byte[1];
uint i = 0;
string binpresentation = "";

while (true)
{
    ++i;
    spi.WriteRead(wb, rb);
    binpresentation = "";
    for (var PinCount = 0; PinCount < 8; ++PinCount)
    {
        binpresentation = binpresentation + (((rb[0] & (1 << PinCount)) != 0) ? "1" : "0");
    }
    Debug.Print(i.ToString() + ":" + binpresentation);

    Thread.Sleep(500);
}

This seems to work! Now the code just needs some clean up, and I need a second IC to put them in serie ;)
"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

#16 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 31 March 2011 - 08:39 PM

CW2 just walked into the chat and he solved it by only changing code:

Well, I just asked Stefan to try Clock_IdleState = true in SPI.Configuration constructor - he has done the rest Posted Image

#17 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 01 April 2011 - 03:40 AM

Slept bad enough...but that's off-topic. Well, let's consider the clock as a square wave, in the middle of an idle-high level. The /PL *must* be pulsed low (although you cut off the source), to move the data from the buttons to the shifter. At this point, on Q7 you will have the 8' button state. The clock begins with a falling edge, that is the first sampling of the SPI. Then the clock will rise up: there is no sampling, but the shifter moves the frozen status of the 7' button (bit 6) to Q7. NOTE: it's important having a state machine without ambiguous states. If you were sampling and shifting the same time, you may have uncertain data. That is the early evening strange behavior. Also...the clock will fall again for 7 times again (samplings), but rises 7 times too (shifts). Yep: it is quite correct. The only point is the missing /PL on your source: it cannot be missing. Cheers
Biggest fault of Netduino? It runs by electricity.

#18 Stefan

Stefan

    Moderator

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

Posted 01 April 2011 - 06:20 AM

The only point is the missing /PL on your source: it cannot be missing.
Cheers

Hi Mario,

I noticed that it works perfectly when I chose to let the SPI take care of /PL:
SPI spi = new SPI(new SPI.Configuration( 
        Pins.GPIO_PIN_D10, //  PL
        true, 
        0, 
        0, 
        true, 
        false, 
        1000, 
        SPI_Devices.SPI1 
));
The 165 doesn't have a buffer as far as I read and this way all of my tests worked.
"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

#19 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 01 April 2011 - 06:51 AM

I apologize: I didn't notice the Pins.D10 on the SPI config. To tell the truth, I still had not understand why sometime the SPI is configured using Pins.None. Tomorrow I'll try to find time to buy the '165, but I am totally involved in the setup of the porting kit, at the moment. Cheers
Biggest fault of Netduino? It runs by electricity.

#20 Stefan

Stefan

    Moderator

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

Posted 01 April 2011 - 07:17 AM

I apologize: I didn't notice the Pins.D10 on the SPI config.
To tell the truth, I still had not understand why sometime the SPI is configured using Pins.None.

People use Pins.None when they want to run multiple SPI devices and control the SS-pin themselves by code, or in my case, to be 100% sure of the behaviour during testing ;)

I myself have a MultiSPI-class which will be available soon, which does the trick quite nice as well.

Tomorrow I'll try to find time to buy the '165, but I am totally involved in the setup of the porting kit, at the moment.

Cool! I also have two 597s to test, it's a difficult one but I want to understand that one as well :D
I'm also going to order a second 165, to put two in a serie, which should be possible.
"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




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.