So... Why bother? My 3PDT switch is great, don't you think?
A classical high quality 3PDT switch is rated for 30,000 activation cycles. With relay bypass, we use a relay that will play the mechanical role of connecting ins and outs. Relays are usually rated between 10 and 100 millions cycles! Thus, this system is much more reliable.
Moreover, the soft switch that we use to activate the guitar pedals also last longer than a 3PDT, usually around 50,000 cycles! They are also easier to replace, as there are only 2 connections to make with the relay bypass system, and not the full 3PDT wiring.
This blog post will present you how does it work, and how to make your own relay bypass system using a microcontroller, from the beginning to the end! Long stuff (but good stuff?)!
Summary
- How does relay bypass work?
- Relay bypass circuit schematic
- The microcontroller
- The relay
- PIC/PC communication device: the PICKIT2
- PIC configuration bits
- C source code to sense the switch
How does relay bypass work?
A relay works like a switch that is activated by a given voltage. There is a coil inside; when it receives a precise current, it will activate the internal switch of the relay. Therefore, the symbol looks like a switch:
The internal switch can be of different nature, and some relays have an internal DPDT built in! This will allow us to switch between "bypass" and "effect on" status.
Unfortunately, relays with an internal 3PDT are quite rare and really big... So how are we going to do to light up the LED? We are going to use a microcontroller. A microcontroller is a 8 pins digital IC that is kind of a mini computer! We can burn the microcontroller with a code that will tell it precisely what it should do. Here, we are going to say to the microcontroller : "activate the relay when I press the switch, and light up the LED"
Here is what it looks like in a commercial pedal (Dr Scientist) :
It look simple, but trust me, it is not as easy as it seems to implement ;)
Relay bypass circuit schematic
Here is the schematic of the relay bypass circuit:
As you can see on the schematic, the PIC12F675 requires a 5V regulated voltage on its pin number 1, and pin number 8 should be connected to the ground. To supply the 5V regulated voltage, we can use a voltage regulator, the 78L05, which is commonly used on circuit implementing a numeric chip, like the Rub a Dub Reverb. The C1 capacitor will avoid any variation of voltage due to the power supply.
Then, the relay is wired as a true bypass DPDT: signal enter through one pin, and is redirected either to the output (bypass), either to the input of the circuit board (SND).) The diode connected to the relay avoid the coil of the relay to blow up the circuit when it is turned off (it can generate a parasitic current).
The microcontroller
Each remaining pin of the microcontroller (pins number 2, 3, 4, 5, 6 and 7) can be used either as an input or an output. They are called GPIOs (General Purpose Inputs / Outputs) and you can configure them as you want with the code we are going to burn in the microcontroller:
- Input: the microcontroller can "sense" what happens on this pin: value of the voltage, pressed switch...etc. It can receive "electrical data" on this pin.
- Output: the microcontroller can send an electrical signal from this pin to the components connected to it. If you send a specific voltage or a voltage with a precise frequency, you can send "electrical data" to other numeric chips like digital potentiometers.
BEWARE : in order to make it easier and logic (irony inside...), the numbers of the GPIOs are different from the number of the pins... Here is a schematic:
Thus, pin number 2 is GPIO number 5, pin 6 is GPIO 1...Etc. In the code that we are going to write, the GPIOs that we will use will have to be named with the GPIO numbers, not the pins numbers!
Good!
Each GPIO can also be configured to be analog or digital:
- Analog : an Analog to Digital Converter (ADC) included in the chip can be use to "read" precisely the value of a voltage, on a 0 to 255 scale (the PIC12F675 is an 8 bit chip, but 16 or 32 bits chips also exist, allowing you to have bigger scales, like 0 to 1023). We can also use a Digital to Analog Converter (DAC) to send a precise voltage on an output.
- Digital : the chip will detect "on" or "off" states, that is to say a "high" or "low" voltage. It is like reading 1 or 0 for a computer. Here, the "high" value will be 5V (it depends on the chip), and "low" value 0V.
To sense the switch, no need to use a "scale" for sensing it: it is either on or off! So the input will be digital as well.
Setting the states of the GPIO high or low will be enough to fully control the relay and LED.
We will see later how to do that in the code example.
The relay
There are many many different relays out there, that will need different voltages to switch. They have different sizes and shapes. Reed relay look like integrated circuits, classical relays like big boxes, with different numbers of pins... Also, there is specific power needed to switch the relay : the activation power. Here are a few examples of relays:
So; we are going to use the high state of the GPIOs to activate the relay. The "high state" is 5V here, so we need a relay that can be activated by a 5V voltage.
For our usage, we need a relay that is:
- Small: if we want the circuit to fit in a 1590A enclosure, we need to make as small as possible. The smaller the better!
- Activation with a 5V voltage: 5V is the "high" value that the microcontroller can send from a pin, so we need a relay that can be activated with such a voltage.
- Low activation power: the microcontroller does not deliver a high intensity output. Generally speaking, it is around 20 mA maximum, which makes a 100mW power on an output. Remember that we can use a transistor to amplify a bit the current if needed.
- DPDT: we need a DPDT to switch the input and the output at the same time.
- Affordable: we do not want this system to cost 100 times the price of a 3PDT... As it can last 3 times longer than a 3PDT bypass system, we can aim a total cost of around 3 times the price of a good 3PDT, that is to say 10 euros approximately. The soft switch already cost around 3 euros, which let 7 euros for all the remaining parts, PCB included!
- No surface mount devices: we want something easy to assemble and repair.
So I had to read a lot (like, a lot!) of datasheets of different relays to find the perfect fit...
And the winner is...
The Takamisawa NA05W-K ! Small sized, cheap (less than 2 euros!), 140mW activation power, DPDT... Seems like a perfect candidate for what we want to do!
The Panasonic TQ2-L - 5V seemed also like a good option: 140mW, a bit bigger though, and more expensive (around 4 euros). However, it is a latching relay which is a bit different from the takamisawa that is a non-latching type.
Relay bypass code (in C)
So, we know what we are going to do, which components we need... We "only" have the PIC to code left to do!
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.For PICs, it is very simple: MicroChip manufactures and sells an interface called PicKit 2 (there is a version 3, but it is more expensive and not very different from the version 2). I strongly advise you to buy an adapter that will make the overall process way simpler than using a breadboard.
There are plenty of good deals online for the PicKit, you can find it for 20 dollars easily. It is like buying a soldering iron: you can use it many times so it is worth the investment! Also, do not forget to buy a bunch of PICs (12F675).
On your PC, you need three softwares to work correctly with PICs:
- MPLabX: it is a free software (well in its simplified version that is perfect for us) that you can download on the MicroChip website. It allow us to code the PIC in C (instead of assembly language that is a low level, very complex language). Click on the "download" tab on this webpage.
- XC8 compiler: the compiler will transform the code that we write in C into a understandable code for the PIC: the hexadecimal format. You can download it on the MicroChip website ("download" tab as well)
- PicKit2 software: it allow your computer to "speak" with the PicKit2 interface. We will use this software in the final steps of this tutorial to burn the code. Download it here. (PicKit2 install A)
Once you are done with the setup of the softwares, place the PIC correctly on the adapter:
Now, open PicKit2 on your computer. It should be able to detect the PicKit ("PicKit 2 connected"):
Lets detect the PIC. In order to do that, you need to select the type of Pic you are using. Click on "Device Family", then "Midrange", and "Standard":
PIC configuration bits
Before doing anything else, we need to configure the PIC, in order to set the features that we need or not. This step is absolutely necessary, the PIC will not even initiate if you do not do it.If you are lost at any step of this tutorial, you can also watch this video that explain quite nicely how to configure the PIC.
To configure the PIC, we first need to create a project in MPLAB. To do that, open MPLab X, click on "File", "New Project", then choose "Standalone Project" and click "Next". You need to choose the type of PIC that we are going to use. Just type the name of the PIC in the "Device" bar, PIC12F675:
Lets configure the PIC. To do that, we need to create a header file that will contain all the configuration information (="configuration bits"). Click on "New", "File". A window will open. Select the "C" folder (we want to program in C, but you can program in other languages depending on the folder you choose: C++, assembler (good luck with that), XML...), and select the "C Header File":
- Oscillator Selection bits : the oscillator is the clock needed for the PIC. It can be either external (using a quartz, and 2 GPIOs), or internal if the PIC has an internal clock. The PIC12F675 has an internal clock, so we are going to use it, by using the "INTRCIO" option. The clock is needed here to use functions like __wait_ms() that will allow us to pause the program for a specific amount of time (in milliseconds).
- Watchdog timer : not necessary here: "OFF"
- Power Up Timer enable bit : add a 72ms delay when the PIC is turned on. Not needed here: select "OFF"
- GP3 / MCLR pin function select : the pin 4 of the PIC can be used as a "reset button" (=MLCR), or as a classic GPIO. Here, we do not need a "reset" button, so select "OFF" to use it as a classic GPIO.
- Brown-out Detect Enable bit : the "Brown Out" circuit is a simple comparator circuit that checks that the voltage supplied to the PIC is not too low. It avoids memory corruption issues if the PIC is undersupplied. However, the PIC will draw more current. As we do not use the internal memory here, select the "OFF" option.
- Code protection bit : do you want your code to be visible by others or no? If you want to protect your code (for a commercial pedal for instance), you can select "ON". Here, however, as the code is public on my blog, no need to protect it so you can select "OFF" :)
- Data code protection bit : PICs have a small internal memory called EEPROM. If you want, you can prevent people from reading what is in it by activating this option. Here, we do not even use the EEPROM so you can select "OFF".
We are nearly done! One last thing: we have to define the internal clock frequency. Here, we will use a 4 MHz freuency. Just add this code under the configurations bits you copied before:
// Define oscillator frequency
#define _XTAL_FREQ 4000000
#define _XTAL_FREQ 4000000
The "//" symbol allows you to write some comments in your code, useful in order to remember why you wrote that. I strongly advise you to put as much comment as you need in your code, in order to be perfectly sure that you can understand everything when reading it. It will be easier to reuse it later for other things this way!
There it is! We are done with configuring the PIC. Save everything, and we can code now.
Relay bypass code: sensing the switch and activating the relay
Then, choose the name of the file, and click on "Finish". The file should be placed in the "Source Files" folders:
// Supplementary libraries
#include <stdint.h>
#include <xc.h>
// Include configuration bits
#include "header.h"
#include <stdint.h>
#include <xc.h>
// Include configuration bits
#include "header.h"
You should have something like this now:
We can start now to code (finally!):
- when the switch is pressed, we have to know the state of the pedal, and change it: if the pedal is off, we have to turn it on and vice versa.
- when the pedal is on, we have to activate the relay and to light up the LED.
void main(void) {
}
}
First, we have to create a variable that will define the current state of the pedal. Here, I 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 "{}":
uint8_t state; // variable that will define the pedal's state: on or off
state=0; // pedal is off when starting
state=0; // pedal is off when starting
The first line of code create the "state" variable that is an unsigned integer = positive integer ("u" = unsigned, "int" = integer). Do not forget the semicolon at the end of every instruction!
As you on the above examples, you can add comments in your code with the "//" symbol. Do it often in order to be sure that you understand clearly every part of your code!
We have now to write some instructions to correctly initialize the PIC, and to tell it what things it should use or not. Here, as we use only digital GPIOs, we do not need the DAC and ADC converters. We are going to inactivate the comparator as well (it is a circuit that can compare the voltages between two pins of the IC). To do that, we write this:
ANSEL = 0; // no analog GPIO
CMCON = 0x07; // comparator off
ADCON0 = 0; // ADC and DAC converters off
Lets define the nature of each GPIOs: we are going to tell the PIC which ones are inputs and which ones are outputs. Here, we need the GPIOs 0, 4 and 5 to be outputs, and the GPIO 1 to be an input:
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
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
Ok! The PIC is ready to start now! We are going to place every other instructions in a while(1) loop. The "while(1)" loop is a loop that will go on forever as the PIC is on. The microcontroller will execute every instruction from the top to the bottom. When it arrives to the end of the loop, it will start again from the top. Here is a small scheme to explain that:
Here, there is no condition for the loop, as we wrote while(1) so the loop goes on forever. But we could have added a condition like while(state == 1) for instance and the loop would have only looped while the state of the pedal is "on".
Here, the PIC is going to check continuously the state of the switch. To do that, we add a "if" statement. If the switch is pressed, the voltage of the GPIO 1 will be 0V (the switch connects the pin to ground). We have to write:
while(1) {
if(GP1 == 0) { // if the switch is pressed
}
}
if(GP1 == 0) { // if the switch is pressed
}
}
In human language, that will be something like "if the GPIO 1 voltage is low (= if the switch is pressed), then execute every instruction between the braces". Beware, do not forget the two "equal" signs in the "if" statement (GP1 == 0)!
OK, so if the switch is pressed, we have to change the state of the pedal. So if the pedal is on, we turn it off, and vice versa. We can use two "if" statements as well:
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
}
}
}
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:
We wait for the bounce period to be over (it is really short), and check that the switch is still on. To do that, we wait 15 milliseconds, then check that the switch is still on. To do that, we will use the __delay_ms() function, and then a if statement to see whether the switch is still pressed. This is why we had to configure the oscillator in the configuration bits!
void main(void) {
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);
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);
There it is for debouncing!. We add 10 ms of waiting at the end of the loop. You think that we are done? Hell, no!
If you leave the code like this, if you keep your foot on the switch, the state will change really quickly from on to off! Pretty annoying... So, we have to add another "if" statement, to change the state of the pedal when the switch is released only! Before checking, we wait another 200ms (time to release the switch)
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);
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);
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)
OK, now that the pedal correctly changes its state when we press the switch, we have to specify to the microcontroller what it should do when the pedal is on or off. This part is easier. We will use a "if" statement: it checks the state of the pedal, and adjust the states of the outputs (activate or not the relay, turn the LED on or not). Write this part before the end of the while(1) loop:
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 each GPIO
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 each GPIO
We add 10 ms of waiting time in the end so the PIC have time to change the state of the GPIOs: it computes quicker than changing voltages on its pins sometimes! Do not be afraid, 10 ms is really really short, and there is no way you can "feel" it while playing!
There it is! We are done !
Here is the full code:
#include <stdio.h>
#include <stdlib.h>
#include <stdint>
#include <xc.h>
#include "header.h" // Include the header (configuration bits)
void main(void) { // main loop
ANSEL = 0; // no analog GPIO
CMCON = 0x07; // comparator off
ADCON0 = 0; // ADC and DAC converters off
TRISIO4 = 0;
TRISIO5 = 0;
TRISIO1 = 1; // GPIO 1 is an input (1 like "Input")
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
#include <stdlib.h>
#include <stdint>
#include <xc.h>
#include "header.h" // Include the header (configuration bits)
void main(void) { // main loop
ANSEL = 0; // no analog GPIO
CMCON = 0x07; // comparator off
ADCON0 = 0; // ADC and DAC converters off
uint8_t state; // variable that will define the pedal's state: on or off
state=0;
TRISIO0 = 0; // GPIO 0 is an output ("0" like "Output")state=0;
TRISIO4 = 0;
TRISIO5 = 0;
TRISIO1 = 1; // GPIO 1 is an input (1 like "Input")
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
GP4=0;
GP0=1; // light up the LED
}
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 each GPIO
__delay_ms(10); // we wait for the PIC to change the state of each GPIO
}
}
Ok, so lets burn it in the PIC now! First, in MPLab X, click on "Build Main Project" (hammer icon):
Then, open the PicKit 2 program, and have the PIC detected (cf beginning of this tutorial). You can then load the "hex" program (= hexadecimal, the only thing the PIC can understant) by clicking on "File", then "Import Hex". The compiled file is in the "MPLABXProjects" folder, then "Relay Bypass.X" folder (name of your project), then "dist", "default", and "production" folders:
Your PIC has your program loaded in it!
Check on breadboard that it works:
On my side, I added a second switch to choose between a classic activation, or "hold". To do that, I used a second SPST switch that will define is the mode is "hold" or "permanent". I used GPIO 2 (pin number 5) as an input to sense the state of this switch.
I added another variable called "temporary" that will define if the activation is classic or in "hold" mode. I let you think a bit about it, it is a bit more complex than the above code, but you should be able to figure it out! If you want, I will post the source code one of these days :)
There it is! Your first PIC project! As you saw, it is a lot of work to get it working. It is not very complex (especially if you are already a bit familiar with coding), but doing everything right is quite long.
PICs can be used for many many different applications. For instance, you can combine them with digital potentiometers that can replace classic potentiometers, and save your presets or have a tap tempo for time-based effects. Many possibilities! Once you have done the relay bypass, you can imagine a lot of different uses for PIC in guitar pedals!
If you have any questions or comment, post a comment and I will reply shortly :)
If this post was useful, thank me by liking the Coda Effects Facebook page! Thank you!
To go further
Explanations about why you should use relay bypass instead of 3PDT bypass (Ramble FX)
Datasheet of the PIC12F675 (132 pages pdf, good luck reading that haha!)
Good tutorial in order to start with the PIC12F675 (blinking a LED)
Video tutorial about GPIOs, very good for beginners
Video introduction about PICs and how they work
Good post about relay bypass on stompville
Another post about Relay Bypass by THCustom
44 Comment
Great post! Thanks for sharing.
Answerbeside Dano BeavisAudio, you're one of my four horsemen favorite stompboxes builder and blogger
AnswerGood stuff!
a great contribution. I'm tired of all those noisy 3PDT.
AnswerDo you think in a round of selling this?
regards
Its killing me... I've looked over this a thousand times and I just can't find my bug... I can get it to initialize in state 0, and can get it to change to state 1, but for some reason, it's not switching back.
AnswerAny suggestions?
well, I debugged the code and got it to switch properly, but there's a terrible high pitched squeal in the bypass mode, and I can hear the processor chirping along every so often..
AnswerThank you very much :) I was really sad when I discovered that the Beavis audio website went down... I hope it will be back soon !
AnswerHello! Relay bypass is more reliable than 3PDT, however it is still quite noisy with high gain pedals due to the mechanical nature of the relay. I am currently working on a "noise-pop-free" version that I will include on all my pedals and maybe sell around.
AnswerWaiting for parts but it should be ready soon. I will post a blog post about it soon
Hang in there! Coding can be really frustrating, but it is always logical! Take your time, maybe leave the build on a side of your bench for a few days and come back to it with a clearer mind, always worked for me :)
AnswerNice ! This kind of high pitch must come from a poorly regulated power supply. Add an electrolytic capacitor to stabilize it, should do the trick
AnswerThis might be a stupid question, this is all brand new to me. Is the PICkit2 only for Windows machines? Thanks in advance :)
AnswerThe PicKit2 and MPLab are both available for Mac, even Linux :) So no worries
AnswerIn picture I see LM78L05 but what is that other transistor? Its not in schematic?
AnswerThere is only one "transistor" in the picture, which is the voltage regulator
Answerwell I have the same problem... why is this...? and how did you solve it...?
AnswerApparently they are a few typos in the code that I have to correct, I will do it very soon.
AnswerFor instance, line 3 should be
"include " (I forgot to add the .h)
Also, in the if statements following the "ifGP1 == 1) {".
There are 2 "if" statements. someone reported me that if you change the second "if" to an "else", it solves it
Nice.. I will try these changes soon. Thank you for the project and for the reply...!
AnswerVery well explained! Thanks so much for sharing it with us :)
AnswerVery well explained! Thanks so much for sharing it with us :)
AnswerWhen I click Read in a PICkit2 software, I get an error: Unsupported Part (ID=3FE0). What could be the problem?
AnswerHonestly, I do not know... I have never experienced this issue...
AnswerExcellent article, thank you for breaking it down in layman's terms. Quick question...I cannot find the Takamisawa NA05W-K in the US, only the Panasonic. Can I use the Panasonic or do you have a recommendation for another relay? Thanks!
AnswerHi, great post! I want to try and build it, do you have a PCB transfer?
AnswerHello,
AnswerI do not have a PCB transfer, but there is one on PCB Effects layouts: http://effectslayouts.blogspot.fr/2016/11/pic-relay-bypass.html
It should work fine!
I am currently waiting for a batch of PCBs that should be available soon as well.
Suggestion. The PIC12675 has an internal weak pull-up resistor on all GPIO except GPIO3. So, you can save some space and leave out R1 and use:
AnswerOPTION_REG = 0b01010001;
WPU = 0b0000010;
Hi! I'm having some problems with this lines:
AnswerTRISIO0 = 0; // pin 7 is an output (0 like "Output")
TRISIO4 = 0;
TRISIO5 = 0;
TRISIO1 = 1; // pin 6 is an input (1 as "Input")
MPLAB says: "Unable to resolve identifier TRISIO0, etc" This message is displayed for each line where TRISIOX is written.
How can I solve it?
First of all... Thanks Benoit for this article and your blog. Amazing!!!
AnswerFor everyone who wants to try it. Dont replace the second IF with an ELSE. Put the ELSE just in front of the IF. Thats it...
if(state == 1) { // if the effect is on
state=0; // ...turn it off
}
ELSE if(state == 0) { // if the pedal is off
state=1; // ...turn if on
Absolutely fantastic post. Very detailed and extremely well written, thanks so much for this, truly!
AnswerIf anyone tries to copy the entire code and use it there will be a slight problem, the first time you press the switch the LED will come on, but when you press it again the LED won't go off. You have to make a little adjustment to the code to make it work 100%.
In the while loop after the 200ms delay, make sure the "if" statement next to //if the pedal is off is actually an "else if" statement. That should make the code work flawlessly.
Thank you! Please note that I have updated the code since then, it is now working when pressing the switch and not on release for instance.
AnswerHave you tried with the PIC12F509? Seems I can't set the ANSEL, ADC/DAC and TRISIO. I read the documentation that the TRISIO should be TRIS in 12F509. I am guessing it uses different library or needs to be defined. Thoughts are highly appreciated.
AnswerFANTASTIC!!! I am ordering at least one PCB set tonight! i just want to let you know that the build doc says 75L05 and not 78L05. I noticed in the schematic and the etchable one on MBP said 78L05.
AnswerThank you! :) It is just a typo, I use 78L05 indeed.
AnswerHello,
AnswerI did not try it with PIC12F509. Let me know if you tried it with it.
Hello Benoit,
AnswerNo worries. Have you tried with Panasonic TQ2-L - 5V ?
Thanks for this! Got all the parts and will give it a shot this week. What is the LDR for? I have some of those for playing with tremolo effects, but I don't understand their purpose in this schematic. Shouldn't a regular resistor be used just to drop the current to acceptable levels for the LED?
AnswerDon't mean to be daft but why not just use a standard SPST switch and connect the LED in parallel with the relay coil (use 9v relay of course)? Switch closes; led lights and relay closes. I did this decades ago for my EH Soul Preacher using a Radio Shack reed relay and it worked fine for years. I believe I used one resistor for some reason that I don't remember anymore. Drop voltage for the relay perhaps? Drop current for LED? I'm sure you could design a more sophisticated version that would still be a lot simpler and cheaper than the programmable microcontroller?
AnswerContinued: Non-latching relay. Sorry. So yeah it's always drawing some power, as is the LED. With a power supply that shouldn't be a problem, right? In fact Soul Preacher was pretty finicky regarding supply voltage. I ran it at 7v so the compressor circuit acted right, and the relay and LED didn't affect it at all.
AnswerI'm looking for a way to use rehoused commercial pedals like the ibanez 9 series and use the existing physical switch. Would this circuit work with that switch? Also is this the one available for etching over on madbeans site?
AnswerI'm curious as to what lead to you choosing to use a PIC device instead of an AVR device? lower idle power consumption? lower cost? preference based on familiarity/experience?
AnswerHello thanks for all the hard work you do putting all this together and on the intervenes! Can I use an arduino to program the pic? I'm new to this but I have one and all the parts to build this . Do you know where I can find info to do this programming to the pic with my arduino?
AnswerHey, man.. First of all, congrats for your page!
AnswerI improved your code to use external interrupt and it's working like a charm.
If you have some interest about it, please contact me, I'd be glad to share it with you!
Best regards.
Augusto Hoffmann, I've also been thinking of using interrupt instead but with such a simple loop does it really make any difference? Just wondering if you've found any advantage.
AnswerI'm new to this programming/pic thing but want to try it out. Can I ask what you mean by "external interrupt"?
Answer