using max7219 for seperate switching

Status
Not open for further replies.

isabella

Junior Member level 3
Joined
Mar 23, 2012
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,523
hi all,

can someone please show me a sample code for using the max7219 for seperate switching and reading input from it?
i want to use the maz7219 as a i/o expander because it can switch 64 led's seperately. (i have 150 inputs and 150 outputs :-o )
i want to switch on different pins on a plug and then test if its wired to the correct corresponding pin.

to make it simpler to understand:

let's say there is a plug with pins a,b,c and d. and there is a panel with pin a,b,c and d.
i want to turn on the pins on the plug and check its wiring to the panel.
if pin a on the plug is wired to pin a on the panel it is correct and i move on to the next pin, if pin b on the plug is wired to pin c on the panel it is incorrect and then i wil stop the testing and display an error.

can someone help?
i have never used i/o expansion before so please be clear.
 

I don't think the MAX7219 is suitable for your application. Yes, it can drive 64 outputs but they are multiplexed and the clock used to change from one output to the next is free-running. Used normally, the LEDs are arranged in a matrix so you only have one connection to each of the 8 digits and one connection to each of the 7+DP segments, that only gives you 16 available outputs and not arranged in a very user friendly way for your needs. You could use 64 opto-couplers but that would be very expensive and you would still have to synchronize your sensing circuit to the multiplexing clock.

A more economical solution might be to use a long shift register with a reset line. You first reset it so you have a known start point then provide pulses to 'walk' a single '1' along the shift register outputs. Each output goes to one pin of your plug. It's then easy to identify the other end of the wires, you use a single probe and count how many shift clocks it takes to make it go high. the number of pulses is the same as the pin number. I've used the technique on PCB testers with more than 3,000 nodes, as soon as the probe touched any connection n the board, the node number was displayed on the screen.

Brian.
 

I don't fully understand what you mean? On the real plug and panels its not a is connected to a, its pin 1 is connected to maybe pin 23 and 56, how would I determine that?
 

OK, I'll try to explain more:

Suppose you have 150 pins. You use shift registers with 150 outputs, one to each connection but you only shift a single '1' along the length of register. Like this 1<149x'0'>, then 01<148x'0'>, then 001<147x'0'> and so on until the last signal is <149x'0'>1. To start checking, you reset the shift register so all outputs are zero. You use one probe to check all the other pins. At reset, all the pins are at zero so no matter which one you connect the probe to, it will read zero. Next you clock a '1' into the shift register, the corresponding output changes to logic high level and because they are connected, so does one of the pins. If you moved the probe across all the pins, only the one connected to the first shift register output would be high so you have identified it. Next you clock the shift register again so the '1' moves to the second output. This time the probe will go high when it finds the pin connected to the second wire. You repeat this 150 times until all the pins are identified. A missing pin, or more than one pin going high would indicate a fault.

Now lets automate it with a little bit of software in whatever language you prefer. This shows the principle, it isn't actual code:

1. reset the shift register, display a blank.
2. load '1' into the shift register and clock it once. Set a variable 'wirecount' to 1
3. load '0' into the shift register but don't clock it yet.
4. check the probe. If it is '1', display the variable 'wirecount', otherwise display nothing.
5. clock the shift register so the '1' moves to the next position
6. add 1 to 'wirecount'
7. if at the end of the shift register go back to step 1 otherwise go back to step 4.

Now when you put the probe on any of the pins it will display which wire back to the shift register (your panel) it is connected to. You can remove the probe and move it to other pins, each time, the new wire number will be displayed.

Brian.
 

thanks it helps alot! now here is another thing im struggling with, i fully understand how im going to use the registers for i/o expansion, the problem is, i only understand this with the 8 bit PISO for the inputs and the 8bit SIPO for the outputs. i found a register that you can wire so that you get 64 bits. i provided the data sheet. im not sure how it works then. can you help?
i want to decrease the number of IC's. how can i do that (make provision for 150 inputs and 150 outputs)
thank you for all the help so far
 

Attachments

  • 1-64 bit register.pdf
    92.7 KB · Views: 104

You are confusing the kind of shift register you need. The MC14557 is designed to be used as a programmable delay, basically what you put in comes out a programed number of clock steps later. It achieves this by passing the input along a pre-set number of shift register stages until it reaches the output pin. The more stages you select, the longer the delay is. What you need is a shift register with an output available at each stage all the time.

I'm still not sure you need 150 inputs, and 150 outputs, there is no way you can reduce the need for 300 connections if you do that. If I understand your needs, what you want is a system that identifies the source of a signal from the far end of a connection to it. To do that, you only need one input although you can use more if you want. This reduces the number of connections to 151 which makes the circuit very much simpler. I'm visualizing a situation where a huge bundle of unmarked cables arrives at a panel and I need to find out which wire is which. Using the method I suggested earlier, all you do is touch the single probe to any one of the wires and the display instantly tells you which one it is. You can of course touch the probe to a contact or plug fitted to the end of the cable just as easily.

You can use shift registers to provide the source signal, or you could use an addressed parallel port, I'm starting to think a port might use fewer parts. With a shift register, you 'walk' a logic high across the connections in sequence, if you use an addressed port, you explicitly tell one of the wires to go high and can select any wire at any time.

What do you think?

Brian.
 

the less the components the better it will be. i am attaching a pdf file to make it more clear.
i like the idea of an addressed parallel port. my biggest concern is, i dont want to use a loose probe. is there any way that i can connect the other ends to inputs of pic.

at the moment we test the wiring of the panel with a multimeter, each pin, one by one. it takes forever . . . .i sort of want a 'just plug in and test'
 

Attachments

  • back panel 730E.pdf
    95.3 KB · Views: 149

That brings back memories... I worked on testing large wiring looms a few years back, they had 16 x 48 way plugs on them. You think you have a problem with 150 connections, I had 768 at each end and they were all hand crimped. !!!

The actual testing process is very easy, the difficulty comes from selecting the individual connects in a way that doesn't use masses of hardware. Commercial systems use large banks of drivers and sensors, often with banks of relays to route the signals but they are very expensive and tend not to be very reliable. I don't think you will find there is a very simple solution to your problem. However, "necessity is the mother of invention" so I've put my inventors hat on and started thinking. These are my first ponderings:

1. there are three possible failure modes: a connection is open circuit, two or more connections are shorted together or a connection is routed to the wrong pin (so presumably another is as well).
2. if a matrix was used, it would have to be at least 12 x 13 (156 with 25 drive lines) to cater for 150 individual selections. If standard 8-bit devices were used it would have to be 8 x 19 (152 with 27 drive lines).
3. it might be feasible to use different voltages on the connections and check them with an ADC. This uses fewer connections but can also be less precise and would be slightly slower.
4. depending on how many of these you have to test, it might be more economical to use a 'Human' to do the checking and only automate the connection selection.

Let me know what you think of my thoughts. I can see a very economical way of doing it but it would still require some intervention although nowhere near as much as using a multimeter.

Where in the World are you? If it's for the company in the PDF, I friends in one of the factories.

Brian.
 

i had the same thoughts,but i really want to exclude the 'human factor', i think the voltage difference idea will also work. is it alot slower? also another thing to remember, some of those pins are connected at 2 or 3 points. im in south africa, we have alot of those machines here.
thanks brian
 

The factories I'm thinking of are in Europe.

Having multiple connections makes things far more complicated and may make the voltage measuring method inappropriate. What I had thought was that you could use resistor networks at one end of the cable and apply a fixed voltage to them. From the other end you measure the voltage across a load to see if the correct source resistor was on that wire. You couldn't reasonably use 150 different voltage levels because measuring such small differences would be prone to error but you cold split the wires into groups of say 20 to make the problem easier to manage. You still need to select 150 measurement points but far fewer at the driving end.

