Momentary switch toggle circuit

GroupDIY Audio Forum

Help Support GroupDIY Audio Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
don't understand!

it's a SET and RESET ic.
I have a Mute button, a Solo button and a solo dc bus.
The Mute button normaly toggles the Mute relay.
The Solo button applies dc to the solo bus and overrides overrides the Mute relay (if set) on the solo'd channel
The Solo dc bus operates the Mute relay on all channels that do not have the Solo button pressed

It sounds weird when you write it out in words but the logic is quite straightforward. You can do it with a couple of mechanical toggle switches and a couple of diodes

You can do it with momentary push buttons and a couple of 14pin DIPs

Or you can do it with an 8 pin MCU

Cheers

Ian
 
I have a Mute button, a Solo button and a solo dc bus.
The Mute button normaly toggles the Mute relay.
The Solo button applies dc to the solo bus and overrides overrides the Mute relay (if set) on the solo'd channel
The Solo dc bus operates the Mute relay on all channels that do not have the Solo button pressed

It sounds weird when you write it out in words but the logic is quite straightforward. You can do it with a couple of mechanical toggle switches and a couple of diodes

You can do it with momentary push buttons and a couple of 14pin DIPs

Or you can do it with an 8 pin MCU

Cheers

Ian
You could configure your own "IC" and have the logic you want on a PCB the size of a dip 14 package or smaller using the Tiny / Litle logic ic's from Texas Instruments / NXP.
Have it made and populated by AISLER in Germany (if you need more than one).
40€ assembly setup costs.

https://www.nxp.com/docs/en/brochure/Logic-MicroPak.pdf
https://www.ti.com/lit/sg/scyt129g/scyt129g.pdfpage 11, 13, 14, 15 (multi function), 16

VC1G00 Single 2-Input NAND Gate X X X X X X X
LVC1G02 Single 2-Input NOR Gate X X X X X X X
LVC1G04 Single Inverter X X X X X X X X
LVC1Gu04 Single Unbuffered Inverter X X X X X X X
LVC1Gx04 Crystal Oscillator Driver X X X
LVC1G06 Single Inverter Buffer/Driver w/Open Drain Output X X X X X X X
LVC1G07 Single Buffer/Driver w/Open Drain Output X X X X X X X X
LVC1G08 Single 2-Input AND Gate X X X X X X X
LVC1G10 Single 3-Input NAND Gate X X X X X
LVC1G11 Single 3-Input AND Gate X X X X X
LVC1G14 Single Schmitt Trigger Inverter X X X X X X X
LVC1G17 Single Schmitt Trigger Buffer X X X X X X X X
LVC1G18 1 of 2 Non-Inverting MUX X X X X X
LVC1G19 1 of 2 Decoder/Demultiplexer X X X X X
LVC1G27 Single 3-Input NOR Gate X X X X X
LVC1G29 2 of 3 Decoder/Demultiplexer X X X
LVC1G32 Single 2-Input OR Gate X X X X X X X
LVC1G34 Single Buffer Gate X X X X X X X X X
LVC1G38 Single 2-Input NAND Gate w/Open Drain Output X X X X X
LVC1G74 Single Positive-Edge-Triggered D-Type Flip-Flop X X X X
LVC1G79 Single D-Type Flip-Flop X X X X
LVC1G80 Single D-Type Flip-Flop X X X
LVC1G86 Single 2-Input Exclusive-OR Gate X X X X
LVC1G123 Single Retrig Monostable w/Schmitt Trigger Inputs X X X
LVC1G125 Single Bus Buffer Gate w/3-State Output X X X X X X X
LVC1G126 Single Bus Buffer Gate w/3-State Output X X X X X X
LVC1G132 Single 2-input NAND gate with Schmitt Trigger input X X X
LVC1G139 2-Line to 4-Line Decoder X X X
LVC1G175 Single D-Type Flip-Flop w/Asynch Clr X X X X
LVC1G240 Single Buffer/Driver w/3-State Output X X X X X
LVC1G332 Single 3-Input OR Gate X X X X X
LVC1G373 Single D-Type Latch w/3-State Output X X X
LVC1G374 Single D-Type Flip-Flop w/3-State Output X X X
LVC1G386 Single 3-Input Exclusive-OR Gate X X X X X
LVC1G0832 Single 3-Input Positive AND-OR Gate X X X
LVC1G3208 Single 3-Input Positive OR-AND Gate
etc

the biggest 4mm² and the smallest less than 1 mm².
there are also ones that don't exist in the cd4000 / 74 series.
Like FET switch: CBT1G125 Single FET Bus Switch
 
I have a Mute button, a Solo button and a solo dc bus.
The Mute button normaly toggles the Mute relay.
The Solo button applies dc to the solo bus and overrides overrides the Mute relay (if set) on the solo'd channel
The Solo dc bus operates the Mute relay on all channels that do not have the Solo button pressed

It sounds weird when you write it out in words but the logic is quite straightforward. You can do it with a couple of mechanical toggle switches and a couple of diodes
Yes. Those type of logical switching operations always tend to sound more complex than they really are imo. Case of picture worth a thousand words, as Telly Savalas might have "sung". Or a good old flowchart. But I can't think of a song with "flowchart" in the lyrics 🤔
 
Last edited:
Yes. Those type of logical switching operations always tend to sound more complex than they really are imo. Case of picture worth a thousand words, as Telly Savalas might have "sung". Or a good old flowchart. But I can't think of a song with "flow hart" in the lyrics 🤔
Yes, I drew the flowchart on a piece of paper using a pencil and eraser before starting to code. Cheapest most flexible and extensible CAD ever.;)

Cheers

Ian
 
