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
}
- It is currently Sat Jan 28, 2023 12:27 am • All times are UTC - 8 hours [ DST ]
Stomp shield Octaver.
6 posts
• Page 1 of 1
Re: Stomp shield Octaver.
Thanks very much for the reply! You helped me out a lot.
- Arduinoob
- Posts: 4
- Joined: Tue Apr 15, 2014 6:46 am
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest