Author Topic: arduino stompbox kit  (Read 8813 times)

g_u_e_s_t

arduino stompbox kit
« on: August 01, 2013, 03:08:46 AM »
i just finished an arduino shield kit, that does all the dirty work of getting a guitar signal ready for sampling and playback:
http://www.openmusiclabs.com/projects/stomp-shield/

all the plans and code are up on the wiki if you want to make your own:
http://wiki.openmusiclabs.com/wiki/StompShield

all comments welcome, as long as they arent about my poor guitar playing in the demo video.

SISKO

Re: arduino stompbox kit
« Reply #1 on: August 01, 2013, 07:38:08 AM »
This is amazing!!

Reading your post about the  pwm dac got me inspired to start looking at audio dsp in microcontrollers. Before that, I only knew little about programming (mostly C/C++) and a little about PICs. Anyway, I started to implement your idea in a PIC**** (dont remember exactly the number) and kind of got it, on the simulator, but did not follow any further.
Recently I bought Teensy 3.0 and started to do the exact same thing. Im  able to read the ADC and port this value to the pwm with no major problems or dificulty as its programmed in Arduino languaje and it seems to be very much like C and with some very comfortable functions.

The Teensy has 16 bit adcs (14bits usables), and capable of 10bits resolution pwm at 46875 Hz (actually it measures 47500Hz). Did some test with the oscilloscope and generator and seemed to work  :)
Right now Im looking at the output filter desing, Im using a RC single pole low pass filter, 10k 1nF) but got to investigate a little more.
Im willing to hear this thing, so im planning the input and output section. must search for preparing the signal to enter the micro. Do you have any advice about this?

Is there a schematic for the shield?
It seems much interesting! I hope I can port your codes to the Teensy... ill work on that as this goes on.

Thanks for the inspiration, your work is really gratified!
--Is there any body out there??--

slacker

Re: arduino stompbox kit
« Reply #2 on: August 01, 2013, 01:18:45 PM »
Looks very interesting, thanks for sharing.

Is there a schematic for the shield?

Schematic is in the second link above.

g_u_e_s_t

Re: arduino stompbox kit
« Reply #3 on: August 01, 2013, 01:57:41 PM »
hey sisko, awesome to hear about your project.  i would say the difficult part was setting up the anti-aliasing filters.  you should check out the schematics up on the wiki, its a pretty straightforward circuit, and can be used with any microcontroller.  you will have to run it at 3.3V for the teensy (i am pretty sure its a 3.3V microcontroller).  the values need to be pretty accurate for the filter, but they are common values, so it shouldnt be tough to find.  you should also look into the dual PWM setup, it extends the PWM to 16b, and increases it frequency.  if the teensy has "phase correct" PWM mode, you should use that as well, its lower distortion.

SISKO

Re: arduino stompbox kit
« Reply #4 on: September 29, 2013, 10:54:10 PM »
Finnally im here with some news and new questions too.
First i must say that this works amazingly. Im using the stompshield design for signal conditioning entering into a Teensy3.0 and leaving from it.
I had a hard time debugging it until i realized that the adc value should be left justified. Fixed that and now works like charm.

Next step, ill modulate the signal with and lfo.

As hapiness arrived, so did some new questions:
why are there two voltages dividers on the stompshield schematic (one at the input, one for the rest)?
I do not fully understand the method of the pwm dac, but it works! Is there a way to make it work with right justified numbers?
Is there a way to output a 16bit number?
« Last Edit: September 29, 2013, 10:56:36 PM by SISKO »
--Is there any body out there??--

g_u_e_s_t

Re: arduino stompbox kit
« Reply #5 on: September 30, 2013, 03:55:13 PM »
glad to hear its working.

there are 2 voltage dividers setting bias voltages because of the small value of the GAIN pot.  you could probably get away with just 1, but then the signal from the output of the input gain stage would effect the bias voltage a bit.  i could only get the pots i wanted in max value of 50k.  so, for a gain of 50, R4 had to 1k.  if could have gotten 1M pots, then i could have used a 20k resistor.