The cheap idea I had may still be feasible. Although it still requires 'Human factor' the testing would be so fast that it may be the most economical method, especially if someone has to be there to handle the cable anyway. My idea was to forget using ICs altogether and make a far cruder machine. What I considered was a 12 x 13 array of LEDs, each with a current limiting resistor, connected one side to the plug and the other side to a common ground. Applying a voltage to a pin at the other end would make one (or more for joined connections) LED light up. The cost would be very small, I'm not sure of SA exchange rates but if I use $US as a base currency, I would guess around $20. At the other end of the cable, you have a voltage source and 25 push switches. Each switch connects the voltage to either 12 or 13 diodes, each of which goes to the connections matching one row and one column of the LED matrix at the other end. So pressing one switch would make all the LEDs in one row light simultaneously. The diodes are wired so the next switch lights all the LEDs in the next row and so on. After all the rows are wired, you wire the next switches to the diodes feeding each column so one switch lights all the LEDs in one column and so on. Cost at the switch end would be for 156 signal diodes and 25 switches, around $50.

To test the cable, all the operator has to do is press each of the 25 switches in sequence and watch the LEDs. They should show a distinctive pattern or one row at a time then one column at a time. Total test time would be maybe one minute. A broken connection would cause an LED to remain off, a short or wrong connection would visibly break the pattern. You could automate the 25 switches electronically if you wanted to. By labeling the LEDs you could identify which connection was at fault.

I can't think of a cheaper way.

Brian.
 

the cost won't be an issue. i think im going to try it with the shift registers, but i'm going to use the shift registers on the input side aswell. im going to try and design the pcb first to see if it's going to work. can you help for a sample code in c, to illustrate how it will work on the input side and output side respectively?
thanks for your help brian.
 

I would suggest you look at the data sheets for the 74LS164 and 74LS165 (or their CMOS equivalents) if you want to use the shift register method. These are serial-in, parallel out and parallel-in, serial out devices respectively. Each is only 8 bits wide so you will have to daisy chain 19 of each to make 150 bits. It will be a complicated PCB!

I can help with PIC microcontroller code, in assembly or in 'C' but I'm afraid I have no experience or tools for programming in Windows if that's what you need. I can explain the principles to you but I can't produce Windows executable code.

Brian.
 

i meant the microcontroller code 'c'.
thanks brian, i already started on the pcb, it looks quite nice!
 

Show me a schematic when you have one (preferably as PDF or in Kicad format) and I'll see what I can cook up to drive it!

Brian.
 

Hi Brian,
i attached a rough sketch, i will put in the resistors and GND's etc. in later.
i also attached a table of pin connections of the first 10 plug pins.

when one of the connections is wrong, it should display the correct connection on the lcd. ( ex. error: Pin1 not connected to Pin20)
there is a possibility that a pin can be correctly wired to its corresponding pin, but also shorted to the pins next to it, so maybe testing the pins next to it will help with that.

thanks for the help
 

Attachments

  • PIN CONNECTIONS.pdf
    21.6 KB · Views: 136
  • back panel.pdf
    11.9 KB · Views: 105

the attachments
 

Attachments

  • PIN CONNECTIONS.pdf
    21.6 KB · Views: 136
  • back panel.pdf
    11.9 KB · Views: 115

Sorry for not replying yesterday - I've got my head buried in some complicated software which is consuming much of my time.

The schematic looks fine in principle, all it needs is software to drive it. I have some reservations over the amount of memory it might take but there is always the option to switch to a 16F648A if it runs out.
I have to ask, is this a commercial project? For my angle it makes no difference but I'm concerned that company confidential information might leak if it's posted here.

Which 'C' compiler do you have?

Brian.
 

hi brian,
this is a project I though of doing, no one knows yet(I first want to get it right...haha) anyway I posted no critically confidential info.
I have C18, I could always use a p18f452.
thanks for taking the time to help!
 

The 18F1320 is closer to the 16F628 and a more recent device too.
Can you confirm the C18 compiler can produce code for PIC16 devices, I thought it was only for the PIC18 series.
The compiler I use (WIZ-C Pro) produces code for 12F, 16F and 18F but for some reason it isn't popular. I can't see why, it does everything the others do at a fraction of the price and has one of the best debuggers I ever used. If I use it to produce code for you, it should be very easy to convert the source code to other compilers as it is ANSI compliant.

I'm still working on another project at the moment but it's close to completion. I'll see what I can do to give you some code to start playing with as soon as it's finished.

Brian.
 

I actually want to use a larger pic with 4 ports, seeing as I'm going to need some inputs for other features. Thank you, good luck with you project, I'll wait for your reply. P.s I'll see what I can do to get the WIZ C . I'll let you know
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…