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

Multiplex shield, experiences?


  • Please log in to reply
30 replies to this topic

#1 Stefan

Stefan

    Moderator

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

Posted 10 March 2011 - 10:52 AM

Hi all,

Since I want to do a bit more in the line of robotics, I am thinking about the amount of I/O-ports.
It will probably be possible to do with only the current amount, but if there were more ports, things would be much easier.

I found out that a Mux Shield could be useful then. But all I find is code for the Arduino, which isn't in C#. Has anyone already got some experience with multiplex shields on a Netduino? Is it easy to adapt code to use a multiplex shield?
"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 10 March 2011 - 11:35 AM

That's me again. I'd suggest the much simpler shift registers, you may control them via SPI interface. E.g. 74HC595 and 74HC597. The problem could arise if you are not so familiar with hardware. Mario
Biggest fault of Netduino? It runs by electricity.

#3 Stefan

Stefan

    Moderator

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

Posted 14 March 2011 - 09:59 AM

I've ordered a 74HC595 (already have one but have it in use for my LCD and they're not so expensive). Going to toy a bit with it when it arrives. Doesn't seem too hard as it's an SPI device indeed.
"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 14 March 2011 - 11:19 AM

The HC595 is very cheap: I have found at 1€/each. I guess you should buy at least 2-3 for type: one is too few. Beware that it gives you only outputs. I must buy the 597 also, because I need additional input too. Mario
Biggest fault of Netduino? It runs by electricity.

#5 Stefan

Stefan

    Moderator

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

Posted 14 March 2011 - 11:28 AM

Outputports are enough for me for now, it's just for learning experiences. No practical use yet. I'm considering a class which has an Enum for the 8 outputports of the 74HC595 and a OutputPort-like-class to handle them, so it won't be difficult to implement it. Good point that 1 isn't enough, but to understand the stuff a bit, one should do for now. Indeed, it costed me €1,00 :)
"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 14 March 2011 - 12:41 PM

I see. Instead, I'm involved in the measurement of the timing offered by the N+. The managed platform is far from being a real-time environment, but I'd like to measure how much it delays some basic operations. That's not so easy as it seems. I have tried to instantiate a timer that gives a tick every millisecond, but the error is huge: some basic ops already get over a ms! So, I wish to connect an external counter, clocked by a crystal, and then read by a shift register (for simplicity). Consider that I haven't any serious instrumentation. I guess we should be know as deep as possible what this device can do, otherwise you may only build games or something like that. Mario
Biggest fault of Netduino? It runs by electricity.

#7 Stefan

Stefan

    Moderator

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

Posted 14 March 2011 - 12:55 PM

For me games is just as training into the C# language, since before the Netduino I actually never programmed in C#. For my final project I don't know if I need a precice clock, although it could be useful for servo motors I suppose. Ah well, step by step we learn, first I have to find out how to use the 74HC59x's ;)
"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 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 14 March 2011 - 01:16 PM

Hmmm...it depends on viewpoints, I think. I don't know if it is a good way learning C# on a Netduino. I use regularly C# on PC, where everything is simple(*). I have decided to buy a N+ for fun, for curiosity and because I missed very much my original passion, which is the electronic. I have always liked electronic circuits and I have studied for it. The N MCU is a kind of nuke, it seems almost impossible that a port read/write takes hundreds of microseconds. I think should take hundreds of nanoseconds! That is the dark side of the game...that because I'd like to optimize wherever is possible. If you will use servos, either you buy "intelligent" servos, or you should implement your own driver. As for me the second choice is much more funny and exciting, but I think would be hard to do with a so slow platform. Anyway it depends on what you expect. Cheers (*) everything is simple, it works well and fast, until you haven't problems...as usual. :rolleyes: :rolleyes:
Biggest fault of Netduino? It runs by electricity.

#9 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 14 March 2011 - 02:27 PM

The N MCU is a kind of nuke, it seems almost impossible that a port read/write takes hundreds of microseconds. I think should take hundreds of nanoseconds!

This is slightly off-topic, but I just would like to point out that the port access itself is very fast (see GPIO speed (MHz), BitBasher threads), it is the CIL interpreter that takes hundreds (or maybe thousands) of instructions to execute the IL opcodes. Unlike its 'bigger brothers', .NET Micro Framework does not have neither Just-In-Time compiler(*) nor native image generator that can translate IL into assembly (native code) - there is a lot happening between port.Write(...) and PIO_CODR/PIO_SODR register access ;-)

(*) Actually, the JIT is there, but it is not enabled, mainly due to flash memory-related issues (size constraints, repetitious reflashing etc.).

#10 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 14 March 2011 - 02:45 PM

Dear CW2 (I don't remember your name), you are right: I was going off-topic for a little. The port R/W was just an example: in the fact there are many apps you must cut off because the "device" is too slow. I am *not* criticizing N or the MF, because I really love C# and I think N is a step beyond. My "sadness" (let's say so) would be just because it's pretty hard to realize even little apps, but where the millisec has to be granted. I know about Fluent for example (excellent work), but I think is such a way to "override" the managed language. At this point would be better to use C++... Anyway, let's get back to Stefan: he's going to motorize his N app. What about shaping the speed/position of ONE-single motor?...Either he has a very slow speed, or he must use an external logic. I really can't see other ways. If you want we may move this discussion on another thread or privately: no problem. Cheers Mario
Biggest fault of Netduino? It runs by electricity.

#11 Stefan

Stefan

    Moderator

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

Posted 14 March 2011 - 02:53 PM

