Board index › Products › Stomp Shield

Stomp shield Octaver.

6 posts · 14827 views

Stomp shield Octaver.

by Arduinoob » Tue Apr 15, 2014 14:32 UTC
Hi,
Im trying to build an Octave effect using the stomp shield but im running into some basic problems with the code. (It's not my strong point!) In order to build the Octave effect I need to full rectify a sine wave. I have altered the bitcrush effect as a start off point. In the code at the bottom, I have managed to half rectify a wave but Im running into problems with the code that is performing the full rectification. Can anyone help with this or just give me the pointers to head in the right direction? Also, when I tested a sine wave in an oscilloscope I was getting the reverse of what I expected with the half rectified wave. The wave was like a half rectified wave but upside down. Anyway, here is the code and thanks for any help in advance.



THe input signal is represented as a signed 16-bit integer. This means that its values can vary between
-32768 up to 32767.


*/
#include "StompShield.h"

int counter; // bit mask
byte button; // button checking timer
byte last_state; // last rotary encoder state
int output;

void setup() {
counter = 0xffff;
StompShield_init(); // setup the arduino for the shield
}

void loop() {
}

ISR(TIMER1_OVF_vect) {

// get ADC data
byte temp1 = ADCL; // you need to fetch the low byte first
byte temp2 = ADCH; // yes it needs to be done this way
int input = ((temp2 << 8) | temp1) + 0x8000; // make a signed 16b value

button--; // check buttons every so often
if (button == 0) {

// controlling what the encoder is doing
byte temp3 = (PIND & 0x94); // mask off and invert
if (((last_state | temp3) & 0x10) == 0) { // falling edge
if (temp3 & 0x04) {
if ((counter & 0x7fff) == 0) counter = 0x8000;
else counter <<= 1;
}
else counter >>= 1;
}
last_state = (temp3 ^ 0x94);
button = 0x20; // reset counter
}

//altering the input signal - half wave rectification
// if (input<=0) {
// output = input;
// } else {
// output=0;
// }

if (input<=0) {
output = input;
} else {
output=input*(-1);
}


// output data
OCR1AL = ((output + 0x8000) >> 8); // convert to unsigned and output high byte
OCR1BL = output; // output the low byte
}

Re: Stomp shield Octaver.

by guest » Wed Apr 16, 2014 08:04 UTC
you are almost there. all you have to do is reset the bias point (and invert it, if thats what you want). so, after you fullwave rectify, your signal is only positive values. so this only takes up half the range (0 - 32k). so you need to multiply everything by 2, to get the full range. but, this makes it 0 - 64k, so you also need to subtract 32k to get it to go from -32k - 32k. also, i cut out all the other code that wasnt doing anything. also, in your code you were inverting the positive values, so it was all coming out negative.

#include "StompShield.h"

int output;

void setup() {
StompShield_init(); // setup the arduino for the shield
}

void loop() {
}

ISR(TIMER1_OVF_vect) {

// get ADC data
byte temp1 = ADCL; // you need to fetch the low byte first
byte temp2 = ADCH; // yes it needs to be done this way
int input = ((temp2 << 8) | temp1) + 0x8000; // make a signed 16b value

if (input < 0) { // if number is negative
output = 0 - input; // output = -input (adding takes less time than multiplying)
} // otherwise dont do anything for positive values

output = input - 0x4000; // shift everything down by 16k, so we now have -16k -> +16k range
output <<= 1; // fast way to multiply by 2 - shift everything to the left 1 bit.

// output data
OCR1AL = ((output + 0x8000) >> 8); // convert to unsigned and output high byte
OCR1BL = output; // output the low byte
}

Re: Stomp shield Octaver.

by Arduinoob » Mon Apr 28, 2014 17:20 UTC
Thanks very much for the reply! You helped me out a lot.

Re: Stomp shield Octaver.

by digithree » Mon Apr 28, 2014 18:10 UTC
You made a small error there guest in your response. The lines
if (input < 0) { // if number is negative
output = 0 - input; // output = -input (adding takes less time than multiplying)
} // otherwise dont do anything for positive values

should be
if (input < 0) { // if number is negative
input = 0 - input; // output = -input (adding takes less time than multiplying)
} // otherwise dont do anything for positive values

otherwise the next line
output = input - 0x4000;

makes the condition redundant if the input is less than zero

Re: Stomp shield Octaver.

by guest » Tue Apr 29, 2014 04:20 UTC
good catch!

Re: Stomp shield Octaver.

by hello_kitty » Mon May 12, 2014 12:27 UTC
small mistake but very siginificant.