"expected unqualified-id before string constant" error for multi-effects guitar pedal

Currently doing a Project with the Arduino UNO where I'm making a multi effects guitar pedal, the menu works fine on its own as does the code (based off of Open Music Labs Clean pass through codehttp://wiki.openmusiclabs.com/wiki/PWMDAC). For some reason when I try to put it in the switch case structure, it keeps on giving me a "expected unqualified-id before string constant" error for the "ISR(TIMER1_CAPT_vect) " line. I've seen other people have similar problems and I've tried everything I can think off to fix it but still the same error, does anyone know how to fix this?

const int buttonPin_up = 7;
const int buttonPin_down = 8;

int selection = 0; // value used for selection

#define PWM_FREQ 0x00FF // pwm frequency 
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // number of pwms

void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(buttonPin_up, INPUT);
  pinMode(buttonPin_down, INPUT);

// setup ADC
  ADMUX = 0x60; // left adjust, adc0, internal vcc
  ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
  ADCSRB = 0x07; // t1 capture for trigger
  DIDR0 = 0x01; // turn off digital inputs for adc0

 // setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs

sei(); // turn on interrupts - not really necessary with arduino

}

void loop() {

  if (digitalRead(buttonPin_up) == HIGH) {
  selection += 1;
  delay(750);
}
 if (digitalRead(buttonPin_down) == HIGH) {
  selection -= 1;
  delay(750);
}
  if (selection > 4) {
  selection = 0;
}
  if (selection < 0) {
  selection = 4;
}
 switch (selection) {

case 0:
  digitalWrite(2, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);

   ISR(TIMER1_CAPT_vect) {

    // get ADC data
    unsigned int temp1 = ADCL;
    unsigned int temp2 = ADCH;


    // output high byte on OC1A
    OCR1AH = temp2 >> 8; // takes top 8 bits
    OCR1AL = temp2; // takes bottom 8 bits

    // output low byte on OC1B
    OCR1BH = temp1 >> 8;
    OCR1BL = temp1;
  }
  
  break;

case 1:
  digitalWrite(3, HIGH);
  digitalWrite(2, LOW);
  digitalWrite(6, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  break;

case 2:
  digitalWrite(4, HIGH);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(6, LOW);
  digitalWrite(5, LOW);
  break;

case 3:
  digitalWrite(5, HIGH);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(6, LOW);
  break;

case 4:
  digitalWrite(6, HIGH);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  break;

 }

I'm not really certain what you are doing, but it compiles and may work as you intend

  1. move the ISR out of case 0
  2. remove the capture interrupt enable from setup()
  3. enable the capture interrupt in case 0
const int buttonPin_up = 7;
const int buttonPin_down = 8;

int selection = 0; // value used for selection

#define PWM_FREQ 0x00FF // pwm frequency
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // number of pwms

ISR(TIMER1_CAPT_vect) {

  // get ADC data
  unsigned int temp1 = ADCL;
  unsigned int temp2 = ADCH;


  // output high byte on OC1A
  OCR1AH = temp2 >> 8; // takes top 8 bits
  OCR1AL = temp2; // takes bottom 8 bits

  // output low byte on OC1B
  OCR1BH = temp1 >> 8;
  OCR1BL = temp1;
}

void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(buttonPin_up, INPUT);
  pinMode(buttonPin_down, INPUT);

  // setup ADC
  ADMUX = 0x60; // left adjust, adc0, internal vcc
  ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
  ADCSRB = 0x07; // t1 capture for trigger
  DIDR0 = 0x01; // turn off digital inputs for adc0

  // setup PWM
  TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
  TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
  //TIMSK1 = 0x20; // interrupt on capture interrupt
  ICR1H = (PWM_FREQ >> 8);
  ICR1L = (PWM_FREQ & 0xff);
  DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs

  sei(); // turn on interrupts - not really necessary with arduino

}

void loop() {

  if (digitalRead(buttonPin_up) == HIGH) {
    selection += 1;
    delay(750);
  }
  if (digitalRead(buttonPin_down) == HIGH) {
    selection -= 1;
    delay(750);
  }
  if (selection > 4) {
    selection = 0;
  }
  if (selection < 0) {
    selection = 4;
  }
  switch (selection) {

    case 0:
      digitalWrite(2, HIGH);
      digitalWrite(6, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);

      TIMSK1 = 0x20; // enable interrupt on capture interrupt

      /*
        ISR(TIMER1_CAPT_vect) {

        // get ADC data
        unsigned int temp1 = ADCL;
        unsigned int temp2 = ADCH;


        // output high byte on OC1A
        OCR1AH = temp2 >> 8; // takes top 8 bits
        OCR1AL = temp2; // takes bottom 8 bits

        // output low byte on OC1B
        OCR1BH = temp1 >> 8;
        OCR1BL = temp1;
        }
      */

      break;

    case 1:
      digitalWrite(3, HIGH);
      digitalWrite(2, LOW);
      digitalWrite(6, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      break;

    case 2:
      digitalWrite(4, HIGH);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(6, LOW);
      digitalWrite(5, LOW);
      break;

    case 3:
      digitalWrite(5, HIGH);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(6, LOW);
      break;

    case 4:
      digitalWrite(6, HIGH);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      break;
  }
}

Hi cattledog thanks for the reply I'll try it out now!

Anyone can tell me why this and presumably the original did not simply use analogRead(), because I don’t see why not.

TIA

a7

Hi Cattledog, tired out the code and was getting signal pass through but sadly it wasn't just in case 0 (wanted it to only happen there, other cases would contain code for different effects etc) but thanks for helping :slight_smile:

Hi alto, I couldn't use analog read and digital write for the sampling and PWM as they were too slow, but there was a work around where you can alter the timer registers on the atmega328p and use one of the timers for a higher PWM rate. Heres a link that briefly goes over it it.

The open music Labs link I posted in the original question shows why this is good for music applications as well but will attach again. If you have any other questions ill try answer as best i can :slight_smile:

http://wiki.openmusiclabs.com/wiki/PWMDAC

edit: I also needed a higher bit rate than the standard outputs so A dual pwm setup was used where pin9 contained the highest 8 bytes of data and pin10 contains the lowest 8 bytes, hence the jumble of other code ( Open music Labs explains it in more detail but just thought id add to save some searching)

1 Like

Disable the pass through in the cases where you don't want it.
Set and clear TIMSK1 in whatever cases make sense.

Thanks Cattledog ill try this now :slight_smile:

Hi cattle dog, implemented your ideas and re-jigged some things an managed to get code that compiles, even added a distortion effect to case 1. Unfortunately can't test at the moment as I only have access to the proper equipment during the day but going to wake up early to test it out! My one concern with it is again with the ISR(TIMER1_CAPT_vect) line of code as I've left the brackets empty, so not sure if it will just do nothing and that I'll be back at square one

const int buttonPin_up = 7;
const int buttonPin_down = 8;

int selection = 0; // value used for selection

#define PWM_FREQ 0x00FF // pwm frequency
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // number of pwms

ISR(TIMER1_CAPT_vect) {
}

void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(buttonPin_up, INPUT);
  pinMode(buttonPin_down, INPUT);

  // setup ADC
  ADMUX = 0x60; // left adjust, adc0, internal vcc
  ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
  ADCSRB = 0x07; // t1 capture for trigger
  DIDR0 = 0x01; // turn off digital inputs for adc0

  // setup PWM
  TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
  TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
  TIMSK1 = 0x20; // interrupt on capture interrupt
  ICR1H = (PWM_FREQ >> 8);
  ICR1L = (PWM_FREQ & 0xff);
  DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs

  sei(); // turn on interrupts - not really necessary with arduino

}

void loop() {

  if (digitalRead(buttonPin_up) == HIGH) {
    selection += 1;
    delay(750);
  }
  if (digitalRead(buttonPin_down) == HIGH) {
    selection -= 1;
    delay(750);
  }
  if (selection > 4) {
    selection = 0;
  }
  if (selection < 0) {
    selection = 4;
  }
  switch (selection) {

    case 0:
      digitalWrite(2, HIGH);
      digitalWrite(6, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);

      TIMSK1 = 0x20; // enable interrupt on capture interrupt
      // get ADC data
      unsigned int temp1 = ADCL;
      unsigned int temp2 = ADCH;

      // output high byte on OC1A
      OCR1AH = temp2 >> 8; // takes top 8 bits
      OCR1AL = temp2; // takes bottom 8 bits

      // output low byte on OC1B
      OCR1BH = temp1 >> 8;
      OCR1BL = temp1;


      break;

    case 1:
      digitalWrite(3, HIGH);
      digitalWrite(2, LOW);
      digitalWrite(6, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);

      TIMSK1 = 0x20;
      int input, dist_thrsh = 30000;
      unsigned int ADC_low, ADC_high;
      // get ADC data
      ADC_low = ADCL; // you need to fetch the low byte first
      ADC_high = ADCH;
      //construct the input sumple summing the ADC low and high byte.
      input = ((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value

      //the input signal is 16bits (values from -32768 to +32768
      //the valueif(input>distortion_threshold) input=distortion_threshold; is clipped to the distortion_threshold value
      if (input > dist_thrsh) input = dist_thrsh;

      //write the PWM signal
      OCR1AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
      OCR1BL = input; // send out low byte

      break;

    case 2:
      digitalWrite(4, HIGH);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(6, LOW);
      digitalWrite(5, LOW);
      break;

    case 3:
      digitalWrite(5, HIGH);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(6, LOW);
      break;

    case 4:
      digitalWrite(6, HIGH);
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      break;
  }
}

Yes, with an empty interrupt vector, nothing will happen when the interrupt is triggered.

What triggers the interrupt, and what do you want to happen when it is triggered?

Hi cattledog, sorry for my late reply again. Ended up having to submit the code I had already but going to work on this in the future, thanks for all your help!