Hello,
I hope no one kills me bc i use an STM32 and ask on the arduino forum. ![]()
But i need a bit of ram, in a small package for this project, so i had to switch to an STM32F103.
The goal is to make a chorus pedal for Guitar.
A chorus effect is generated by mixing a Signal with varying delay(0-30ms) to the original one.
Old effects used BBD chips, modern are completely digital.
I just wanna make the delay digital, the rest of the pedal will be analog.
So the code wont be that complex:
Analog in (12bit > 40khz smapling freq)
Delay from 0-100ms controlled via analog Input
Analog out (PWM or R2R)
I already tried it with a blue-pill board, programmed via Arduino.
My frankenstein-code works somehow, but im not happy with it.
Im a lousy programmer, who copy pastes a lot. :-[
I used 8bit timer PWM (~280khz) as DAC.
The thing is kinda noisy. especially with low delay.
Even after filtering.
And it makes strange noises when i rapidly change the delaytime.
How could i improve my code?
Or can someone help me?
Or would it be better to use a R2R ladder as DAC?
This is my actual code:
int Input_Audio=PA2; //Audio input
int Input_Delay=PA1; //LFO input
int Output_PWM=PB9;Â //PWM output
int dcval;
int PWM_Out;
int memory[4000];Â Â //circular buffer
int delaytime;
void setup()
{Â Â
  pinMode(Input_Audio, INPUT);
  pinMode(Input_Delay, INPUT);
  pinMode(Output_PWM, PWM); Â
  Timer2.setMode(TIMER_CH1,TIMER_OUTPUTCOMPARE);
  Timer2.setCompare(TIMER_CH1, 1);
  Timer4.setOverflow(255);Â
  Timer2.setPrescaleFactor(1);
  Timer2.setOverflow(255);
  Timer2.attachInterrupt(TIMER_CH1,PWM_int);
  Timer2.refresh();
}
void loop() {
 delaytime=analogRead(Input_Delay);Â
 for(int i = 0; i < delaytime; i ++)
 {
  PWM_Out = memory[i];   Â
  dcval=analogRead(Input_Audio);
  dcval=map(dcval,4096,0,255,0); Â
  memory[i] = dcval;
 }
}
void PWM_int(void)
{
 pwmWrite(Output_PWM,PWM_Out); Â
}
Greetings
David
Chorus_fixed_Delay.ino (828 Bytes)