Relay Bypass with "latch" function

Started by Benoi31, January 25, 2016, 05:13:37 AM

Previous topic - Next topic

Benoi31


ElectricDruid


thanal9999

#22
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
   }   
   
}

thanal9999

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!


Benoi31

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!

MetalGuy

Another good SMD alternative is VO1400AEFTR. It's tested to work very well as a "mute device".

Rixen

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

Beo

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.

electrosonic

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

Andrew.
  • SUPPORTER

MetalGuy

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.

Rixen

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

Beo

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

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.

Transmogrifox

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

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.

trans·mog·ri·fy
tr.v. trans·mog·ri·fied, trans·mog·ri·fy·ing, trans·mog·ri·fies To change into a different shape or form, especially one that is fantastic or bizarre.

Beo

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.

Transmogrifox

#34
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 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

And...
Here is yet another way to skin the cat:
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.
trans·mog·ri·fy
tr.v. trans·mog·ri·fied, trans·mog·ri·fy·ing, trans·mog·ri·fies To change into a different shape or form, especially one that is fantastic or bizarre.

Beo

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.

Benoi31

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.


Benoi31

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.


Benoi31

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