mikh3x4/smartup-robot

Potential bug/typo when setting up round-robin for ADCs

Opened this issue · 2 comments

When setting up round-robin for ADCs, you use decimal value 10100 instead 0b10100. It works for you, but most likely only by coincidence: 10100 (DEC) is 10011101110100 (BIN), and compiles fine because assertions in RP2040 C SDK were disabled (or ignored).

//temp sensor and pin 28
adc_set_round_robin(10100);

If you had PARAM_ASSERTIONS_ENABLED_ADC enabled, it would catch it (from the C pico-sdk, hardware/adc.h):

static inline void adc_set_round_robin(uint input_mask) {
    valid_params_if(ADC, input_mask < (1 << NUM_ADC_CHANNELS));
    hw_write_masked(&adc_hw->cs, input_mask << ADC_CS_RROBIN_LSB, ADC_CS_RROBIN_BITS);
}

Oh, nice find.
I'm not sure if I'm more impressed by the fact that you caught it or the fact that I managed to find a number that has 5 last digits the same in DEC and BIN.

Out of curiosity why are you digging into the sources now?

Out of curiosity why are you digging into the sources now?

I wasn't really digging into your project sources directly, I was searching for some Pico ADC related stuff, including using GitHub search. While scrolling the results this one just looked weird, unusual, so I got interested and wanted figure out why it worked in the first place.