You could configure your own "IC" and have the logic you want on a PCB the size of a dip 14 package or smaller using the Tiny / Litle logic ic's from Texas Instruments / NXP.
Have it made and populated by AISLER in Germany (if you need more than one).
40€ assembly setup costs.

https://www.nxp.com/docs/en/brochure/Logic-MicroPak.pdf
https://www.ti.com/lit/sg/scyt129g/scyt129g.pdfpage 11, 13, 14, 15 (multi function), 16
Thanks for sharing. I was completely unaware of these tiny logic gates. I thought the discrete IC market was all but dead but if Texas thinks it is worthwhile to make individual gates there must be a decent sized glue logic market.

Cheers

Ian
 
Thanks for sharing. I was completely unaware of these tiny logic gates. I thought the discrete IC market was all but dead but if Texas thinks it is worthwhile to make individual gates there must be a decent sized glue logic market.

Cheers

Ian
well, they are probably used in phones, tablets, among
Even contain analog audio switches.

Even the old Nokia 3310 used resistors that where incredibly small, maybe even smaller than 0402, pretty sure.

they are older than 5 years, i stumbled over them around that time.

the best programmers don't use a computer but pencil and paper i was toughed by a teacher.
a scheme exists and it's called Grafcet, a french system, but master that and your code is without any error or bugs at first compile and never fails.
 
well, they are probably used in phones, tablets, among
Even contain analog audio switches.

Even the old Nokia 3310 used resistors that where incredibly small, maybe even smaller than 0402, pretty sure.

they are older than 5 years, i stumbled over them around that time.

the best programmers don't use a computer but pencil and paper i was toughed by a teacher.
a scheme exists and it's called Grafcet, a french system, but master that and your code is without any error or bugs at first compile and never fails.
AFAIK the smallest SMD resistors are 0201....

JR
 
Smallest SMD resistor today (Oct. 2022) would be a 01005 (0402 Metric) ~ 0.016" L x 0.008" W (0.40mm x 0.20mm) :oops:

We where recently @ the SMD assembly line for a few Production runs - and my Boss asked the 'local Boss' how small SMD components they where placing for the Customers now-a-days and the size above where mentioned ...!... along with a few less nice words, as they where used by some that didn't need them that small + the Fact that in order to tell if they where soldered into place they had to feel them with their fingernails as the Eyes couldnt make them out ...!
 
well, use the interrupt "code" to detect button press rather than the main loop (NOP) and checking the button millions of times a second.

The best coding procedure is using state machines.

https://en.wikipedia.org/wiki/Finite-state_machine
When you are dedicating an entire MCU to such a simple functionality is does not seem worthwhile to add complexity.

Interrupts are useful to preserve processor overhead when dealing with lots of activity, IMO for something this simple KISS.

JR
 
When you are dedicating an entire MCU to such a simple functionality is does not seem worthwhile to add complexity.

Interrupts are useful to preserve processor overhead when dealing with lots of activity, IMO for something this simple KISS.

JR
Why complex?

void mybuttonISR(void);

void mybuttonISR(void)
{
...
..
.
}

Main(){
// setup chip
...
..
.
While(1) {
asm("nop");
}
}

in case the mcu detects a activity on the pin it executes a simple task.
You could even start a timer on that interrupt to measure how long you pressed the button.

You can leave the main loop empty (nop).
Using the main loop to check button would result that the button gets checked a few million times a second.
it takes a bit more and you can even set the chip to sleep if nothing is to be done, wake up when there is activity on the button and save on energy.
 
Using the main loop to check button would result that the button gets checked a few million times a second.
Conceptually it might sound like a good idea to avoid doing "work" if you don't need to. But the clock on a mircontroller is running regardless so you're not wasting power at all. There is zero benefit in efficiency / performance.

Also, in practice, a typical loop will do enough stuff that it's more like 10us/loop or 100,000/s. Much less if you're checking an ADC. But again, it wouldn't matter if it were millions because the clock is running regardless.

it takes a bit more and you can even set the chip to sleep if nothing is to be done, wake up when there is activity on the button and save on energy.
So are you suggesting that the chip be put into "sleep" mode until a button is pressed so that you can save 5mA?

And slow down the time it takes for your interrupt to run because it takes time for the chip to resume?
 
well, use the interrupt "code" to detect button press rather than the main loop (NOP) and checking the button millions of times a second.

The best coding procedure is using state machines.

https://en.wikipedia.org/wiki/Finite-state_machine
I mostly agree. The code I showed is proof of principle only. The problem with using an edge triggered interrupt is that switch bounce will cause multiple interrupts. To debounce you do need to wait a specific interval before checking the switch again (or allowing it to interrupt). The usual way is to set up a timer interrupt to read the switches every 25mS or so and use a state machine to determine true switch state. All this I am familiar with.

My primary aim, as described in the first post, was to verify that my logic in determining the toggle status was correct.

Cheers

Ian
 
I mostly agree. The code I showed is proof of principle only. The problem with using an edge triggered interrupt is that switch bounce will cause multiple interrupts. To debounce you do need to wait a specific interval before checking the switch again (or allowing it to interrupt). The usual way is to set up a timer interrupt to read the switches every 25mS or so and use a state machine to determine true switch state. All this I am familiar with.

My primary aim, as described in the first post, was to verify that my logic in determining the toggle status was correct.

Cheers

Ian
well, that's why you take a "state machine" approach, you check the button 250/500 times before proceeding.
if it's 250/500x uninterrupted times a "I", step over or repeat.

check the schematic of Microchip PicDem 2 board, they used a 100nF capacitor to debounce.

https://ww1.microchip.com/downloads/en/DeviceDoc/30374d.pdfpage 54
 

Latest posts

Back
Top