Welcome, Guest
Username: Password: Remember me

TOPIC: Delay Effect Guitar Pedal.

Delay Effect Guitar Pedal. 1 year 2 weeks ago #467

  • Ray
  • Ray's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 280
  • Thank you received: 60
  • Karma: 10
The delay effect in Arduno UNO is limited by the amount of RAM memory. With 2KB or RAM we can store up to 2048 samples of 8 bits each.

With the default parameters, the PWM signal is generated at 33KHz, that means that every sample is generated every 30us (1/33KHz) so with 2KB of ram we have a delay of:
2048 x 30us = 62ms

62ms is not a lot but enough to be noticeable, more like a "doubler" effect, check it out:

pedalshield_uno_delay.ino:
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs previous works.
// pedalshield_uno_delay.ino reads the ADC, saves it into the DelayBuffer[] array and plays it into the PWM output.
//  pressing the pushbutton_1 or 2 makes the delay longer or shorter
 
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4

//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel

//other variables
int input, vol_variable=512;
int counter=0;
unsigned int ADC_low, ADC_high;
 
#define MAX_DELAY 2000
byte DelayBuffer[MAX_DELAY];
unsigned int DelayCounter = 0;
unsigned int Delay_Depth = MAX_DELAY;
 
void setup() {
  //setup IO
  pinMode(FOOTSWITCH, INPUT_PULLUP);
  pinMode(TOGGLE, INPUT_PULLUP);
  pinMode(PUSHBUTTON_1, INPUT_PULLUP);
  pinMode(PUSHBUTTON_2, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
 
  // 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() 
{
    //Turn on the LED if the effect is ON.
  if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH); 
     else  digitalWrite(LED, LOW);
  //nothing here, all happens in the Timer 1 interruption.
}
 
ISR(TIMER1_CAPT_vect) 
{
  // get ADC data
  ADC_low = 0; // ADC_low always 0 to save space
  ADC_high = ADCH;
 
  //store the high bit only for 
  DelayBuffer[DelayCounter] = ADC_high;
 
counter++; //to save resources, the pushbuttons are checked every 100 times.
if(counter==100)
{ 
counter=0;
if (!digitalRead(PUSHBUTTON_1)) {
  if (Delay_Depth<MAX_DELAY)Delay_Depth=Delay_Depth+1; //increase the vol
    digitalWrite(LED, LOW); //blinks the led
    }
 
    if (!digitalRead(PUSHBUTTON_2)) {
  if (Delay_Depth>0)Delay_Depth=Delay_Depth-1; //decrease vol
  digitalWrite(LED, LOW); //blinks the led
    }
}
 
//Increse/reset delay counter.   
  DelayCounter++;
  if(DelayCounter >= Delay_Depth) DelayCounter = 0; 
 
  input = (((DelayBuffer[DelayCounter] << 8) | ADC_low) + 0x8000)+(((ADC_high << 8) | ADC_low) + 0x8000); // make a signed 16b value
 
  //write the PWM signal
  OCR1AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
  OCR1BL = input; // send out low byte
 
}


File Attachment:

File Name: pedalshield_uno_delay.zip
File Size: 1 KB
Last Edit: 1 year 2 weeks ago by Ray.
The administrator has disabled public write access.

Delay Effect Guitar Pedal. 2 months 1 week ago #724

  • Kosak
  • Kosak's Avatar
  • OFFLINE
  • New Member
  • Posts: 4
  • Karma: 0
Hi,
could you provide little insight, algorithm, or description on how this effect really work?
The administrator has disabled public write access.

Delay Effect Guitar Pedal. 2 months 1 week ago #725

  • Ray
  • Ray's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 280
  • Thank you received: 60
  • Karma: 10
Hi Kosak, we wrote an explanation how how this code works for the DUE version of the pedal. The code is a bit different but the idea is basically the same, have a look at it:
www.electrosmash.com/forum/software-peda...ld/5-delay-pedal#178
The administrator has disabled public write access.
Time to create page: 0.357 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio