ABZ Encoder

edo76mal
Posts: 9
Joined: Wed May 11, 2022 10:17 am

ABZ Encoder

Postby edo76mal » Tue Jun 07, 2022 6:55 am

Hi.

I need to develop the reading of a 2048 pulse abz encoder with wroom32 and visualgdb. I tried with the rotary encoder sample but it doesn't work. Can you help me?

Thanks to everybody.

cupracing
Posts: 3
Joined: Wed Jun 08, 2022 6:28 am

Re: ABZ Encoder

Postby cupracing » Wed Jun 08, 2022 6:34 am

Hi, based on my experience with esp32 it is not possible to accurately read an encoder as determinism is not accurate.

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: ABZ Encoder

Postby ESP_Sprite » Wed Jun 08, 2022 7:47 am

cupracing wrote:
Wed Jun 08, 2022 6:34 am
Hi, based on my experience with esp32 it is not possible to accurately read an encoder as determinism is not accurate.
The ESP32 has a pulse counter specifically for this purpose with examples showing how to use this that as far as we know hasn't had any bugs or issues. Can you specify what you mean with 'determinism is not accurate'?

@edo76mal: You'll have to be a bit more precise than 'it doesn't work' for us to be able to help you. What results do you expect and what results do you get? What have you tried doing yourself to fix the issue?

edo76mal
Posts: 9
Joined: Wed May 11, 2022 10:17 am

Re: ABZ Encoder

Postby edo76mal » Wed Jun 08, 2022 12:08 pm

The code example I use is rotary encoder. I am not able to read encoder pulses using only one channel. I want to count the square waves, so I can use only one channel (channel A in my case)

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: ABZ Encoder

Postby ESP_Sprite » Wed Jun 08, 2022 12:53 pm

Aside from the Z, an ABZ encoder is the same as a rotary encoder, isn't it? Why wouldn't you be able to use the pulse encoder example then? (I assume you're refering to this one)

edo76mal
Posts: 9
Joined: Wed May 11, 2022 10:17 am

Re: ABZ Encoder

Postby edo76mal » Wed Jun 08, 2022 1:47 pm

Yes, the sample in that.

An ABZ encoder has A, B and Z signals and I want to use only A signal. So, I expect to read each square wave that comes from the A signal of the encoder but it is not true. I don't read the pulses.
FurthermoreI don't succeed in setting 4 ms task, I noticed that task can run to 10 ms.

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: ABZ Encoder

Postby ESP_Sprite » Thu Jun 09, 2022 2:29 am

Okay, so you're effectively wanting to count pulses of a square wave? You should be able to get there by modifying all references to channel B in that example, setting the level_gpio_num of channel A to -1 (to indicate you're not using it) and to remove all pcnt_chan_set_*_action statements and replace it with ESP_ERROR_CHECK(pcnt_channel_set_edge_action(pcnt_chan_a, PCNT_CHANNEL_EDGE_ACTION_INCREASE, PCNT_CHANNEL_EDGE_ACTION_INCREASE)); . This should count both positive and negative edges. Suggest you also read the Pulse Count Controller section of the TRM.

cupracing
Posts: 3
Joined: Wed Jun 08, 2022 6:28 am

Re: ABZ Encoder

Postby cupracing » Thu Jun 09, 2022 9:34 am

Hi ESP_Sprite, because I try to go up to 250 deterministic cycles, but seems that over 100hz the freertos has some problems. Can you explain me why that?

Craige Hales
Posts: 94
Joined: Tue Sep 07, 2021 12:07 pm

Re: ABZ Encoder

Postby Craige Hales » Thu Jun 09, 2022 12:52 pm

You should use an interrupt handler. gpio_isr_handler_add would be a starting point. As the doc says, do the least work you can in the isr handler, update state information and return. Don't call anything. Use an async task to consume the state information. The state information lives in static variables. For a quadrature encoder, the isr could manage a tiny state machine that updates a counter. Yes, look into the pulse counter. Looks like a better idea than writing your own!

As I recall, the vTaskDelay can't go smaller than a fairly large delay, 1/100 1/1000 ? sec perhaps...been a while. Sounds like you might be trying to use that in a way it isn't designed to be used.
Last edited by Craige Hales on Fri Jun 10, 2022 3:02 am, edited 1 time in total.
Craige

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: ABZ Encoder

Postby ESP_Sprite » Fri Jun 10, 2022 1:05 am

cupracing wrote:
Thu Jun 09, 2022 9:34 am
Hi ESP_Sprite, because I try to go up to 250 deterministic cycles, but seems that over 100hz the freertos has some problems. Can you explain me why that?
The pulse counter specifically is a *hardware* device that does the pulse counting. It doesn't need software or FreeRTOS to do anything. How does your implementation require 250 interrupts per second? (Also, if you really need that, you could use esp-timer, a hardware timer, or if you really need to, increase FreeRTOSses tick granularity)

Who is online

Users browsing this forum: No registered users and 74 guests