Continue to Site

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.

  • 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.

Simple logic switch with pushbutton?

Status
Not open for further replies.

dalmation

Member
Hello,
I need a simple circuit (as simple and cheap as possible).

I have a 3.3V supply, a momentary ON push button (tactile switch) and two logic outputs.

I want the circuit to do the following...

I need the outputs to toggle between 10, 01, 00 (in that order) at each push of the button. I would also need 3 led indicators to show position 1, 2 and 3 so I know where I'm at.

I thought of using a binary counter and a non inverting buffer (to drive leds), but I have very limited room on the PCB.

Ideally if I could do it with a few transistors I could fit it all in using surface mount components.

The circuit is to enable me to remove a DPDT toggle switch which is physically too big to suit my circuit.

Any ideas? Thanks in advance.

-DAlmation.

EDIT: Whats the cheapest, nastiest PIC microcontroller that could do this?
 
Last edited:
An 8 pin one like the 12F675 would do it easily, one input, two logic outputs, and three LED outputs. You could also use a 6 pin 10F series, and use diodes to feed the LED's from the logic outputs.

Probably a SM 8 pin one would be more than small enough, and avoid the diode gating.
 
oops- just noticed- I actually need it to go in the following order:

00 - 01 - 10

So a binary counter could be a cheaper option, right?

The only problem is the leds... could a binary counter power a small led without a line driver?

I could have no led on for position 1, then stick an led on the 2 outputs for position 3 & 4.

I can get binary counters for anout 10% cost of the pic chip.

what you think?

-Dal.
 
I think this may be what you want:- https://www.electro-tech-online.com/threads/counter-circuit-used-to-switch-an-encoder-chip.32328/

IC5a and IC5b in the circuit I posted in this thread (see my second last post) is configured as a Modulo 3 counter. It cycles through 00, 01, 10. You may want to include a power on reset as it may start in the 11 state when the power is turned on. You also need a bounce suppressor to prevent spurious counting.

If you use a 74HC flip flop, it will drive the LEDs.
 
Sorry- how do you do it with flip-flops? Sounds like a good idea but I cant picture it?


I designed a circuit last night that used a binary counter (1st 2 stages).
The 2 binary outputs were connected via an AND gate to to the reset pin (so 11 would trigger reset). I can get a Single AND gate IC so its nice and small and very cheap.

I also wired the outputs to transistor switches to drive the LEDS
00= No leds
10= LED1 on, LED2 off
01= LED1 off, LED2 on

Still interested in the flip-flop option before going further.

Thanks again.

-Dalmation.
 
Okay guys- built a prototype today and ran in to some problems.

I went with the binary counter method. The counters fine, but it still doesnt work...

It isnt pulling enough current when in state 0 and it isnt supplying enough current when in state 1.

I shorted the leads manually to Vcc and ground whilst measuring the current.

The circuit needs to sink 25mA to ground (in state 0) and needs to supply 50mA (in state 1). To be on the safe side- I'll assume 50mA sink and supply.

I attached a line driver (74HC541)- no help. I upped the supply and tried the 74LS541, it could JUST sink enough current, but couldnt supply enough.

Is there a way of arranging a couple of transistors so they will SINK :gtoet: 50mA current when given an Input=0 and supply :gtoet: 50mA current when given input=1 ?

I'd really appreciate the help on this one.

Thanks again.

-DAlmation.
 
Quote:- Sorry- how do you do it with flip-flops? Sounds like a good idea but I cant picture it?
Did you look at the link that I posted for you?

All you need is one IC, a JK Flip Flop configured as a Modulo 3 counter.

If you want to source or sink > 25 mA then you will need transistor buffers for the LEDs since the 74HC series can onlt source or sink a maximum of 25 mA.

I thought that you only wanted to drive LEDs. So why do you need so much current? Normally about 10 mA is enough. And why do you need to both source and sink current?

Post a circuit of what you have built so we can help more. Otherwise we are working in the dark.
 
The output lines are for manipulating some binary address lines in an existing circuit to change the readout on a display (see my other thread - Binary to Hex converters).

I use it to call up 3 memory locations which contain configuration settings for hardware. Most of the address lines remain unchanged (so I just hard wire them to Vcc or ground), but two need manipulated to get the 3 addresses I need to access. (00, 01 and 10).

