Hello !
Do you know if there are any relay bypass PCB out there with a "latch / unlatch" function ?
I mean the possibility to wire a switch that would let you choose between normal switching or a temporary switching while your foot is on the switch.
I am currently designing a tremolo, and I think it could be a nice feature to add to it (especially with square waves)
I am also learning PIC programming, but relay bypass is not as easy as it seems to program... And I find the lack of source code disturbing for such a project that could be a great way to learn PIC programming.
For now I am really a beginner (light up a LED, sense a switch), but if by any chance I manage to get the code right, I will try to make a tutorial on my blog;
Thank you !
Benoit
If you can turn an LED on and off with a PIC, you can do the same with a non-latching relay.
Are you using Assembly or C?
With a micro controller it's possible to detect between a switch being pressed and then quickly released and one being pressed and held down so you could do your latch/unlatch switching without a second switch to choose which.
I'm working on something that does this at the moment, not for switching a relay but the idea is the same, I can post some example code if you like.
Hello,
thanks for the replies,
for now, I am using Basic (weird huh? but I have some background with it, it helps a bit)
are you using bascom? if so, I can share my bascom code for relay bypass. comes with debounce.
$regfile = "atTiny85.dat"
$crystal = 1000000
Config Pinb.2 = Output 'LED
Config Pinb.3 = Output 'Relay 1
Config Pinb.4 = Output 'Relay 2
Config Pinb.0 = Input ' Stomp
Dim Bypass As Boolean
Dim Button As Boolean
'default
Pinb.2 = 0
Bypass = 1
Button = 0
Portb.3 = 1
Portb.4 = 0
Waitms 5
Portb.3 = 0
Portb.4 = 0
Do
If Pinb.0 = 1 Then
Waitms 20
If Pinb.0 = 1 Then 'debounce
If Bypass = 1 And Button = 0 Then
Portb.2 = 1
Bypass = 0
Portb.3 = 0
Portb.4 = 1
Button = 1
Elseif Bypass = 0 And Button = 0 Then
Portb.2 = 0
Bypass = 1
Portb.3 = 1
Portb.4 = 0
Button = 1
End If
Waitms 5
Portb.3 = 0
Portb.4 = 0
End If
End If
If Pinb.0 = 0 And Button = 1 Then
Button = 0
End If
Waitms 10
Loop
End
>with a micro controller it's possible to detect between a switch being pressed and then quickly released and one being pressed and held down so you could do your latch/unlatch switching without a second switch to choose which.
I like to do this to save a footswitch and have previously posted some rough code that does this here:
http://www.diystompboxes.com/smfforum/index.php?topic=107226.msg1013314#msg1013314
Wow!
Thank you all!
Time to decipher all of this now
Quote from: slacker on January 25, 2016, 01:04:41 PM
With a micro controller it's possible to detect between a switch being pressed and then quickly released and one being pressed and held down so you could do your latch/unlatch switching without a second switch...
Does it need to be microprocessed?
On a school I went to, all classrooms had slide projectors with ONE push button for operation. Press and quick release, next slide. Press and hold, previous slide.
It was in the seventies, I really doubt it was microprocessed.
You can do it with FET switching (like on some old Boss pedals), but it is rather a big system compared to a microprocessor scheme, and I figured out that it was a good way to start learning programming PICs. (which is always useful, right ? ^^)
For now my PIC is blinking a LED when I press a button, so I am waiting to receive the relays and it should be done (or I hope so)
I had hard time finding which software to use, how to emulate a Pic...etc, but finally managed to do it.
Quote from: Benoi31 on February 08, 2016, 04:28:38 AM
I had hard time finding which software to use, how to emulate a Pic...etc, but finally managed to do it.
Hummm, care to share?
No problem of course!
I decided to use MPlab X, and a PicKit 2 with an adaptator (this one precisely: http://www.ebay.fr/itm/PICkit2-PIC-KIT2-debugger-programmer-for-dsPIC-PIC32-PIC24-Logifind-adapter-UK-/272114170848?var=&hash=item3f5b44bbe0:m:mIELUS3LF9UEks5m_qdscVw )
MPLab is quite complex to handle, but this video presents well how to start:
https://www.youtube.com/watch?v=mUofSucHx_E
To test my code before burning the chip, I used Real Pic Simulator:
http://digitalelectrosoft.com/pic-simulator
Quote from: cloudscapes on January 25, 2016, 07:48:30 PM
are you using bascom? if so, I can share my bascom code for relay bypass. comes with debounce.
$regfile = "atTiny85.dat"
$crystal = 1000000
Config Pinb.2 = Output 'LED
Config Pinb.3 = Output 'Relay 1
Config Pinb.4 = Output 'Relay 2
Config Pinb.0 = Input ' Stomp
Dim Bypass As Boolean
Dim Button As Boolean
'default
Pinb.2 = 0
Bypass = 1
Button = 0
Portb.3 = 1
Portb.4 = 0
Waitms 5
Portb.3 = 0
Portb.4 = 0
Do
If Pinb.0 = 1 Then
Waitms 20
If Pinb.0 = 1 Then 'debounce
If Bypass = 1 And Button = 0 Then
Portb.2 = 1
Bypass = 0
Portb.3 = 0
Portb.4 = 1
Button = 1
Elseif Bypass = 0 And Button = 0 Then
Portb.2 = 0
Bypass = 1
Portb.3 = 1
Portb.4 = 0
Button = 1
End If
Waitms 5
Portb.3 = 0
Portb.4 = 0
End If
End If
If Pinb.0 = 0 And Button = 1 Then
Button = 0
End If
Waitms 10
Loop
End
I have now a code that is pretty similar to this one (in C though).
Samhay, why do you use shadow registers for sGPIO? I am not familiar with this concept.
Is 200 ms enough to differentiate a long press and a short press of the switch?
Also, is a debounce counter really better than a simple :
if switch =1
__wait_ms(20)
if switch = 1
change state
?
Thank you for your help
>Samhay, why do you use shadow registers for sGPIO? I am not familiar with this concept.
It's often not necessary, but can be good practice with the basic PICs as it prevents read/modify/write errors. If you google 'shadow register' you should find plenty of more thorough explanation.
Benoit,
I finished some code doing just that in an application. If you pressed and held the foot switch down for 3 seconds it would program that switch to output a 100 msec pulse, instead of latching it the switch output on and off. Holding the switch down for another 3 seconds would switch it to a normal latching on/off mode.
Basically, you look for the switch press to be a "0"(that is ON) and start to increment a timer and if it exceeds a certain amount, then you set a bit to change the switch function after the switch is released. Below find the Check Switch function written in C. Reacting to whether Prg = 1 or Prg = 0 is in another subroutine.
void Check_Switch_Pressed() {
while (digitalRead(Pin_Sw[Switch]) == 0) { //Is Key pressed on current Switch(Press = Zero)
hold_delay++; //Each hold delay is equal to 50ms....add 1 to here.
time_delay = (hold_delay * 50)/1000; //Each time delay is equal to 1sec
delay(50); //Go to sleep for 50ms for Switch debounce
if(time_delay >= 3 && time_delay <= 5 && Prg == 0) { //If switch is held >= 3secs and <= 5secs Then
Prg = 1; //Set Program Mode Bit to execute Program Mode Code when Switch is Released.
Slow_Flasher(3); //Flash Button LED 3 times to Let User know they are in Program Mode
}
}
}
Yeah it works for the switching part :)
Just miss the relay (currently waiting for parts..)
Do you need a transistor to drive the relay? What is the maximum output current of a PIC 12F675? I read 20 mA somewhere, but I am not sure... I ordered 100mW switching relay, it should be enough (or I hope so!)
I am now working on the temporary mod, set with a switch.
void Check_Switch_Pressed() {
while (digitalRead(Pin_Sw[Switch]) == 0) { //Is Key pressed on current Switch(Press = Zero)
hold_delay++; //Each hold delay is equal to 50ms....add 1 to here.
time_delay = (hold_delay * 50)/1000; //Each time delay is equal to 1sec
delay(50); //Go to sleep for 50ms for Switch debounce
if(time_delay >= 3 && time_delay <= 5 && Prg == 0) { //If switch is held >= 3secs and <= 5secs Then
Prg = 1; //Set Program Mode Bit to execute Program Mode Code when Switch is Released.
Slow_Flasher(3); //Flash Button LED 3 times to Let User know they are in Program Mode
}
}
}
Clever, but I rather use an external switch for now (better with my current design of the pedal)
I am going to configure the last GPIO as an input for the switch (with values of 5V or 0V - 1 or 0), and I will add a if / else in the code architecture to make the activation temporary.
>Do you need a transistor to drive the relay?
Almost certainly yes. I have used both MOSFETS and relatively high gain BJTs.
Ok so my code works for momentary activation now, with an external switch to choose between the two modes. I am quite proud of myself :icon_mrgreen: (I know, this is complete beginner stuff, but still, feels good to make something that works!)
I am still waiting for the relay to be in my mailbox. I'll try to add a transistor to drive the relay
I also noticed that some people use an optofet to silence the switch while switching (http://www.diystompboxes.com/smfforum/index.php?topic=112029.0)
Do you think it is necessary? Is the amount of "clicking" noises important with a simple relay scheme?
Thank you all!
I'll try to post my code this evening if that is of any help
Well done - sounds like good progress.
As far as switch noise / bounce goes. I have only one pedal (with a relay) where this is a problem. A mute (optoFET or otherwise) might help, but I would treat this on a case-by-case basis.
Hello !
So, just to let you know, I prototyped the PIC on my breadboard, and everything worked, even without a transistor to amplify the current to activate the relay :)
I used a relay that is slightly bigger than the classic Panasonic TQ2L, and that is also way cheaper, a Takamisawa NA05W-K.
I conceive a small PCB that can fit in 1590A enclosure, currently waiting for it
(https://scontent-cdg2-1.xx.fbcdn.net/hphotos-xlp1/v/t1.0-9/12814327_1709754915947333_1771382263482021959_n.png?oh=97aef1c728fe450f2fb7952880fa9312&oe=575E6842)
Switch 1 is the soft SPST switch, and switch 2 is an optionnal switch to choose between momentary and "normal" activation of the effect.
Hello everyone, I wrote a full blog post about relay bypass on my blog. Unfortunately, I only have the french version for now, but the english one should be released soon.
At least, the source code is there :
http://www.coda-effects.fr/2016/04/relay-bypass-mise-au-point-et.html
Hello, here is the english version of the tutorial, hope that it helps!
http://www.coda-effects.com/2016/04/relay-bypass-conception-and-relay.html
Nice work. Thanks for sharing!
Tom
Hello Benoi.
I am trying to create a triple pedal switching with PIC picrocontroller.
So inspired from your post and blog I thought to give a try on your code for a single pedal and start from there tweaking it for my purposes.
(I am a noob at programming but I am in the learning process)
So I burned the code into a pic12f629 (same as 12f675 without AD converters) and something strange happens.
The led and relay engages when I press the momentary switch but then it remains "on" whatever I press the switch again or not... Do you have any idea why this is?
I forgot to mention that I used a transistor to drive the relay and the LED... So I used only 1 output pin(GP5) as output.
This is the code...
void main(void) {//main loop
CMCON = 0x07; // comparator off
uint8_t state; // variable that will define the pedal's state: on or off
state=0;
TRISIO0 = 1;
TRISIO1 = 1;
TRISIO2 = 0;
TRISIO3 = 1;
TRISIO4 = 0;
TRISIO5 = 0;
GPIO=0; // Initially, all GPIOs are in a low state
while(1) {
if(GP1 == 0) { // if the switch is pressed
__delay_ms(15); // debounce
if(GP1 == 0) {
__delay_ms(200); // switch released
if(GP1 == 1) {
if(state == 1) { // if the effect is on
state=0; // ...turn it off
}
if(state == 0) { // if the pedal is off
state=1; // ...turn if on
}
}
}
}
__delay_ms(10);
if(state == 1) { // if the pedal is on
GP5=1; // activate the relay
}
else { // else (if the pedal is off)
GP5=0; // inactivate the relay
}
__delay_ms(10); // we wait for the PIC to change the state of each GPIO
}
}
It seems that with a liitle change in the code, it works fine... (with some help from the comment section on the blog of Benoi)
if(GP1 == 0) { // if the switch is pressed
__delay_ms(15); // debounce
if(GP1 == 0) {
__delay_ms(200); // switch released
if(GP1 == 1) {
if(state == 1) { // if the effect is on
state=0; // ...turn it off
}
else { // if the pedal is off
state=1; // ...turn if on
}
just an "else" statement instead of "if" after if(GP1==1)
Thank you for all your info and help Benoi!
Hello everyone!
I updated the system with a photoFET to make it completely silent when switching:
http://www.coda-effects.com/2016/08/relay-bypass-with-anti-pop-system.html
Updated code too!
Another good SMD alternative is VO1400AEFTR. It's tested to work very well as a "mute device".
Quote from: MetalGuy on August 22, 2016, 04:14:19 PM
Another good SMD alternative is VO1400AEFTR. It's tested to work very well as a "mute device".
..which also looks like it has a smooth and relatively slow response (52 - 500us) compared to other photo MOSFETS...
Quote from: Benoi31 on August 18, 2016, 12:35:43 PM
Hello everyone!
I updated the system with a photoFET to make it completely silent when switching:
http://www.coda-effects.com/2016/08/relay-bypass-with-anti-pop-system.html
Updated code too!
Looks like you have the PhotoFET wired direct. Don't you need a small current limiting resistor to feed the LED side so you don't blow it (I use 1k for 5v driving pin)? Also, I found I needed a 10uF electro cap across the LED to slow down the FET on/off curve (instant mute causes it's own click/thump). Could be done by ramping up/down the activation with PWM but the cap is easy.
One of the members here investigated using a cap to slow the switch transients and found it ineffective. Did you find out otherwise? (He also mentions the PWM approach)
http://stompville.co.uk/?p=423 (http://stompville.co.uk/?p=423)
Andrew.
Quote..which also looks like it has a smooth and relatively slow response (52 - 500us) compared to other photo MOSFETS...
Seriously? You call 500
microseconds slow?
I've tested and used these in tube amps replacing J174s and they work very well.
Although an SMD part on double layer boards it fits and can be soldered directly on the DIP4 pads.
Quote from: MetalGuy on August 23, 2016, 03:53:44 PM
Quote..which also looks like it has a smooth and relatively slow response (52 - 500us) compared to other photo MOSFETS...
Seriously? You call 500 microseconds slow?
I've tested and used these in tube amps replacing J174s and they work very well.
Although an SMD part on double layer boards it fits and can be soldered directly on the DIP4 pads.
yes, and I meant in a positive sense for this application- reduced transients. Although the TLP220 is slower at 0.5 to 1.0
ms . Looks like the price (VO1400AEFTR) is good too..
Quote from: electrosonic on August 23, 2016, 01:32:50 PM
One of the members here investigated using a cap to slow the switch transients and found it ineffective. Did you find out otherwise? (He also mentions the PWM approach)
http://stompville.co.uk/?p=423 (http://stompville.co.uk/?p=423)
Andrew.
I found it helped, but didn't completely get rid of the thump. Testing the mute by itself with relay out proved that a fast mute was adding it's own thump. I might try the pwm ramp up/down. Elegant as it reduces parts, if it can be dialed in.
Quote from: Beo on August 23, 2016, 06:40:50 PM
Quote from: electrosonic on August 23, 2016, 01:32:50 PM
One of the members here investigated using a cap to slow the switch transients and found it ineffective. Did you find out otherwise? (He also mentions the PWM approach)
http://stompville.co.uk/?p=423 (http://stompville.co.uk/?p=423)
Andrew.
I found it helped, but didn't completely get rid of the thump. Testing the mute by itself with relay out proved that a fast mute was adding it's own thump. I might try the pwm ramp up/down. Elegant as it reduces parts, if it can be dialed in.
Pay attention to your power supply noise when the relay switches. That instant demand for current will be seen at the 9V input and put a bump into your circuit.
I usually put a resistor in series with the regulator feeding the microcontroller along with a big cap. Place the big cap so it is a short loop between microcontroller ground pins and regulator input.
That way when it switches it takes the energy out of the cap in a short loop and then the recharge time on the cap through the resistor is much slower so it doesn't couple much of an audible sound into the power supply rails.
You might find after decoupling the power supply from the switching circuit that you don't have any need for a mute circuit. I have a fuzz working right now that uses latching relay bypass (it's not microcontroller but same principle). It's quiet enough on its own.
Quote from: Transmogrifox on August 23, 2016, 07:53:27 PM
I usually put a resistor in series with the regulator feeding the microcontroller along with a big cap. Place the big cap so it is a short loop between microcontroller ground pins and regulator input.
By regulator input, you mean on the 9v side of the regulator? I use 5v latching relays (driving +/- relay pins for a pretty short duration). I wouldn't have thought this would be a sharp drain back through the regulator. I use a 10uF and a 100nF cap on the 5V side of the regulator, making sure cap +ve is very close to uC power pin, but not sure if ground pins are close to uC ground pin.
Yes, on the 9V side.
The current has to come from somewhere. My simulations told me a 10 uF on the 5V side will barely touch this.
Here's about what is happening:
5V relay coil resistance = 178 ohms (based on this (http://www.mouser.com/ds/2/212/KEM_R7001_EA2_EB2-780767.pdf) 5V double coil latch relay)
Coil current = 28 mA
Pulse timing recommended by manufacturer is 10ms.
If
C=10uF
T=10ms
I=28mA
Then
V=IT/C= 28V
This means a 10uF cap with a 28mA ideal current source applied would drop by 28V after 10ms. For the relay circuit this means 10uF doesn't have enough energy to even latch the coil, so where does the extra energy come from? It comes from the LDO, which comes out of the 9V supply.
Now suppose your 9V supply has a capacitance of 330uF on it, let us consider what this current pulse does to the 9V supply:
10ms*28mA/330uF = 848 mV
If wired to a good DC supply, probably source impedance is 1 to 2 ohms so you might see a dip closer to 50 mV, but that is still quite a lot if coupled into the signal path. Definitely will be audible in a booster, fuzz or anything with an amplifier stage like a typical booster. Most op amp circuits would tend to do better at rejecting power supply noise.
Either way maybe you can see why I tend to think the pop is not due to some kind of EMI coupling of coil current to the relay contacts.
If you put the storage capacitor on the upstream (9V) side of the LDO you can get more energy per capacitance because you can allow for a significant voltage drop.
Suppose you want to be able to latch the relay when supply voltage is as low as 7V, so the available juice is 7V-5V = 2V difference on the cap.
I=28mA
T=10ms
V=2V
C = I*T/V = 28m*10m/2 = 140 uF
So bare minimum is 140uF. Put in 150uF or 220uF and you have the energy storage available.
Now size the resistor so you don't take much current off the 9V input.
You probably want to prevent more than about 2 mA coming out of the supply when this switches, and assuming a 2V dip, you get
2V/2mA = 1k-ohm
Now check the time constant to be sure it recharges acceptably fast:
R*C = 1k*220u = 220ms
Can't imagine re-triggering this within 220ms so it will be recharged enough to switch again.
The other concern you might have to take into consideration is the power usage of your PIC chip. I was using an analog latch circuit which was using <100uA so its drain on the 1k was not worth considering.
If your PIC is using, say, 1mA then you have a trade-off between capacitor size and resistor size to make sure you have enough headroom to drive the relay without resetting the PIC vs capacitor size.
In other words, your PIC takes 1V out of your margin and then you can only operate down to 8V instead of 7V. This is no problem if you never use a battery, but it is nice if your FX circuit starts sounding bad due to low battery before the relay switching circuit is unable to activate the switch.
Either way this is a good start.
Also from the calculations maybe you can see how reducing the pulse-width helps. I have seen my single-coil units latch within 1ms, but the datasheet suggests 10ms so I design my circuits to meet that target.
One way to demonstrate to yourself that the pop is not due to coupling between coil and contacts is drive the coils directly with a battery and resistor (150 ohm) with no connection to the signal power or ground. I expect this to be equivalent to a mechanical stomp switch (which isn't click-free, but not usually irritating).
Then you will know if you hear popping when using the same power source as the effect that the power supply filtering and ground connection layout is where you need to focus your attention.
Look here for some more info about popping during switch activation:
http://www.muzique.com/lab/pop.htm (http://www.muzique.com/lab/pop.htm)
And...
Here is yet another way to skin the cat:
http://www.diystompboxes.com/smfforum/index.php?topic=109159.0 (http://www.diystompboxes.com/smfforum/index.php?topic=109159.0)
It uses a single-coil latching relay which has a bit higher coil resistance (lower current than the double coil type). Driven directly from MCU pins.
Nice stuff Foxy, I appreciate the math. I definitely need to focus on power conditioning my uC. I spent hours messing with slowing down the mute, DC coupling the signals and snubbing the relay, all trying to get super quiet... thinking the whole time my power was solid.
QuoteAnother good SMD alternative is VO1400AEFTR. It's tested to work very well as a "mute device".
Good to know! I am not very familiar with SMD yet, but if I use it one time, I will remember this option.
QuoteLooks like you have the PhotoFET wired direct. Don't you need a small current limiting resistor to feed the LED side so you don't blow it (I use 1k for 5v driving pin)? Also, I found I needed a 10uF electro cap across the LED to slow down the FET on/off curve (instant mute causes it's own click/thump). Could be done by ramping up/down the activation with PWM but the cap is easy.
Actually, this is a mistake from my part, I used the resistor on my build. I will correct the blog post soon. I used 1k as well.
QuotePlace the big cap so it is a short loop between microcontroller ground pins and regulator input.
I think this is a good general tip when working with regulators / microcontroller. This was the only way to remove the ticking I had with my tap tempo tremolo.
Hello!
I am still working on this project and I found a way to add :
- a temporary activation mode (like a "hold" mode for the pedal) that you can select with a switch
- a way to activate the relay when you press the switch (and not when the switch is released like the previous version)
I am currently writing up a blog post about it, however if you are interested, I made a GitHub repository with the project
https://github.com/benoitme/relaybypass
You can read the C code here: https://github.com/benoitme/relaybypass/blob/master/relayonpress.c
and the header here: https://github.com/benoitme/relaybypass/blob/master/header.h
There is also the .hex file in the "dist" folder if you wish to flash PIC directly.
If you have a Github account (any programmer around us?), do not hesitate to star the project for updates, or to fork it if you wish to modify it to do your own version.
Just a small update to say that I made the PCB and preprogrammed PIC available on my website if that is of any interest for anyone :
http://www.coda-effects.com/p/relay-bypass-pcb.html (http://www.coda-effects.com/p/relay-bypass-pcb.html)