Delay Pedal

10 years 6 months ago - 9 years 1 month ago #8 by JR
Delay Pedal was created by JR

Rendering Error in layout Message/Item: array_keys(): Argument #1 ($array) must be of type array, null given. Please enable debug mode for more information.

Please Log in to join the conversation.

10 years 6 months ago - 9 years 1 month ago #9 by JR
Replied by JR on topic Delay Pedal

Rendering Error in layout Message/Item: array_keys(): Argument #1 ($array) must be of type array, null given. Please enable debug mode for more information.

Please Log in to join the conversation.

9 years 5 months ago - 9 years 5 months ago #178 by Ray
Replied by Ray on topic Delay Pedal
Some folks asked for a better explanation of the delay.ino code, so I hope it helps:
Starting from the beginning...

- The idea is to buffer the guitar signal 450 ms. Keeping a sample rate of 44.1 KHz (which is one sample every 22.6us) we will need 20000 samples to be stored (450000/22us= 200000 samples). This is why MAX_DELAY=20000.

- The Mix Potentiometer should be ON (down) in order to mix the original and the delayed signal and make them sound at the same time.

- Main Loop: Both ADCs and potentiometers are read.

- TC4_Handler (sampling function): This function is executed every 22.6us. It will save the current read signal in a buffer.
This is maybe the most tricky part, but is a very easy idea,
It also adjust the volume and writes de DACs.

- The main idea can be resumed in this image, with the key points (1,2,3) highlighted in the code below:





Variable Definitions:

int in_ADC0, in_ADC1; //variables for 2 ADCs values (ADC0, ADC1)
int POT0, POT1, POT2, out_DAC0, out_DAC1; //variables for 3 pots (ADC8, ADC9, ADC10)
int LED = 3;
int FOOTSWITCH = 7;
int TOGGLE = 2;

#define MAX_DELAY 20000
uint16_t sDelayBuffer0[MAX_DELAY];
uint16_t sDelayBuffer1[MAX_DELAY];
unsigned int DelayCounter = 0;
unsigned int Delay_Depth = MAX_DELAY;



Setup loop, it sets the sampling frequency at 44.1KHz (1/44KHz=22.6us). It also fixes all the general parameters like the ADC and DAC configuration.

void setup()
{
//turn on the timer clock in the power management controller
pmc_set_writeprotect(false);
pmc_enable_periph_clk(ID_TC4);

//we want wavesel 01 with RC
TC_Configure(TC1,1,TC_CMR_WAVE|TC_CMR_WAVSEL_UP_RC|TC_CMR_TCCLKS_TIMER_CLOCK2);
TC_SetRC(TC1, 1, 238); // sets <> 44.1 Khz interrupt rate
TC_Start(TC1, 1);

// enable timer interrupts on the timer
TC1->TC_CHANNEL[1].TC_IER=TC_IER_CPCS;
TC1->TC_CHANNEL[1].TC_IDR=~TC_IER_CPCS;

//Enable the interrupt in the nested vector interrupt controller
//TC4_IRQn where 4 is the timer number * timer channels (3) + the channel number
//(=(1*3)+1) for timer1 channel1
NVIC_EnableIRQ(TC4_IRQn);

//ADC Configuration
ADC->ADC_MR |= 0x80; // DAC in free running mode.
ADC->ADC_CR=2; // Starts ADC conversion.
ADC->ADC_CHER=0x1CC0; // Enable ADC channels 0,1,8,9 and 10

//DAC Configuration
analogWrite(DAC0,0); // Enables DAC0
analogWrite(DAC1,0); // Enables DAC0
}



The main loop, just read the inputs (guitar signal ADCs, and potentiometer ADCs )

void loop()
{
//Read the ADCs
while((ADC->ADC_ISR & 0x1CC0)!=0x1CC0);// wait for ADC 0, 1, 8, 9, 10 conversion complete.
in_ADC0=ADC->ADC_CDR[7]; // read data from ADC0
in_ADC1=ADC->ADC_CDR[6]; // read data from ADC1
POT0=ADC->ADC_CDR[10]; // read data from ADC8
POT1=ADC->ADC_CDR[11]; // read data from ADC9
POT2=ADC->ADC_CDR[12]; // read data from ADC10
}


The interrupt function at 44.1KHz rate (every 22.6us)
void TC4_Handler()
{
//Save in the buffer the current guitar signal, to be stored Store current readings
(1) sDelayBuffer0[DelayCounter] = in_ADC0;
(1) sDelayBuffer1[DelayCounter] = in_ADC1;

//Adjust Delay Depth based in pot2 position, this part is tricky, POT0>>2 is the same as writing POT0/2. To the values that this potentiometer produces (from 0 to 2097) are re-maped in values between 1 and 20000. There is more info about the map function in the Arduino website.
Basically Delay_Depth value will go from 1 to 20000 depending on POT0 position (i.e if POT0 is at the middle point, Delay_Depth=10000 )


Delay_Depth=map(POT0>>2,0,2097,1,MAX_DELAY);

THIS IS VERY IMPORTANT: We use an index to save the data in the buffer, so we increment it, the actual reading will be stored one sample before the index position.
//--Increse/reset delay counter.

(2)DelayCounter++;
//If we reach the end of the buffer, we reset the counter
if(DelayCounter >= Delay_Depth) DelayCounter = 0;

We write on the DACs the current index buffer sample, which is indeed the one that was stored here 20000 samples before:

(3)out_DAC0 = ((sDelayBuffer0[DelayCounter]));
(3)out_DAC1 = ((sDelayBuffer1[DelayCounter]));

//Add volume feature - this is easy.
out_DAC0=map(out_DAC0,0,4095,1,POT2);
out_DAC1=map(out_DAC1,0,4095,1,POT2);

//Write the DACs
dacc_set_channel_selection(DACC_INTERFACE, 0); //select DAC channel 0
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
dacc_set_channel_selection(DACC_INTERFACE, 1); //select DAC channel 1
dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);//write on DAC

//Clear status allowing the interrupt to be fired again.
TC_GetStatus(TC1, 1);
}
Attachments:

Please Log in to join the conversation.

9 years 1 month ago #274 by JohnReagan
Replied by JohnReagan on topic Delay Pedal

Rendering Error in layout Message/Item: array_keys(): Argument #1 ($array) must be of type array, null given. Please enable debug mode for more information.

Please Log in to join the conversation.

ElectroSmash - Delay Pedal - Electro Smash
9 years 1 month ago #275 by Ray
Replied by Ray on topic Delay Pedal

Rendering Error in layout Message/Item: array_keys(): Argument #1 ($array) must be of type array, null given. Please enable debug mode for more information.

Please Log in to join the conversation.

9 years 5 hours ago #299 by mtytgat
Replied by mtytgat on topic Delay Pedal

Rendering Error in layout Message/Item: array_keys(): Argument #1 ($array) must be of type array, null given. Please enable debug mode for more information.

Please Log in to join the conversation.

8 years 11 months ago - 8 years 11 months ago #301 by Ray
Replied by Ray on topic Delay Pedal

Rendering Error in layout Message/Item: array_keys(): Argument #1 ($array) must be of type array, null given. Please enable debug mode for more information.

Please Log in to join the conversation.

Time to create page: 0.093 seconds

Follow us

You can also follow us on:

facebook   google   instagram

pinterest   youtube   twitter