Christian_K
New member
I build a simple, working teensy 4.0 based midi-controller with Doepfer potentiometer wheels:
The full code is listed at the end of this post.
I have an issue with the value smoothing, which leads to midi-event flooding whilst the potentiometers are in between my floor and ceiling values , therefore this post, with the intention to get help.
(This is my first Arduino and Electronics project)
I used 3 different value smoothing concepts:
a.) Default software solution [1]
b.) Extended software solution [2]
c.) Teensy on board solution (`analogReadResolution() analogReadAveraging()`)
I still use approach c.) but the analogue readings are still not very smooth. Using a different analogReadResolution-setting does not help. With the settings
I would like to solve this root cause, i.e. I want to build a circuit, which prevents the deviations, by smoothing the current instead of smoothing unstable readings.
According to this post [3], analoge readings should be smoother, with 100nF capacitors added between the ground and the analogue board input. I bought various high quality 100nF capacitors, but they appear not to have any effect on the deviation at all, whilst added, i.e. the deviation plot does not look any different, compared to without the capacitors. 100nF might not fit for my purpose, as I have 3 potentiometers instead of 1 in the post behind [3].
So my questions are:
Thank you all in advance
[1] https://docs.arduino.cc/built-in-examples/analog/Smoothing/
[2] https://goetzmd.de/nicht-konstante-poti-werte-am-arduino-ausgleichen-tutorial/
[3] https://forum.pjrc.com/index.php?threads/teensy-3-1-analogread-0-1-uf-capacitor-but-what-kind.54027/
The full code is listed at the end of this post.
I have an issue with the value smoothing, which leads to midi-event flooding whilst the potentiometers are in between my floor and ceiling values , therefore this post, with the intention to get help.
(This is my first Arduino and Electronics project)
I used 3 different value smoothing concepts:
a.) Default software solution [1]
b.) Extended software solution [2]
c.) Teensy on board solution (`analogReadResolution() analogReadAveraging()`)
I still use approach c.) but the analogue readings are still not very smooth. Using a different analogReadResolution-setting does not help. With the settings
analogReadResolution(10)
andanalogReadAveraging(32)
I still get following deviation, when i keep my pitchbend wheel still somewhere in the upper half:I would like to solve this root cause, i.e. I want to build a circuit, which prevents the deviations, by smoothing the current instead of smoothing unstable readings.
According to this post [3], analoge readings should be smoother, with 100nF capacitors added between the ground and the analogue board input. I bought various high quality 100nF capacitors, but they appear not to have any effect on the deviation at all, whilst added, i.e. the deviation plot does not look any different, compared to without the capacitors. 100nF might not fit for my purpose, as I have 3 potentiometers instead of 1 in the post behind [3].
So my questions are:
- What is the electronic intention of the capacitors mentioned (i.e. what is the design pattern idea behind adding them)?
- How can I calculate the proper capacitor value for my setup, i.e. what is the math behind the issue?
- Do I have to triple the capacitor value?
- Do I have to divide the capacitor value by 3?
- Any other ideas to solve the problem by design in favour of having bad readings?
Thank you all in advance
[1] https://docs.arduino.cc/built-in-examples/analog/Smoothing/
[2] https://goetzmd.de/nicht-konstante-poti-werte-am-arduino-ausgleichen-tutorial/
[3] https://forum.pjrc.com/index.php?threads/teensy-3-1-analogread-0-1-uf-capacitor-but-what-kind.54027/
C:
const boolean serialMode = true;
const int midiChannel = 1;
const int midiCtrlNoModulation = 1;
const int potiAmount = 3;
int potiPin[] = { A0, A1, A2 };
int potiReadValue[] = { 0, 0, 0 };
int outputValue[] = { 0, 0, 0 };
int outputValueOld[] = { 0, 0, 0 };
void setup() {
analogReadAveraging(32);
analogReadResolution(10);
if (serialMode) {
Serial.begin(9600);
}
}
void loop() {
for (int i = 0; i < potiAmount; i++) {
potiReadValue[i] = analogRead(potiPin[i]);
if (i == 0) {
// Spring centered pitch bend wheel
outputValue[i] = midiCenterValueMappingPitch(potiReadValue[i], 150, 300, 313, 475);
} else if (i == 1) {
// Non-centered modulation wheel
outputValue[i] = constrain(map(potiReadValue[i], 162, 502, 0, 127), 0, 127);
} else if (i == 2) {
// Non-centered aftertouch wheel
outputValue[i] = constrain(map(potiReadValue[i], 144, 508, 0, 127), 0, 127);
}
if (outputValueOld[i] != outputValue[i]) {
if (i == 0) usbMIDI.sendPitchBend(outputValue[i], midiChannel);
else if (i == 1) usbMIDI.sendControlChange(midiCtrlNoModulation, outputValue[i], midiChannel);
else if (i == 2) usbMIDI.sendAfterTouch(outputValue[i], midiChannel);
}
outputValueOld[i] = outputValue[i];
}
traceValuesWhenSerialOn();
delay(5);
}
int midiCenterValueMappingPitch(int readValue, int lowerCeiling, int lowerThreshold, int upperThreshold, int upperCeiling) {
// https://studiocode.dev/kb/MIDI/midi-pitch-bend/
int result;
if (readValue <= lowerThreshold) {
result = constrain(map(readValue, lowerCeiling, lowerThreshold, -8192, -1), -8192, 1);
} else if (readValue >= upperThreshold) {
result = constrain(map(readValue, upperThreshold, upperCeiling, 1, 8191), 1, 8191);
} else {
result = 0;
}
return result;
}
void traceValuesWhenSerialOn() {
// Prints the current read values as well as the mapped Values
if (serialMode) {
delay(100);
Serial.print("|\t");
for (int x = 0; x < potiAmount; x++) {
Serial.print(potiReadValue[x]);
Serial.print("\t");
}
Serial.print("|\t");
for (int x = 0; x < potiAmount; x++) {
Serial.print(outputValue[x]);
Serial.print("\t");
}
Serial.println("");
}
}