Skip to content

Fix Pin is not configured as analog channel error #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

jeremiahrose
Copy link

Forum conversation on the issue here: https://community.simplefoc.com/t/pin-is-not-configured-as-analog-channel/6751/5

Current sense align is currently not working on ESP32 boards due to a __analogChannelConfig(): Pin is not configured as analog channel error during current_sense.init().

The error is coming from this function in the arduino-esp32 framework. It is checking to see if the pin type is ESP32_BUS_TYPE_ADC_ONESHOT.

In arduino-esp32, it appears that the ESP32_BUS_TYPE_ADC_ONESHOT setting is only applied to a pin in the __analogInit function, which in turn is only ever invoked during an analogRead (or analogReadMilliVolts, which SimpleFOC doesn’t use).

This is mainly a bug in arduino-esp32 (since analogSetPinAttenuation should be able to work before an analogRead is called). But we can (and should) work around this in the SimpleFOC library since it may be a long time until a fix is released upstream. We can ensure the pin is initialised correctly by reversing the order of the analogSetPinAttenuation and the analogRead calls in the hardware specific driver for ESP32.

Forum conversation on the issue here: https://community.simplefoc.com/t/pin-is-not-configured-as-analog-channel/6751/5

Current sense align is currently not working on ESP32 boards due to a `__analogChannelConfig(): Pin is not configured as analog channel` error during `current_sense.init()`.

The error is coming from [this function](https://github.com/espressif/arduino-esp32/blob/bda7c4811728e538b4ea393a5be148cbb614daed/cores/esp32/esp32-hal-adc.c#L157C38-L172) in the `arduino-esp32` framework. It is checking to see if the pin type is `ESP32_BUS_TYPE_ADC_ONESHOT`.

In `arduino-esp32`, it appears that the `ESP32_BUS_TYPE_ADC_ONESHOT` setting is only applied to a pin in the `__analogInit` function, which in turn is only ever invoked during an `analogRead` (or `analogReadMilliVolts`, which SimpleFOC doesn’t use).

This is mainly a bug in `arduino-esp32` (since `analogSetPinAttenuation` should be able to work before an `analogRead` is called). But we can (and should) work around this in the SimpleFOC library since it may be a long time until a fix is released upstream. We can ensure the pin is initialised correctly by reversing the order of the `analogSetPinAttenuation` and the `analogRead` calls in the hardware specific driver for ESP32.
@runger1101001 runger1101001 added the bug Something isn't working label Mar 13, 2025
@runger1101001
Copy link
Member

Thanks so much for reporting this. As we're not using the value returned by analogRead() here this looks like it will work as expected. I don't have a setup ready to test this with atm.

@askuric
Copy link
Member

askuric commented Mar 14, 2025

Hi @jeremiahrose,
I've verified and I do not have the error code after integrating the change. We can merge this.

Just to clarify, when you say:

Current sense align is currently not working on ESP32 boards due to a __analogChannelConfig(): Pin is not configured as analog channel error during current_sense.init().

In my investigation, I did not see any real effects of this error apart from the displayed message. The adcRead functions still functions normally. Did you have some issues with your current sensing which you can trace back to this error? (or which dissapeared after the implemented change)

@runger1101001 runger1101001 added this to the 2.3.5_Release milestone Mar 14, 2025
@runger1101001 runger1101001 merged commit 1e1ace5 into simplefoc:dev Mar 14, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants