• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How would I count the number of switches currently active?

Status
Not open for further replies.

nfsbuff

New Member
Hi all, first time posting here, so let's see what happens.

My problem is this:
I am designing a control panel with 7 toggle switches that control-via relays-the availability of power to 7 outlets. On the panel there is to be 2 7-segment displays. One will show how many devices are plugged into the 7 outlets, and the other how many are currently drawing power. What logic would I implement to do the count in this scenario?

My first idea would be to use a pulsing IC to poll the outlets. My second idea would be to measure resistance per outlet and return how many are above and below a certain threshold. But, both these ideas rely on returning a count that I can feed into a 4511. Any ideas?
 

Diver300

Well-Known Member
Most Helpful Member
You have to be careful mixing mains and low voltage. If you get any mains on the low voltage stuff things will go bang.

You can detect that the power to the outlets with double pole switches with one pole to turn the outlet on and off and one to run the logic.

Alternatives are relays or small transformers in parallel with the outlets.

The more difficult thing is to measure the current taken by the outlets. How much power will the loads be taking? You can't measure the resistance per outlet if it they are powered.

Converting 7 separate logic levels to BCD with logic involves a lot of ICs. I suggest you use a microcontroller, or use an analog adder. (Analog Addition)
 

nfsbuff

New Member
Thanks for the reply Diver300. There is no direct connection between the main power and the logic. All the IC's etc are run by a 12V DC power supply. My goal is not to measure the current being drawn by each outlet, but rather if the outlet is drawing power; this action is taken via a relay. My goal with the BCD logic and whatever else I may need is to show a count of how many of the outlets have currently been switched on.
 
Last edited:

Diver300

Well-Known Member
Most Helpful Member
The problem is that adding up is a fairly complicated function, and as everyone uses microcontrollers, the manufacturers have stopped making dedicated adders.

This is a priority encode, which does what you want if the switches are turned on in the right order, but even that is discontinued.

http://www.electro-tech-online.com/custompdfs/2009/06/hef4532b.pdf

If you want to do it with combination logic, the best thing to do is to make two full adders, to count up two groups of 3. Then two more full adders will add up the results of the first two, along with the last input as the carry in.

Adder (electronics) - Wikipedia, the free encyclopedia)

You need about 8 exclusive-or gates, 8 AND gates and 4 OR gates, I think
 

Mr RB

Well-Known Member
Connect each relay output by a resistor to a common voltage divider. Then the voltage on point X will be eaxactly proportional to the number of relays activated.

Then use a LM394 (I think) bargraph driver IC to drive a single led output but instead of led you have diodes to light a numeral ont he 7-seg display.

So for each digit you have 8 resistors, LM394, and 40ish diodes.

That's the lowest chip count I can do, although "40ish" diodes is a little ugly. I guess compared to the 7 relays you already have...
 

nfsbuff

New Member
Hmm, that's an interesting solution Mr. RB. I'll give it some thought.

What I'm starting to find out is that, in general, displaying a simple count of "on" switches is not simple at all. I'm starting to lean towards a truth table stored in an EEPROM. Doing so would eliminate the need for a counter and/or adder.
 

Mr RB

Well-Known Member
Well sometimes the simplicity is staring you in the eye. ;)

You have 2 seven segment displays, and you need to count 2 lots of 7 items...

....

Just attach each item to it's own segment, then look at the displays and you can "see" how many are on. Almost zero parts cost. With the added bonus of seeing WHICH ones are on. And the double added bonus of your friends exclaiming "What the heck is that????" :eek:

(edit) The eprom idea is beautiful! Apart from the need to program one which could be a pain.
 
Last edited:

Diver300

Well-Known Member
Most Helpful Member
If you can find an eeprom with parallel inputs and outputs.

Do they exist any more?

A note of caution if you are going to use a potential divider from the relay outputs, you have to make sure that the impedance is constant. To do that, you need to connect each resistor to ground when the relay is de-energised.
 

nfsbuff

New Member
Hahaha, Mr RB, plus two points to you sir for a awesome idea. :p Still, while being simple it wouldn't fit the end result I need.

Diver300, two different parallel EEPROM's I (was) looking at were these:
256KB from Digi-Key

64KB from Jameco

However, I just recently got in touch with a friend who has an ATMEL microprocessor programmer. If I can get that to work, I can skip the EEPROM all together and have the truth table on the micro. This is all a rush of new stuff for me, so we'll see where this all goes.
 

MikeMl

