Welcome, Guest
Username: Password: Remember me

TOPIC: Clean-Transparent Guitar Pedal.

Clean-Transparent Guitar Pedal. 1 year 6 months ago #457

  • Ray
  • Ray's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 363
  • Thank you received: 79
  • Karma: 16
The code below is the simplest code you can start with to understand the process of "reading" and writing "audio".
The guitar signal is read using the ADC0 and then is played back again using a PWM signal (PWM9 and PWM10 pins).

clean_pedalshield_uno.ino:
// CC-by-www.Electrosmash.com
// Based on OpenMusicLabs previous works.
// clean_pedalshield_uno.ino reads the ADC and plays it back into the PWM output
 
//defining hardware 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;
byte ADC_low, ADC_high;
 
void setup() {
  //setup IO
  pinMode(FOOTSWITCH, 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 else here, all happens in the Timer 1 interruption.
}
 
ISR(TIMER1_CAPT_vect) 
{
  // 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
 
 
  //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_clean.zip
File Size: 1 KB
Last Edit: 1 year 5 months ago by Ray.
The administrator has disabled public write access.

Clean-Transparent Guitar Pedal. 10 months 2 days ago #665

  • PotentPollen
  • PotentPollen's Avatar
  • OFFLINE
  • New Member
  • Posts: 4
  • Thank you received: 2
  • Karma: 2
Hello! I'm having a strange issue with the audio output, and would appreciate any advice possible!

So everything seems to be working mostly fine. I have very nice audio coming through the Amp, except quietly in the background (maybe 1/5 of the volume of the clean audio) there's the same guitar signal but heavily distorted. I tried adjusting the variable resistor and it might have slightly changed how loud or quiet this faint distorted signal but it's still there. Isn't all the sound output generated at the PWM? How could some of my audio output be perfect and also some of it be distorted? Also the sustain is strange, when a note rings for very long it sort of gets cut out abruptly (is this related to the capacitors RC time?). Thanks in advance for any help!

Edit: The quieter signal sounds more like fuzz if that's useful. Also, I don't have an oscilloscope at my disposal. If I did troubleshooting this would be far easier.
Last Edit: 10 months 2 days ago by PotentPollen.
The administrator has disabled public write access.
The following user(s) said Thank You: Ray

Clean-Transparent Guitar Pedal. 10 months 2 days ago #666

  • Ray
  • Ray's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 363
  • Thank you received: 79
  • Karma: 16
Hi, you are possibly overloading the input of your amp, some guitar players use this trick to play nice cracking tones. Every amplifier its different but if yours gets easily distorted you can place a 4K7 resistor in parallel with the C7 capacitor:
www.electrosmash.com/images/tech/pedalsh...ld-uno-schematic.png
It will reduce to output signal and your system will improve. you can solder the resistor on the bottom side of the PCB so all will look neat.
Keep us updated with your progress!
The administrator has disabled public write access.

Clean-Transparent Guitar Pedal. 8 months 3 weeks ago #686

  • PotentPollen
  • PotentPollen's Avatar
  • OFFLINE
  • New Member
  • Posts: 4
  • Thank you received: 2
  • Karma: 2
Thanks for the reply! I actually just rebuilt the whole project and fiddled with RV1 a bit (opened it up a bit) and now the sound is clean and working fine.
The administrator has disabled public write access.
The following user(s) said Thank You: Ray

Clean-Transparent Guitar Pedal. 8 months 3 weeks ago #687

  • Ray
  • Ray's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 363
  • Thank you received: 79
  • Karma: 16
Nice to hear that ! :woohoo:
The administrator has disabled public write access.
Time to create page: 0.361 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio