Anyone successfully tried the Coda Effects relay switching?

Stompboxes circuits published in magazines, books or on DIY electronics websites.
User avatar
electrosonic
Breadboard Brother
Posts: 127
Joined: 28 Nov 2008, 17:53
Location: Vancouver, BC
Has thanked: 24 times
Been thanked: 13 times

Post by electrosonic »

I would put the the uC on a breadboard and hook up LEDs / resistors to the output pins. Then you can easily see what's going on

I would also manually connect the relay to +5v and ground and listen for a click as it changes state. Then swap leads and listen for it to go to the other state.

Andrew

oooscasianooo
Posts: 7
Joined: 17 Sep 2013, 05:35

Post by oooscasianooo »

Hope this helps someone. On the last post of page 1 I posted issues with my build. Turns out my relays were no good! I didn't think to suspect them since I ordered them from Jameco on ebay, which I'm pretty sure is a legitimate electronics store. I ended up on some "verified distributors" page and didn't see Jameco had made it, so I returned those relays.

I ended up ordering relays directly from Mouser and plugged them in as soon as I got them, and it worked great!

Sucks because I was racking my brain trying to figure out if it was an issue with the code or the stripboard layout, but was bad relays.

Anyway, double check everything! hahaha

novoselic
Posts: 2
Joined: 14 Jul 2014, 02:18

Post by novoselic »

Hello!
sorry for ressurecting this old thread, but maybe someone will find it helpful.

I don't like current version with temporary/normal toggle (and button release in temporary mode is not muted while switching), so I wrote new version
No more toggle for temporary mode. If you press button normally (for less then 0.4 sec) - then it's working like normal bypass
If you press and hold button for 0.4 sec then temporary (or latching) mode activates automatically. Status LED starts blinking and pedal will switch to bypass mode on button release.

Code is for Arduino/Attiny13a, but general idea is clear enough to be rewritten back for PIC
Button debounce routine was taken from https://learn.adafruit.com/make-it-switch/debouncing

Code: Select all

const byte relayPin  = 3; //pin2
const byte relay2Pin = 4; //pin3

const byte ledPin    = 2; //pin7
const byte buttonPin = 1; //pin6
const byte mutePin   = 0; //pin5

const char blinkDelta = 3;
const unsigned long debounceDelay = 15;    // the debounce time; increase if the output flickers
const unsigned long latchingDelay = 400;   // delay before activation momentary mode

char blinkValue;
byte state       = 0;  // on-off state of the pedal (1 = on, 0 = off)
byte changeState = 0;  // flag, set it equals 1 to change status of the pedal
byte latching    = 0;  // define the mode of the pedal : classic of latching activation
byte buttonState     = HIGH;  // the current reading from the input pin
byte lastButtonState = HIGH;  // the previous reading from the input pin

// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long time = 0;              // the last time when button was pressed

void setup()  {
  pinMode(buttonPin, INPUT);

  pinMode(ledPin, OUTPUT);
  pinMode(mutePin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(relay2Pin, OUTPUT);

  digitalWrite(ledPin, LOW);   // LED off
  digitalWrite(mutePin, LOW);  // photoFET off
  digitalWrite(relayPin, LOW); // relay off
  digitalWrite(relay2Pin, LOW);// relay off 
} 

inline void updateState() {
  if(state == 0) { // change to on
    digitalWrite(mutePin, HIGH); // photoFET on
    delay(10);
    digitalWrite(ledPin, HIGH); // LED on
    digitalWrite(relayPin, HIGH); // relay on
    delay(20);
    digitalWrite(mutePin, LOW); // photoFET off
    state = 1;
  } 
  else { // change to off
    digitalWrite(mutePin, HIGH); // photoFET on
    delay(10);
    digitalWrite(ledPin, LOW); // LED off
    digitalWrite(relayPin, LOW); // relay off
    delay(20);
    digitalWrite(mutePin, LOW);
    state = 0;
  }
  delay(10);
  changeState=0; // reset changeState
}

void loop()  {
  byte buttonStateChanged = 0;
  // read the state of the switch into a local variable:
  byte reading = digitalRead(buttonPin);

  // check to see if you just pressed the button
  // (i.e. the input went from LOW to HIGH), and you've waited long enough
  // since the last press to ignore any noise:

  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer than the debounce
    // delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;
      buttonStateChanged = 1;

      // button is pressed
      if (buttonState == LOW) {
        //changing state on every press
        changeState = 1;
        //if state was OFF
        if (state == 0) {
          //start counting before latching mode activation
          time = millis();
          latching = 0;
        }
      }
    }
  }

  // if state == ON and button is pressed long enough
  if (latching == 0 && buttonStateChanged == 0 && buttonState == LOW && state == 1 && ((millis() - time) > latchingDelay)) {
    //activating latching mode
    latching = 1;
    blinkValue = 0;
  }

  if (latching == 1 && state == 1) {
    //blinking
    char newValue = blinkValue - blinkDelta;
    if (newValue * blinkValue <=0 ){
      if (newValue>0 ) {
        digitalWrite(ledPin, HIGH);
      } 
      else {
        digitalWrite(ledPin, LOW);
      }
    }
    blinkValue = newValue;

    //button release
    if (buttonStateChanged == 1 && buttonState == HIGH) {
      changeState = 1;
    }
  }

  // save the reading. Next time through the loop, it'll be the lastButtonState:
  lastButtonState = reading;

  // Changing state of the pedal
  if(changeState == 1) {
    updateState();
  } 
  else {
    delay(1);
  }
}

User avatar
mictester
Old Solderhand
Posts: 2916
Joined: 11 Sep 2008, 21:29
my favorite amplifier: Mesa Boogie, Roost Sessionmaster, AC30
Completed builds: Hundreds! Mostly originals, a few clones and lots of modifications.
Location: Somewhat closer to Amsterdam than before!
Has thanked: 27 times
Been thanked: 375 times
Contact:

Post by mictester »

Zokk wrote:Hello

please could you explain why you've removed the freewheel diode on the relay?
Usually this diode is mandatory to protect the relay against feedback voltage.

Thanks.
Because the pins for the coil "swap voltages" when the relay is activated, and "swap back" when it's deactivated. It's NOT a normal relay - it's a bistable relay.
"Why is it humming?" "Because it doesn't know the words!"

User avatar
plush
Resistor Ronker
Posts: 389
Joined: 08 Dec 2015, 10:29
Location: Moscow, Evil Russia
Has thanked: 27 times
Been thanked: 80 times

Post by plush »

mictester wrote:
Zokk wrote:Hello

please could you explain why you've removed the freewheel diode on the relay?
Usually this diode is mandatory to protect the relay against feedback voltage.

Thanks.
Because the pins for the coil "swap voltages" when the relay is activated, and "swap back" when it's deactivated. It's NOT a normal relay - it's a bistable relay.
Nah, it's monostable. And the diode is actually must-have.

novoselic
Posts: 2
Joined: 14 Jul 2014, 02:18

Post by novoselic »

In this case relay is driven directly by MCU which usually have ESD protection diodes on generai IO pins. But to be sure external diode is preferred

Post Reply