Well-Known Member
Most Helpful Member
...
A note of caution if you are going to use a potential divider from the relay outputs, you have to make sure that the impedance is constant. To do that, you need to connect each resistor to ground when the relay is de-energised.
Just sum the resistor currents into a "virtual ground" at the input of an opamp configured as a summing amplifier. That way, the voltage steps at the output of the opamp are precisely determined by the values of the seven resistors. If you want equal steps, make the resistors equal. If you want non-equal steps, weight the resistors as required. You could even make binary steps if you use the resistors and switches to implement a R-2R ladder.
 

tcmtech

Banned
Most Helpful Member
What happened to common sense? Use illuminated switches! If you cant count to 7 or understand that if ones lit up its probably on you shouldn't be working with electricity period! :eek:;)

If you want to know which device is drawing power I bet its the one thats attached to the outlet thats connected to a rocker switch thats illuminated! :D

This sounds like another pointlessly over complicated class assignment project. :eek:
 

nfsbuff

New Member
Or, tcmtech, sarcasm aside, its an exploratory project--not done because I have to but because I want to. Can I count to seven? Yes. Am I still going to try and accomplish this? Yup. This is no class project, and my goal is not industry grade efficiency. Why put a puzzle together if you already know what the picture is? Because its a challenge and in meeting it, however "pointlessly over complicated" it is, there's fun to be had in the problem solving process.

So, rather than blast into a thread and steamroll it with useless quips about the pointlessness of it all, say something useful.
 

shimniok

Member
If it weren't for pointlessly overcomplicated, what would engineers do with all the spare time?? :D

I personally think it'd be quite a bit easier to program certain inexpensive MCUs than an EPROM -- e.g. Arduino or Pololu Orangutan or something BASIC-based... Otherwise... you can implement in all discrete gates but... that is a lot of gates. :)

Another option... I see that PDIP arithmetic chips are out there so you could explore that. I have never used one so... *shrug* E.g. Texas Instruments SN74F283N at Mouser for $0.72 :D

sn74f283_diag.jpg

Basically it adds a pair of 4-bit binary inputs and spits out a binary result with carry.

How you'd use this... ? Couple thoughts. Either one of these chips for each pair (1,2 and 3,4 and 5,6) then take another chip to add the outputs of the first two pairs, and another chip to add the third pair and switch 7. Then a final chip to add the results of these two chips.

Or you could try using discrete gates to add up at least the initial pairs (1,2 ; 3,4 ; 5,6) and the adder chip to go from there. It'd increase chip count but you could say you made your own adder. :) Here's a page on the logic/gates involved.

PHY107 Addition using Logic Gates

So use a half adder for each pair. So now you have 3 pair, 3 half adders. Take the 3 half adders plus switch 7 and feed into 2 adder chips (ie, 1,2+3,4 and 5,6 + 7) and feed the results of that into a final adder.

Since you're < decimal 10 (binary 111, hex 0x0A) you can use a BCD (binary coded decimal) to 7-segment driver to drive your LED. Should be able to scare up one of those on mouser easily too.

IIWY I'd design this in Eagle or at least carefully on paper so you can fully utilize all the gates in your quad-ands, quad-xors, etc. And wire them up properly. That is a heck of a lot of chips and pins to get right.

Michael
 

nfsbuff

New Member
shimniok, thanks! There are some great ideas in there. I've been exploring the adder idea, and came to the same conclusion that going the MCU route will probably work best. I was able to get a hold of a programming board for Atmel MCU's, so now we get to work and see what happens :D
 

shimniok

Member
PS: you could also add up 3 at a time but at that point you'd need a half adder and full adder together. Without spending too much time thinking about this I still like the idea of using HA's for each pair.

So you're talking one AND and one XOR for each half adder (x3) That means one Quad AND (7408) and a Quad XOR (7486) covers all the half adders. Btw each HA feeds the output into A0/B0 and the carry into A1/B1. So you need 3 adders. 5 chips. Not too awful bad I guess. You could go with an 8th switch, and not add any chips; you'd just need to implement another HA.

Michael
 

BrownOut

Banned
I still like the original idea of polling. Alternatively, you can 'capture' the outputs of the relays in a linear shift register, and then use a simple binary counter to determine the number of 'set' bits in the shift register. I'm curious about why this informaiton is important? I'm working on a similar project, but I'm more concerned with exactly what appliances are running rather than just the number. Also, by what method do you actuate the relays? Are you using a current sensor?
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top