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

Not sure, how it will work, never tried it, but saw years back in the datasheet of the pic18F452 that you can put in sleep mode.

prevent Climate change
: )

1000 milisecond ÷10 mHz = 0.0001
100 nano second per line of code or in instruction.

Don't know how many channel he has or what he is building.
 
you check the button 250/500 times before proceeding.

Or you interrupt on the first edge, and in the ISR disable triggering on that input pin and set a timer interrupt. When the timer fires you check the pin again and make sure it has stopped bouncing. Or if you just want a toggle and don't care if the switch is held or not, you fire on the first edge, perform whatever toggle action you want, and then when the timer interrupt fires you re-arm if the switch has been released by then, or if the switch is still held you reset the timer interrupt and just repeat the timer ISR until the switch has been released, at which point you re-arm the switch edge triggered ISR.
 
My suggestion that using interrupts was unneeded complexity was based on my personal experience. Of course interrupts have their utility and sophisticated applications support multiple levels of hierarchy.

Just like the simple 4013 FF, MCUs need to be debounced...

JR
 
Seeing this thread - have to offer that it's a long time since I did switch reading BUT I can't recall it being so complex as much of the stuff going on here,
Assembler programming / 8 bit mcu / logic masking and firmware debounce / scan every 10ms.
Probably using timer interrupt but just to set a flag that is picked up inn the main loop,
 
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.
As I said, the code shown is proof of principle only. It is easier, faster and less error prone to get a loop with an included delay to work than to initially code an interrupt to do the same. The state machine applies to bot solutions
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
Yes I have seen this. It undoubtedly works in some cases but not all.

Cheers

Ian
 
Using an interrupt to detect when a human being has pressed / released a button is like using the Emergency Alert System to notify you that Olivia Rodrigo has released a new single.

An example of where using an interrupt would be appropriate would be to notify when data can be read / written with an asynchronous device like a disk drive where polling would negatively impact bandwidth.
 
Or you interrupt on the first edge, and in the ISR disable triggering on that input pin and set a timer interrupt. When the timer fires you check the pin again and make sure it has stopped bouncing. Or if you just want a toggle and don't care if the switch is held or not, you fire on the first edge, perform whatever toggle action you want, and then when the timer interrupt fires you re-arm if the switch has been released by then, or if the switch is still held you reset the timer interrupt and just repeat the timer ISR until the switch has been released, at which point you re-arm the switch edge triggered ISR.

You can also arm a Timer upon button press edge up, watch the timer value go up whilst checking the button pin.
The times doesn't have to binded to a interrupt, you can check the timer A and B register.
Kill the timer when button input pin = 0.

this code should only be about the buttons, the thing changes if do other tasks.
 
Ian, any issue with clock noise from a processor?

If you use momentary switches you only have one sku to order and you can do nice touches like global solo undo and group solos & mutes
 
Ian, any issue with clock noise from a processor?

If you use momentary switches you only have one sku to order and you can do nice touches like global solo undo and group solos & mutes

Do you mean that clock noise may induce false switch signals ?
If so then that should be addressed at source rather than relying on the switch detect circuit to deal with.
Apologies if I've misunderstood the point.
 
Ian, any issue with clock noise from a processor?

If you use momentary switches you only have one sku to order and you can do nice touches like global solo undo and group solos & mutes
None at all that I have come across. I have the code running on a proto board beside my keyboard all evening., I occasionally press the button and toggle the LED. So both debounce and the toggle logic work fine and these were my main concerns. Next step is to extend it to two buttons (solo and mute) and emulate the solo dc bus (using a toggle switch probably) and then verify the solo/mute logic. So far the code is a mere 96 bytes.

Cheers

Ian
 
There is absolutely no shortage of noob Arduino code

Cheers

Ian
;)
many people have no idea.
they only know the "arduino" IDE code.

sure it works or could work eventually and it seams to do the job apparently.

but these people never actually learn to program a chip.
how the properties of the chip work.

most of them probably never see the datasheet of the atmel.
i have spend alot of time with the pic18f452 to bad i had to use 74hc595 to add buttons and leds with the 74hc126 and lose time bitbanging while translating a midi signal. big part c and some assembler. i even printed out a part of the datasheet. it toke me like a half a year to get the lcd running.
accept for the bitbang part and paralel lcd, it was accurate with Ableton up to 999 BPM.
it even showed the cpu usesage, well showing when it's idle.

and you should have to read this page or you're just assuming.
https://en.wikipedia.org/wiki/Logic_gate
 

Latest posts

Back
Top