EEVblog Electronics Community Forum

Electronics => Projects, Designs, and Technical Stuff => Topic started by: c4757p on September 01, 2013, 12:38:01 am

Title: Simple switch matrix
Post by: c4757p on September 01, 2013, 12:38:01 am
Just thought I'd share this with anybody who is interested. I wanted a switch matrix to do automated testing of another project I'm working on, so I threw this together. I'll add more when I get it completed. (I'm currently dealing with a bug in the firmware that I suspect to be a very smelly brainfart, and I haven't done the enclosure)

4x6 matrix of switches, including four matrix positions which allow up to 3A, controlled via USB.

Sorry about the picture quality, I couldn't find my camera so I had to use a potato.
Title: Re: Simple switch matrix
Post by: Paul Price on September 01, 2013, 02:09:00 am
Looks relay pretty.
Title: Re: Simple switch matrix
Post by: c4757p on September 01, 2013, 02:14:09 am
Groan-worthy puns? What, are you trying to be me now? That's my job! :box:

:-DD

By the way, PCB is from Elecrow. Thought I'd give them a try. Not quite as nice as ITead - the silkscreen is smudged in a couple places, the HASL isn't quite L* (this was actually enough to be a bit of an annoyance with the TSSOPs, I imagine it could be a bear with lots of fine-pitched packages and reflow soldering), and the silkscreen registration is off a bit. It just looks kind of cheap, at least up close. One of the boards actually had a solder lump hanging off one of the pads. But electrically, everything is just fine, nothing questionable in the copper and the drill registration is spot on.

*I just picked up another one and looked a bit more closely. The HASL finish is perfect on one side, and lumpy on the other. On the lumpy side, the pads rise above the solder mask, so that when you're placing a chip, it tends to fall with its pins in between the pads. There's probably enough stuck to the pads to solder many components with just a bit of flux - I'm not really convinced the hot air ever touched that side... The lumpy side is not consistent, I have about half with smooth top and half with smooth bottom.
Title: Re: Simple switch matrix
Post by: Dave on September 01, 2013, 02:49:18 am
Aaaaaaaand... you are going to have to bodge it. You need to tie one of the CBUS pins on the FT230X to ground, and configure the chip, so it doesn't go into suspend mode. Silly FTDI with their buggy chips. :D

Other than that, pretty sweet looking board. What are you going to use it for?
Title: Re: Simple switch matrix
Post by: c4757p on September 01, 2013, 02:58:50 am
|O Dammit! I knew that, too! I knew there'd be something stupid on this board, I threw it together way too quickly. (And notice the lack of mounting holes?)

Other than that, pretty sweet looking board. What are you going to use it for?

The "pressing" need was to do a long-ish-term test of the voltage reference board I just made. I want to switch my only PC-interface-capable multimeter* onto a few signals, including the reference output, internal temperature sense output, input current shunt resistor, and a separate ambient thermometer, once every 30 minutes or so for a few days. (I included many more inputs than I need so I can use it for whatever the hell else I can think of, too :-+)

*Not counting the 3468A, which you kindly sent me the interface board for! (Thanks again) But I haven't had a chance to play with the software side of that yet.


Edit: The errata note from FTDI (http://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_139_FT230X%20Errata%20Technical%20Note.pdf) says it has been fixed in silicon revision D, which is what I have. Is that true?
Title: Re: Simple switch matrix
Post by: c4757p on September 01, 2013, 03:49:12 am
Ah yes, it was indeed a smelly brainfart, I screwed up the PROGMEM accesses in an array of structs containing strings. :scared: (The "it's almost midnight and I'm chugging coffee" solution was to just move the data to RAM, since I used a mega168 instead of the mega48 I specified and have bucketfuls of RAM...)

And why can't the compiler manage this on its own? God, it has no trouble sticking const data in non-writable blocks on a PC...

Works a treat. :-+
Title: Re: Simple switch matrix
Post by: free_electron on September 01, 2013, 05:47:39 am
you using those Meder sil reed relays ? ive had bad experience with em. they tend to be sticky ...
Coto is far better.
Title: Re: Simple switch matrix
Post by: David_AVD on September 01, 2013, 07:46:55 am
Do you have a part number for that 6 pin programming header?  I've just started using Atmel devices, but only have unshrouded male headers in stock.  It would be nice to get the shrouded version so the programmer can only be plugged in the right way.
Title: Re: Simple switch matrix
Post by: notsob on September 01, 2013, 08:27:34 am
shrouded headers
http://www.ebay.com/sch/i.html?_trksid=p2050601.m570.l1313.TR12.TRC2.A0.Xshrouded+header&_nkw=shrouded+header&_sacat=0&_from=R40 (http://www.ebay.com/sch/i.html?_trksid=p2050601.m570.l1313.TR12.TRC2.A0.Xshrouded+header&_nkw=shrouded+header&_sacat=0&_from=R40)

or get name brand ones from a distributor.
Title: Re: Simple switch matrix
Post by: David_AVD on September 01, 2013, 10:14:10 am
I know what type the connectors are, but for the life of me couldn't find the 6 pin ones on Digikey or Mouser earlier.

After changing the search terms to "PCB header" I narrowed it down and found them.   Thanks for the eBay tip though.   :)
Title: Re: Simple switch matrix
Post by: c4757p on September 01, 2013, 12:19:41 pm
you using those Meder sil reed relays ? ive had bad experience with em. they tend to be sticky ...
Coto is far better.

Coto is indeed good. These are Hamlin, actually. I bought them on eBay a few months ago for about half the usual cost and figured I'd put them to good use.

David, no idea on the header, it's been loose in a drawer for at least a year now  :)
Title: Re: Simple switch matrix
Post by: baljemmett on September 01, 2013, 11:44:49 pm
By the way, PCB is from Elecrow. Thought I'd give them a try. Not quite as nice as ITead - the silkscreen is smudged in a couple places, the HASL isn't quite L* (this was actually enough to be a bit of an annoyance with the TSSOPs, I imagine it could be a bear with lots of fine-pitched packages and reflow soldering), and the silkscreen registration is off a bit. It just looks kind of cheap, at least up close. One of the boards actually had a solder lump hanging off one of the pads. But electrically, everything is just fine, nothing questionable in the copper and the drill registration is spot on.

Interesting - I had them make a couple of designs up about six months ago, and don't recall noticing anything amiss (although I have no real experience for comparisons!).  Just took a closer look at some of the spares boards and can't spot any issues; either I got lucky or you got unlucky, I guess.  I'd presumed, from the identical specs/requirements and even the 'Fusion' branded EAGLE CAM/DRC setting files, that all these cheap prototyping services used the same board house for production - or perhaps several in rotation.

(Also, I am very impressed with the output of your potato.  Mine always seem to lack fine detail; perhaps I need to parboil them before exposure?)
Title: Re: Simple switch matrix
Post by: c4757p on September 02, 2013, 12:01:42 am
Yeah, they probably use the same few board houses. Most of the ones ITead uses must not be too ghastly, I've had very good luck with them. Perhaps I'll give Elecrow another try next time and see if they come out any different.

(Also, I am very impressed with the output of your potato.  Mine always seem to lack fine detail; perhaps I need to parboil them before exposure?)


You have to hold it just right. A bit of salt helps, too.

Edit: Aaaaaaaaaargh... GCC....... it's a great compiler for PC, but the optimize-for-size mode is pretty crap for MCU. I just dropped from 3280 bytes to 3246 by adding function prototypes for the functions in main.c. I can only presume it was too stupid to "look ahead" and see them while running the optimization if I didn't mention them first.....? :wtf: And even with -Os, I can spot a few places in the disassembly where it stuffs a register multiple times without actually using the intermediate values...
Title: Re: Simple switch matrix
Post by: Mike Warren on September 02, 2013, 04:00:04 am
Edit: Aaaaaaaaaargh... GCC....... it's a great compiler for PC, but the optimize-for-size mode is pretty crap for MCU. I just dropped from 3280 bytes to 3246 by adding function prototypes for the functions in main.c. I can only presume it was too stupid to "look ahead" and see them while running the optimization if I didn't mention them first.....? :wtf: And even with -Os, I can spot a few places in the disassembly where it stuffs a register multiple times without actually using the intermediate values...

