4051 ic, InitMux doesn't work, manually works

So I was having trouble getting my mux on the Daisy seed to work with the 4051 IC, I’ve tried using the referenced documented way as such:

// KNOB PINS
#define POT_KNOB_PIN A1

// MUXED POTS
#define POT_MUX_PIN A2
#define POT_MUX_D0 D5
#define POT_MUX_D1 D6
#define POT_MUX_D2 D7

// CV INPUTS
#define CV_AMOUNT_PIN A0

...

// ADC configuration
AdcChannelConfig adcConfig[3];
adcConfig[0].InitSingle(POT_KNOB_PIN);
adcConfig[1].InitSingle(CV_AMOUNT_PIN);
adcConfig[2].InitMux(POT_MUX_PIN, 2, POT_MUX_D0, POT_MUX_D1, POT_MUX_D2);
hw.adc.Init(adcConfig, 3);
hw.adc.Start();

...

hw.adc.GetMuxFloat(2, 0);

It doesn’t return the value, but doing the setup manually works perfectly, as such:

// KNOB PINS
#define POT_KNOB_PIN A1

// MUXED POTS
#define POT_MUX_PIN A2
#define POT_MUX_D0 D5
#define POT_MUX_D1 D6
#define POT_MUX_D2 D7

// CV INPUTS
#define CV_AMOUNT_PIN A0

...

// ADC configuration
AdcChannelConfig adcConfig[3];
adcConfig[0].InitSingle(POT_KNOB_PIN);
adcConfig[1].InitSingle(CV_AMOUNT_PIN);
adcConfig[2].InitSingle(POT_MUX_PIN);
hw.adc.Init(adcConfig, 3);
hw.adc.Start();

...

dsy_gpio test1, test2, test3;
test1.pin = POT_MUX_D0;
test1.mode = DSY_GPIO_MODE_OUTPUT_PP;
test1.pull = DSY_GPIO_NOPULL;
dsy_gpio_init(&test1);
dsy_gpio_write(&test1, 0);

test2.pin = POT_MUX_D1;
test2.mode = DSY_GPIO_MODE_OUTPUT_PP;
test2.pull = DSY_GPIO_NOPULL;
dsy_gpio_init(&test2);
dsy_gpio_write(&test2, 0);

test3.pin = POT_MUX_D2;
test3.mode = DSY_GPIO_MODE_OUTPUT_PP;
test3.pull = DSY_GPIO_NOPULL;
dsy_gpio_init(&test3);
dsy_gpio_write(&test3, 0);
...

hw.adc.GetFloat(2);

Anyone can shed a light on what I could be missing? Thanks!

Edit: added schematic for this use case:


After some more debugging, I can see that when I initialize (first run of the program) the value is actually well updated, but then it “sticks” to a value and never changes again until I restart the app then it changes to a new value (if I move the pot while app is off for example)

I’m only testing (for now) with 2 pots, is it something related to that fact? I’ve traced and the calls seem to be happening correctly I cannot really see where’s the black hole :slight_smile:

But I suspect it’s initializing correctly, but in runtime is not updating/reading the value correctly somehow.

I guess I’m keeping a log here :slight_smile: I’ve also discovered that this is caused by using breakpoints using the debugger…If I disconnect the breakpoint and let it run, update the knob, then it reads the updated value…

Lesson for this: Breakpoints can mess with your head I imagine due to run rates…so at the end of the day it’s working correctly…took me a while to try not using the debugger and breakpoints…

Hi Pedro!

Is the main issue of this thread still need resolving?
I’m not sure if there’s something else in the code that could be affecting it.
It could be easier to troubleshoot by isolating just the mux section of the code (even removing the adc configuration for the POT_KNOB and CV_AMOUNT for now) and use serial printing.

Hi thanks, it’s working now, well at least I stopped using breakpoints to watch pot values that is, if I add a breakpoint then it stops updating the pots when using the mux system, so I’m testing it differently that’s all.

Thanks.

Hi Pedro!

I’m sorry for the delay in reply. Ideally, it would be nice to be able to use breakpoints. We should have a closer look at this when we make a proper mux tutorial in the near future. Thank you for bringing this up to us.