Devices & Components
Arduino Nano
Resistor 10k ohm
Resistor 4.75k ohm
Capacitor 100 nF
Resistor 2.21k ohm
Pushbutton Switch, Push On-Push Off
Capacitor 2.7nF
Capacitor 33nF
Pushbutton Switch, Momentary
Resistor 6.8k
Electrolitic Capacitor 2.2uF
Breadboard (generic)
Resistor 100k ohm
Software & Tools
Arduino IDE
Project description
Code
8Bit Digital Delay sketch
c_cpp
Load it to arduino in order to do it work
1/***************************************************************************************************************************** 2 echoTrek - 8Bit Digital Delay / LO-FI Bitcrusher / Reverse Speech DSP Pedal Effects for Guitar, Voice, Synths, etc. 3 Works with Arduino UNO R3 / NANO / PRO MINI - See the schematics for wiring details. By J. CesarSound - ver 1.0 - Jan/2021. 4******************************************************************************************************************************/ 5 6#define audio_in A0 7#define time_selector A3 8 9const unsigned int d_size = 1900; //Delay memory buffer size 10unsigned int val, d_val, d_time; 11int i, j; 12byte count = 2; 13bool rev = 0; 14char delay_data[d_size + 1] = { NULL }; //Delay memory buffer 15char delay_data_1[d_size + 1] = { NULL }; //Delay memory buffer 16 17 18void setup() { 19 pinMode(time_selector, INPUT_PULLUP); 20 DDRD = B00000010; 21 DDRB = B11100000; 22 InitTimer1(); //Set up timer 1 for 16.384kHz 23 setPwmFrequency(5, 1); //function for setting PWM High frequency 62.475kHz on pin D5 24 analogReference(INTERNAL); //Use 1.1v aref voltage. 25 up_time(); 26} 27 28void loop() { 29 if (digitalRead(time_selector) == LOW) { 30 up_time(); 31 PORTB = B11100000; //make pin 13 high and power on the led when pushbutton is pressed 32 while (digitalRead(time_selector) == LOW); 33 } else PORTB = B11000000; //make pin 13 low and power off the led pushbutton is released 34 if (rev) PORTD = B00000000; else PORTD = B00000010; //Reverse speech sampler indication TX Led power on 35} 36 37void sampling() { 38 val = map(analogRead(audio_in), 0, 900, 0, 255); 39 delay_sound(); 40 analogWrite(5, d_val); 41} 42 43void delay_sound() { 44 i = i + 1; if (i > d_time) i = 0; 45 delay_data[i] = val; 46 if (i == d_time) j = 0; 47 delay_data_1[i] = delay_data[i]; 48 j = j + 1; if (j > d_time) j = 0; 49 if (!rev) d_val = delay_data_1[j]; 50 if (rev) d_val = delay_data_1[d_time - j]; 51} 52 53void up_time() { 54 noInterrupts(); 55 count++; 56 if (count > 7) 57 count = 1; 58 delay(20); 59 60 switch (count) { 61 case 1: 62 d_time = 400; rev = 0; //63ms 63 break; 64 case 2: 65 d_time = 700; //110ms 66 break; 67 case 3: 68 d_time = 1000; //158ms 69 break; 70 case 4: 71 d_time = 1300; //205ms 72 break; 73 case 5: 74 d_time = 1600; //253ms 75 break; 76 case 6: 77 d_time = 1900; //300ms 78 break; 79 case 7: 80 d_time = 1500; rev = 1; //Reverse speech 81 break; 82 } interrupts(); 83} 84 85//Set up timer 1 for 16.384kHz (975) 86void InitTimer1() { 87 cli(); //Disable global interrupts 88 TCCR1A = 0; //Reset Timer 1 Counter Control Register A 89 TCCR1B = 0; //Reset Timer 1 Counter Control Register B 90 TCNT1 = 0; //initialize counter value to 0 91 OCR1A = 975; //Set Timer 1 to desired frequency: 16384Hz (16,000,000 / 16384) - 1 = 975 92 //Turn on CTC (clear timer on compare match) mode: 93 TCCR1B |= (1 << WGM12); 94 TCCR1B |= (1 << CS10); //CS10 Prescalar = 1 (no prescalar used); CS11 Prescalar = 8 95 TIMSK1 |= (1 << OCIE1A); //Enable timer interrupt 96 sei(); //Enable interrupts 97} 98 99ISR(TIMER1_COMPA_vect) { 100 sampling(); 101} 102 103//PWM 62.475kHz high frequency DAC for pins 5 & 6 (others are 32k) 104void setPwmFrequency(int pin, int divisor) { 105 byte mode; 106 if (pin == 5 || pin == 6 || pin == 9 || pin == 10) { 107 switch (divisor) { 108 case 1: mode = 0x01; break; 109 case 8: mode = 0x02; break; 110 case 64: mode = 0x03; break; 111 case 256: mode = 0x04; break; 112 case 1024: mode = 0x05; break; 113 default: return; 114 } 115 if (pin == 5 || pin == 6) { 116 TCCR0B = TCCR0B & 0b11111000 | mode; 117 } else { 118 TCCR1B = TCCR1B & 0b11111000 | mode; 119 } 120 } else if (pin == 3 || pin == 11) { 121 switch (divisor) { 122 case 1: mode = 0x01; break; 123 case 8: mode = 0x02; break; 124 case 32: mode = 0x03; break; 125 case 64: mode = 0x04; break; 126 case 128: mode = 0x05; break; 127 case 256: mode = 0x06; break; 128 case 1024: mode = 0x07; break; 129 default: return; 130 } 131 TCCR2B = TCCR2B & 0b11111000 | mode; 132 } 133}
Downloadable files
Schematics wiring
To wire the parts
Schematics wiring
Schematics wiring
To wire the parts
Schematics wiring
Comments
Only logged in users can leave comments