Skip to content
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

Failed to use Rotary_encoder_example (IDFGH-5105) #6889

Closed
zsjlovestudy opened this issue Apr 16, 2021 · 8 comments
Closed

Failed to use Rotary_encoder_example (IDFGH-5105) #6889

zsjlovestudy opened this issue Apr 16, 2021 · 8 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@zsjlovestudy
Copy link

Because I used pins 10 and 11 on the PCB , when I changed the GPIO pins in the example, there was an error.

I need to use four rotary encoders simultaneously。However, after I made four copies according to the template of the sample code, he made a mistake of interrupting the repeated registration. Could you please tell me how to solve this?

When I comment out the code that breaks registration, I can run all three at once, except for pins 10 and 11.

image

image

image

@espressif-bot espressif-bot added the Status: Opened Issue is new label Apr 16, 2021
@github-actions github-actions bot changed the title Failed to use Rotary_encoder_example Failed to use Rotary_encoder_example (IDFGH-5105) Apr 16, 2021
@suda-morris
Copy link
Collaborator

GPIO10 and GPIO11 on ESP32 are used by SPI flash by default, please refer to datasheet and soc/esp32/include/soc/io_mux_reg.h for more details.
As for the example itself, if you want to drive multiple encoders with overflow handling (in interrupt handler), you need to alter the example, make sure calling pcnt_isr_service_install only once globally. And handle the overflow event for each pcnt unit respectively in the ISR callback.

@zsjlovestudy
Copy link
Author

Hello, I have read the io_mux_reg.h file, but I don't quite understand it.First I want to know if 10 and 11 can be modified to be used as encoders.Secondly, if possible, how to modify it?

@suda-morris
Copy link
Collaborator

Hi @zsjlovestudy GPIO11 is SPI_CS0_GPIO_NUM you can't use it for other purposes.

@zsjlovestudy
Copy link
Author

Hi @zsjlovestudy GPIO11 is SPI_CS0_GPIO_NUM you can't use it for other purposes.

Hello, could you please tell me if there are any other pins like 11 pins? Because I need to specify the pin to PWM and encoder at present.
image

@suda-morris
Copy link
Collaborator

The following GPIOs are used by SPI Flash by default:

#define SPI_CLK_GPIO_NUM                            6
#define SPI_CS0_GPIO_NUM                            11
#define SPI_Q_GPIO_NUM                              7
#define SPI_D_GPIO_NUM                              8
#define SPI_WP_GPIO_NUM                             10
#define SPI_HD_GPIO_NUM                             9

@camrbuss
Copy link

camrbuss commented May 3, 2021

In order to create multiple encoder instances the ROTARY_CHECK needs to be avoided from the pcnt_isr_service_install call. I added this switch to the "register interrupt handler" section of rotary_encoder_pcnt_ec11.c so that I could have multiple encoder instances.

	// register interrupt handler
	switch(pcnt_isr_service_install(0))
	{
		case ESP_OK:
			break;
		case ESP_ERR_INVALID_STATE:
			ESP_LOGI(TAG, "pcnt isr already installed");
			break;
		default:
			ROTARY_CHECK(1==0, "install isr service failed", err, ESP_FAIL);
	}

Does anyone want a pull request for something like this? Is this component going to be an "official" component one day?

@suda-morris
Copy link
Collaborator

Hi @camrbuss yes, the issue you found is correct. The interrupt is shared by PCNT channels, it should be installed only once.

Is this component going to be an "official" component one day?

We don't have a plan to raise the level of this example component, but we're working on new PCNT driver APIs to make that peripheral more flexible, especially for encoders use cases.

@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels Jun 30, 2021
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress labels Jul 8, 2021
@yangwc
Copy link

yangwc commented Jul 13, 2021

I ran into the same problem. I configured two encoder.
image

image

espressif-bot pushed a commit that referenced this issue Oct 12, 2021
Fix the issue mentioned when using two or more encoders. Modify PCNT_CTRL_GND_IO
to avoid the affect of USB JTAG(origin pin 19 is used for USB D-). Update esp32c3.
peripherals.ld and docs for esp32s3.

Closes #6889
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

5 participants