The lines are unfortunately a bit current hungry. (I cannot change the main circuit- only my 'manipulator' circuit can be changed.

I currently switch between the states with a DPDT toggle switch and a tactile switch and 2 diodes, but this is physically too bulky and a bit costly.

The lines do not register as 0 unless decent current can flow to ground and do not register as 1 unless decent current flows to it from Vcc. Othewise they float and oscillate the display.

That is why I need it to both sink and supply the high current.

I have the counter working fine, but I need to arrange some transistors so they sink on input=0 and supply when input=1

I'll post a pic of the counter circuit, but its the transistors I am stuck on.

-Thanks again.

-DAlmation.

EDIT- Heres a quick picture of the binary counter circuit (CD4040 binary counter, counts 00, 01, 10 -then repeats)
Binary counter.PNG
 
Last edited:
What the heck is this contraption you're hacking into? You may be at the point where it'd be simpler to redesign the whole thing the right way from scratch (grin)...
 
Last edited:
Lol, I suppose you could call it hacking- never thought of it like that.

Its for reading the equipment serial number and some basic config data on some motherboards with 80 pin simm modules.

Its a just a time saver but its became a bit of a pet project- really enjoying myself.

The setup works brilliantly already- I just want to replace the big bulky switch with a solid state equivalant.

Any ideas on the transistor pull up / sink circuit- its starting to hurt my brain:D

-DAl.
 
:D You are indeed a guru of all things electronic.

Cant thank you enough- I'll need to annoy the missus by dissapearing into my workshop for yet another night.

Thanks again.

-DAlmation
 
A tiny 6-pin PIC solution could include switch debouncing and switch press 'beep' audible feedback.
dals-switch-png.14879

Then again, if this circuitry is all going on a single board with the displays then you (we) could have probably come up with a better low parts count solution.
 

Attachments

  • Dal's Switch.PNG
    Dal's Switch.PNG
    17 KB · Views: 518
The pic 10f200/206 com in SOT23 package and are the same size as just the single AND gate in my counter design- so it woul take up less space.
Thats a cute little chip!

The speaker output could be made the 3rd led (for logic state 00).
The resistors could be cut down to just one resistor (cos theres only ever gonna be 1 LED on at a time :)

If you look at my PCB (left side), if you remove the Toggle switch and 2 diodes and move the tactile switch to the side- theres plenty of space to fit that all in.

An adaptor to attach the SOT23 to my programmer is only about $20 and the Pic itself is only about $0.50 (my toggle switch is about $2-4 depending on quantity)

Sounds good! - I need to try the push/pull circuit to make sure I can replace the toggle switch reliably.

I cant wait to try it- if it works with th ebinary counter- I'm sure I'll revisit this pic solution.

I solute your wisdom.

-Dal.
 
Okay- spent a few hours on it tonight.

The circuit works- but not for my application.

The best I can get out the final output is

Logic 0= 0.3 to 0.5 Volts
Logic 1= 2.6 to 2.7Volts

To get the proper 3 to 3.3V output, I would need to increase the supply voltage (cant do that).

I dont understand why the 0.5 volts is a problem- but it definitely is! It just seems to register as a floating logic line (display just flickers gibberish).

Unless there is a way to top up the voltage and chop it down to 0.0V, It isnt gonna work. If there isnt a way of doing this- I'll just need to stick with the mechanical switch.


I'd be REALLY interested if anyone can offer some insight as to why its behaving like this as it affects some other earlier projects (which failed).

I was trying to read/erase and reprogram an eeprom in circuit. I had access to all pins (via a memory expansion socket)- but most of the data was corrupt because of 'blurring' of 1's and 0's (same as my current problem), no matter which line driver/buffer I used. It just wouldnt go to a proper logic0.

-Anyways- thanks for all the help- I really appreciate it.

-DAlmation.
 
Almost sounds like you've got some other logic somewhere driving those lines and you're fighting those devices when you try to drive the lines.
 
Yeah- its a pity I couldnt get it to work- but I learned a lot messing around with it.

Back to the mechanical switch. On the bright side- thats the design complete- so I can send it off to the pcb fabricators today :)

Thanks again...

-DAlmation.
 
dalmation said:
Okay- spent a few hours on it tonight.

The circuit works- but not for my application.

The best I can get out the final output is

Logic 0= 0.3 to 0.5 Volts
Logic 1= 2.6 to 2.7Volts
This is because of the base - emitter voltage drops.
To get the proper 3 to 3.3V output, I would need to increase the supply voltage (cant do that).

I dont understand why the 0.5 volts is a problem- but it definitely is! It just seems to register as a floating logic line (display just flickers gibberish).

Unless there is a way to top up the voltage and chop it down to 0.0V, It isnt gonna work. If there isnt a way of doing this- I'll just need to stick with the mechanical switch.


I'd be REALLY interested if anyone can offer some insight as to why its behaving like this as it affects some other earlier projects (which failed).

I was trying to read/erase and reprogram an eeprom in circuit. I had access to all pins (via a memory expansion socket)- but most of the data was corrupt because of 'blurring' of 1's and 0's (same as my current problem), no matter which line driver/buffer I used. It just wouldnt go to a proper logic0.

-Anyways- thanks for all the help- I really appreciate it.

-DAlmation.
You need a configuration that does not include the B - E voltage drops.

I suggest :-
connect the emitter of the PNP to +3.3 V and the emitter of the NPN to gnd.

Now connect a resistor from the base of the PNP to the logic output and a resistor from the base of the NPN to the same point. Connect the 2 collectors together. In this configuration, the only voltage drop will be the saturation voltage which ought to be about 0.2 V is you have enough base current. Note that the circuit will act as an inverter. So you'll have to account for this somewhere.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top