I don't mind at all :) I read somewhere that by sending delayed pulses to an outputport of a servo motor it can be driven, didn't sound too hard to me. But I must say, I haven't got any experience with it and I orderred 5 servos but because I'm cheap I have to wait a month for them to arrive (by boat from Hongkong for less then €2,- each including shipping costs) But first I want to experiment a bit with SPI and the 74HC59x's, or at least some form of multiplexing to increase my GPIO-ports. Performance hasn't been an issue to me yet on the Netduino, but when it is, I'll ask for advise on these boards I guess ;)
"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

#12 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 14 March 2011 - 03:20 PM

Anyway, let's get back to Stefan: he's going to motorize his N app. What about shaping the speed/position of ONE-single motor?...Either he has a very slow speed, or he must use an external logic.
I really can't see other ways.

You can use PWM to control motors. For servos, there are several samples in the forum, please have a look at e.g. Chris Seto's Netduino servo class. Similarly, DC motors can be operated by H-Bridge circuits that usually take PWM input to control the speed (there is currently one issue with fixed PWM frequency at 10 kHz that may causes motors to 'hum', because it is in audible range - this will be fixed in the next firmware versions). Hope this helps.

#13 Stefan

Stefan

    Moderator

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

Posted 14 March 2011 - 03:22 PM

You can use PWM to control motors. For servos, there are several samples in the forum, please have a look at e.g. Chris Seto's Netduino servo class. Similarly, DC motors can be operated by H-Bridge circuits that usually take PWM input to control the speed (there is currently one issue with fixed PWM frequency at 10 kHz that may causes motors to 'hum', because it is in audible range - this will be fixed in the next firmware versions). Hope this helps.

Thanks CW2, I will look into it as soon as the servos arrive. As I explained, since I'm a cheap guy I have to patient though, so until then I will work on several projects for educational purposes.
"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

#14 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 14 March 2011 - 07:01 PM

...first I have to find out how to use the 74HC59x's

Curiously, Hack a Day just published an article that links to Interactive 595 Shift Register Simulator Posted Image

#15 Stefan

Stefan

    Moderator

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

Posted 14 March 2011 - 08:25 PM

Well, I got 8 leds driven over 5 wires with a 74HC595.
Yes there is a resistor on the breadboard, and I had only one led burning at all time :)
Posted Image

Code:

SPI SPI_Out = new SPI(new SPI.Configuration(
                Pins.GPIO_PIN_D10,
                false,
                0,
                0,
                false,
                false,
                1000,
                SPI.SPI_module.SPI1
            ));

            byte[] writebuffer = new byte[1];
            while (true)
            {
                writebuffer[0] = 0; SPI_Out.Write(writebuffer); Thread.Sleep(100);
                writebuffer[0] = 1; SPI_Out.Write(writebuffer); Thread.Sleep(100);
                writebuffer[0] = 2; SPI_Out.Write(writebuffer); Thread.Sleep(100);
                writebuffer[0] = 4; SPI_Out.Write(writebuffer); Thread.Sleep(100);
                writebuffer[0] = 8; SPI_Out.Write(writebuffer); Thread.Sleep(100);
                writebuffer[0] = 16; SPI_Out.Write(writebuffer); Thread.Sleep(100);
                writebuffer[0] = 32; SPI_Out.Write(writebuffer); Thread.Sleep(100);
                writebuffer[0] = 64; SPI_Out.Write(writebuffer); Thread.Sleep(100);
                writebuffer[0] = 128; SPI_Out.Write(writebuffer); Thread.Sleep(100);
            }

"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 Stefan

Stefan

    Moderator

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

Posted 16 March 2011 - 08:26 AM

I made some progress. I made a 74HC595 class and an OutputPort-class so it works almost exactly as regular outputports.

The blinking led example would be translated like this:
// Initializes the 74HC595 IC
Ic74HC595 IcOut = new Ic74HC595(Pins.GPIO_PIN_D10, SPI.SPI_module.SPI1);

// Defines the outputport, mind the last parameter, referring to the 74HC595 IC
OutputPort595 led = new OutputPort595(Ic74HC595.Pins.GPO_PIN_D0, false, IcOut);

while (true)
{
    led.Write(!led.Read());
    Thread.Sleep(500);
}

I think the 597 will be harder, since I also want to support interrupts, but that's a challenge for the upcoming week. Today I'll get 2 597s and an additional 595 to toy with :)
"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

#17 Stefan

Stefan

    Moderator

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

Posted 16 March 2011 - 11:57 AM

Darn :( Just came back from the local electronics shop but the 597 she orderred was arrived as SMD IC, so I have to play with the 595s a bit further.
"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

#18 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 16 March 2011 - 12:44 PM

I think the 597 will be harder, since I also want to support interrupts


Hi Stefan. I wouldn't be sure that managing the 597 inputs as they were really independent would be a good bet. Formally it is surely a good move, but consider how bad performing would be.
Instead, for example, I'd link two 597 in pipeline so that, with a very fast operation, the Netduino will get 16 bits at once.
Throwing many int's will stuck the application, I guess.

Unfortunately I'm realizing that all the sweet things learned for programming abstraction would be taken as we were diabetics (correct in english?)

Good luck.
Mario
Biggest fault of Netduino? It runs by electricity.

#19 Stefan

Stefan

    Moderator

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

Posted 16 March 2011 - 12:49 PM

Interesting. Too bad I don't have one yet, otherwise I could try some stuff :) Tonight CET, I will post the classes for the 74HC595 IC in hope for criticism to improve the driver :D
"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

#20 Stefan

Stefan

    Moderator

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

Posted 16 March 2011 - 01:17 PM

By the way, can't I use a 74HC165 instead of a 74HC597? Isn't it actually almost the same?
"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.