And people keep calling me an idiot for preferring to use AVR Assembler. :)

I thought that FTDI bug was fixed in the latest (D) revision?

https://www.eevblog.com/forum/projects/ft230x-what-am-i-missing/msg168068/#msg168068 (https://www.eevblog.com/forum/projects/ft230x-what-am-i-missing/msg168068/#msg168068)
Title: Re: Simple switch matrix
Post by: c4757p on September 02, 2013, 04:03:43 am
And people keep calling me an idiot for preferring to use AVR Assembler. :)

Speaking of which: I shaved another 5% or so off by compiling the code as - get this - C++.

:scared:

Next bit of firmware will be all assembly. Screw this shit.

(Yeah, I'm putting way too much nitpicking and effort into a little serial command interpreter that flips a few relays.)
Title: Re: Simple switch matrix
Post by: c4757p on September 02, 2013, 10:26:53 pm
Hey, not too much nitpicking - I'm taking the time to finish off the serial interface code and put together a well-written "standard" serial library for other AVR projects, since I'm switching to AVR. (Most of the good ones out there are GPL |O)

And look at this fart GCC let out:

Code: [Select]
ldi r31,0
adc r31,r1
clr r31
sbci r31,hi8(-(RX_BUFFER))
pop r31

This is with size optimization ON! I have not left out any r31 operations. So...... clear r31, set r31, clear r31, set r31, set r31. Where's "read r31"? What a piece of shit! Why is "check for register stores not followed by a read" not an optimization step with -Os on?? Kill me now.....

Anyway... on to replace a few chunks of code with assembly...

I take it the GCC developers haven't had to work with anything with RAM measured in KB in a long time.
Title: Re: Simple switch matrix
Post by: alm on September 02, 2013, 10:44:57 pm
Speaking of which: I shaved another 5% or so off by compiling the code as - get this - C++.
There are subtle differences between how const is defined between C and C++. The C++ definition is stricter and allows for more optimization. There may be other differences that are relevant, for example in the aliasing rules. C++ is not a strict subset of C, although most incompatibilities are fairly minor. It may also be that the C++ compiler has different default flags than the C compiler.

This is with size optimization ON! I have not left out any r31 operations. So...... clear r31, set r31, clear r31, set r31, set r31. Where's "read r31"? What a piece of shit! Why is "check for register stores not followed by a read" not an optimization step with -Os on?? Kill me now.....
My guess is that they use one of the flags set by sbci after the pop. Note that adc and sbci both set and use the carry flag, and clr sets a bunch of other flags. Although I can't see how adc would set the carry flag since r31 is 0 at that point.

Edit: if the carry set was set before the ldi, and r1 is 0xff, then adc will set the carry flag.
Title: Re: Simple switch matrix
Post by: c4757p on September 02, 2013, 10:55:31 pm
True. I forgot to mention that the only things between that and the function end were st, lds, subi, and sts, none of which use the carry flag.

Silly register use aside, the output is really not that bad; I shouldn't criticize it that much. I can save some more space by replacing a few key sections with assembly, but I have yet to find a whole function that really needs a full asm rewrite.
Title: Re: Simple switch matrix
Post by: c4757p on September 03, 2013, 08:26:18 pm
And... here it is!

There's only one thing that I don't like - there is actually somewhat substantial leakage between the column inputs (on the order of 50 meg). They run somewhat close together all the way up the PCB (I probably should have unmasked the copper, or at least strips between them). It's just enough to make autoranging DMMs with hi-Z ranges oscillate if the relays are disengaged and voltage is applied. :-\