Logic issues, conditionals on analog in erratic


#1

I've been trying to use 3 momentary footswitches on one analog input. I worked out some potential dividers values that give an analog input the following:

3.1v while pressing 1st FS
2.3v pressing FS1 simultaneously with a 2nd FS
1.5v nominal (no FS pressed)
0.93v pressing just FS2
0v while pressing a 3rd footswitch.

I soldered it up, fitted it to box and tested with multimeter. Reliably gives said voltages. Upon powering up Axoloti and connecting the GPIO Ain to a disp dial I get the expected even spread of 0, 18, 31, 45, 61 values when pressing the footswitches. I assumed (oh dear) I'd have a good enough resolution to create a simple AD converter with those voltage/k-rate signals. Unfortunately I've had a surprise!

So here is my patch so far...

For a start I have disp dial directly reading PC4 but it reacts unreliably to my switch presses. There is a visible lag between a switch press and the dial moving. Some presses it's almost instant, others it takes upto maybe 1/2 second. It always goes to the right value though. I'm pretty sure my footswitches are putting out the voltage when I press them (tested) and the delay is something to do with Axoloti. I also see this delay when setting parameters to be controlled by a 25k pot on another analog in and I see slow response when sending MIDI in to control parameters.
For the moment I am just putting up with this problem but it's not ideal, is this normal? If not any ideas why I could be experiencing such slow GPIO?

So next, the logicy bits. I guess the picture is fairly self explanatory?
The middle (voltage/value wise) functions have timers so they are not occasionally triggered as the voltage rushes up or down past them on it's way to 0v or 3.1v (that was happening). Funnily enough those 2 more complicated functions are the ones that are working the best. The most unreliable is the top one, which is also the simplest.

I've liberally employed disp bools all over the shop to try and debug this and they are acting strangely. At the top the input is compared to 9, if it's less it should trigger disp bool 1? that 1 output should also be toggled to a continuous 1 that keeps the next disp bool lit?
That's how I thought it would work and it does 80% of the time. However, sometimes I press it, see the initial value dial react (albeit slowly) and then maybe the first disp bool lights but the toggle doesnt light the 2nd disp bool. Or the 2nd disp bool correctly toggles on only to turn itself straight back off again. Or the 2 toggles do contradictory things. Or it works but with an annoying delay.

Although it works 80% of the time that is definitely not good enough for performance. Not quite sure what I'm doing wrong here, any hints/ideas/criticisms and witicisms are very welcome!


#2

This is caused by the fact that ADC reads are noisy. The simplest solution is to implement exponentially weighted moving average (EWMA) on your ADC values.


#3

aha, thanks tele_player. I put a LPF between the gpio and the logic and it's better


#4

Exactly. Another easy way is to drop one or two of the low bits, using >> and <<.
The ADC value is left shifted 15 bits, so shift right 16 followed by shift left 16 drops one bit, shift right 17 followed by shift left 17 drops two.


#5

Ok, so that essentially acts as a noise gate, dropping the lower bits which is where most of the noise is (hopefully)

Allthough I've fixed the problem of the unreliability the latency still remains. There is a visible lag (just visible) between any input via gpio and MIDI. Is this normal? Maybe it's just while using the patcher and 'live' button?


#6

I haven't noticed this latency. I'm using Mac OS 10.14.6. Maybe it's only while using patcher, maybe it's a peculiarity of your OS?


#7

I've had delays/erratic behaviour in the display objects in some patches, but I think it's just the display on the patcher.


#8

great, thanks. I'll connect a digital out to a digital in and try and measure it standalone and with patcher. Will report back with results.


#9

the patcher display objects are not updated very frequently, so it is easy to spot latency there. try with a short triggered sound or hook up an external led to get the "real" deal