when the pot is all the way down, so its at a gain of 1, the output of the opamp has to drive the 1k resistor directly at full amplitude.  the 1k resistor and 22uF capacitor give a lowpass filter of 7.5Hz, so up at 75Hz youre only 20dB down, and 750Hz is only 40dB down, which is not really enough to keep one stage of the circuit from effecting others.  so i opted to use a second bias voltage to keep them completely isolated.

the PWM dac is designed to work with 16b numbers.  there are 2 resistors, one from PWM_H and PWM_L.  these are 2 seperate PWM outputs of the microcontroller.  the high byte goes to PWM_H and the low byte to PWM_L.  the 2 PWM outputs should be off the same counter, and ideally in phase correct mode, although that is not as critical.

the audio value needs to be converted to be played out on the PWM.  the PWM is centered at 0x80, with values below this being negative, and values above this being positive.  so if you are using signed values, just add them to 0x80.

SISKO

Re: arduino stompbox kit
« Reply #6 on: October 03, 2013, 12:13:24 PM »
Thanks for the explanation about the voltage dividers.

I cannot get 16b of resolution, but that maybe me and the fact im workin with the teensy rather than the arduino.
My sketch looks like this:

    y = analogRead(0)<< 6;.// Convert 16bit analogRead() value to 10bit, left justified
    ADCH = y  >> 8;............// ADCH now contains the 8 upper bits (MSBs?)
    ADCL = y & 0xFF;...........// ADCL now contains de lower 8 bits          
    analogWrite (3, ADCH);..// Output PWM @pin3
    analogWrite (4, ADCL);

"y" and analogRead(0) are both unsigned int
ADCH and ADCL are both bytes data types

analogWrite() are two independant PWM outputs @46,875 kHz with 10bits of resolution (i limited its resolution to 8 bits with analogWriteResolution(8) because ADCH and ADCL are 8bits.

The way its now, it works perfectly. Almost no difrence when turning the mix knob from one side to the other.
As soon as i try to ouput the full 16b value of analog read (y = analogRead(0);) i get a very small signal that its easly distorted if the input level is a little high
« Last Edit: October 03, 2013, 12:21:26 PM by SISKO »
--Is there any body out there??--

g_u_e_s_t

Re: arduino stompbox kit
« Reply #7 on: October 03, 2013, 02:39:51 PM »
try this:

Code: [Select]
y = analogRead(0);.// Convert 16bit analogRead() value to 10bit, left justified
analogWrite (3, y & 0x03fc);..// Output PWM @pin3
analogWrite (4, ((y << 8) & 0x0300));

the way i am assuming the teensy works, is that analogRead() gives a value from 0 - 1023 (10b), and that analogWrite() takes in a value from 0 - 1023 (10b).  so what happens here, is that your 10b value comes in, and the upper 8b gets passed to pin3, and the lower 2b gets passed to pin4, but shifted up by 8b (the resistors at the output mixer deal with the scaling).  this way both values take up the full PWM range.

you wont see any audio difference between this and just passing your 10b value straight through with this code.  the 16b aspect starts making things sound better when you do multiplies and other operations which would otherwise truncate at 10b.  but with 16b output you get better resolution as they no longer truncate.

SISKO

Re: arduino stompbox kit
« Reply #8 on: October 03, 2013, 05:15:30 PM »
It works!  :icon_biggrin:

As youve said, there is no audio difference but it feels much better to know that its working the best way it can (or at least how it should)

Thanks so much for taking the time!
--Is there any body out there??--

Jamdog

Re: arduino stompbox kit
« Reply #9 on: April 15, 2016, 09:28:07 PM »
Greetings.  I know this is somewhat an old post,  but I am just starting at looking into using a teensy 3.1 to make myself a pedal.
The 3.1 is an arm processor and has a DAC (and many pwms)
I hope to be using an ADC on the way in,  and the DAC on the way out.
I do have a pair of tl082 that I think will be required to tweak the ins and outs. 

Anything I should be concerned about?
-Jamdog