Relay Bypass with "latch" function

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

Previous topic - Next topic

Benoi31

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

samhay

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?
I'm a refugee of the great dropbox purge of '17.
Project details (schematics, layouts, etc) are slowly being added here: http://samdump.wordpress.com

slacker

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.

Benoi31

Hello,
thanks for the replies,
for now, I am using Basic (weird huh? but I have some background with it, it helps a bit)

cloudscapes

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
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}

samhay

>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
I'm a refugee of the great dropbox purge of '17.
Project details (schematics, layouts, etc) are slowly being added here: http://samdump.wordpress.com

Benoi31

Wow!
Thank you all!
Time to decipher all of this now

Hatredman


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.
Kirk Hammet invented the Burst Box.

Benoi31

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.

Hatredman


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?
Kirk Hammet invented the Burst Box.

Benoi31

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

Benoi31

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

>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.
I'm a refugee of the great dropbox purge of '17.
Project details (schematics, layouts, etc) are slowly being added here: http://samdump.wordpress.com

caldersm

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



Benoi31

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

samhay

>Do you need a transistor to drive the relay?

Almost certainly yes. I have used both MOSFETS and relatively high gain BJTs.
I'm a refugee of the great dropbox purge of '17.
Project details (schematics, layouts, etc) are slowly being added here: http://samdump.wordpress.com

Benoi31

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


samhay

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.
I'm a refugee of the great dropbox purge of '17.
Project details (schematics, layouts, etc) are slowly being added here: http://samdump.wordpress.com

Benoi31

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


Switch 1 is the soft SPST switch, and switch 2 is an optionnal switch to choose between momentary and "normal" activation of the effect.

Benoi31

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