Professional Documents
Culture Documents
Coda Effects - Relay Bypass - Conception and Relay Bypass Code
Coda Effects - Relay Bypass - Conception and Relay Bypass Code
So... Why bother? My 3PDT switch is great, don't
HOME
you think?STEP BY STEP
ALL POSTS SHOP BUILDS ABOUT
Summary
How does relay bypass work?
Relay bypass circuit schematic
HOME
The microcontroller
ALL POSTS STEP BY STEP SHOP BUILDS ABOUT
The relay
PIC/PC communication device: the
PICKIT2
PIC configuration bits
C source code to sense the switch
HOME ALL POSTS STEP BY STEP SHOP BUILDS ABOUT
The microcontroller
Good!
The relay
PIC / PC interface
In order to code and burn the chips, we need
something to connect it to our computer, that
will allow us to burn the code in the
microcontroller.
Setup everything.
HOME ALL POSTS STEP BY STEP SHOP BUILDS ABOUT
select "OFF".
HOME
Once you are
ALL POSTS
done withSHOP
STEP BY STEP
that ("INTRCIO",
BUILDS
then
ABOUT
everything "OFF"), you can click on the big
"Generate Source Code to Output" button. It
should display a code in the "Config Bits Source"
window. Select and copy this code:
HOME
Then, choose
ALL POSTS
the nameSHOP
STEP BY STEP
of theBUILDS
file, andABOUT
click on
"Finish". The file should be placed in the "Source
Files" folders:
// Supplementary libraries
#include <stdint.h>
#include <xc.h>
// Include configuration bits
void main(void) {
}
First, we have to create a variable that will
HOME
define theSTEP
ALL POSTS
current
BY STEP
state
SHOP
of the pedal.
BUILDS
Here, I
ABOUT
named it "state". It can have two values : 1 (pedal
is "on") or 0 (pedal is "off'").
When the PIC start (when a power supply is
connected to the pedal), we can make the effect
off by defining the initial value of state equal to
0. Write this code inside the "{}":
TRISIO0 = 0; // pin 7 is an
output (0 like "Output")
TRISIO4 = 0;
TRISIO5 = 0;
TRISIO1 = 1; // pin 6 is an
input (1 as "Input")
GPIO=0; // all the GPIOs are
in low state (0V) when
starting
while(1) {
if(GP1 == 0) { // if the
switch is pressed
}
HOME ALL POSTS STEP BY STEP SHOP BUILDS ABOUT
}
while(1) {
if(GP1 == 0) { // if the
switch is pressed
if(state == 1) { // if
the pedal is on...
state=0; // ...turn
it off
}
if(state == 0) { // if
the pedal is off
state=1; // ...turn
it on
}
}
}
HOME ALL POSTS STEP BY STEP SHOP BUILDS ABOUT
The variable state is changed when we press the
switch!
Debouncing
Well, practically speaking, it is not that easy...
When you press a switch, it does not usually
provide a clean edge. There are some "bounces"
and peaks, and the switch can be "on / off" very
quickly when pressed, during a very short
amount of time:
while(1) {
if(GP1 == 0) { // if the
switch is pressed
__delay_ms(15); //
debounce
if(GP1 == 0) {
if(state == 1) {
// if the pedal is on...
state=0; //
...turn it off
}
if(state == 0) {
// if the pedal is off...
state=1; //
...turn it on
}
}
}
}
}
__delay_ms(10);
void main(void) {
while(1) {
if(GP1 == 0) { // if the
switch is pressed
__delay_ms(15); //
debounce
if(GP1 == 0) {
__delay_ms(200);
if(GP1 == 1) { //
switch is not pressed anymore
if(state == 1)
{ // if the pedal is on...
state=0; //
...turn it off
}
if(state == 0)
{ // if the pedal is off...
state=1; //
...turn it on
}
}
}
}
}
}
__delay_ms(10);
HOME ALL POSTS STEP BY STEP SHOP BUILDS ABOUT
You can try different __wait_ms() durations here,
I found that 200 ms was quite good: not too long
(we do not want to wait too much to activate the
pedal), and not too short (false positives)
if(state == 1) { // if the
pedal is on
GP5=1; // activate the
relay
GP4=0;
GP0=1; // turn the LED on
}
else { // else (if the pedal
is off)
GP5=0; // inactivate the
relay
GP4=0;
GP0=0; // turn the LED off
}
__delay_ms(10); // we wait for
the PIC to change the state of
HOME ALL POSTS STEP BY STEP SHOP BUILDS ABOUT
each GPIO
#include <stdio.h>
#include <stdlib.h>
#include <stdint>
#include <xc.h>
#include "header.h" // Include
the header (configuration
bits)
HOME ALL POSTS STEP BY STEP SHOP BUILDS ABOUT
HOME
Change the
ALL POSTS
VDD for 5V,
STEP BY STEP
thenBUILDS
SHOP
click onABOUT
"Write"
and it should be programmed to the PIC!
RELATED POSTS
What is guitar signal?
Big Muff Ram's Head clone (73 version)
Potentiometers and guitar effects
Vemuram Jan Ray clone
LPB1 boost
Klon Centaur Clone and mods (Aion Refractor)