Page 1 of 1
ABZ Encoder
Posted: Tue Jun 07, 2022 6:55 am
by edo76mal
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.
Re: ABZ Encoder
Posted: Wed Jun 08, 2022 6:34 am
by cupracing
Hi, based on my experience with esp32 it is not possible to accurately read an encoder as determinism is not accurate.
Re: ABZ Encoder
Posted: Wed Jun 08, 2022 7:47 am
by ESP_Sprite
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?
Re: ABZ Encoder
Posted: Wed Jun 08, 2022 12:08 pm
by edo76mal
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)
Re: ABZ Encoder
Posted: Wed Jun 08, 2022 12:53 pm
by ESP_Sprite
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)
Re: ABZ Encoder
Posted: Wed Jun 08, 2022 1:47 pm
by edo76mal
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.
Re: ABZ Encoder
Posted: Thu Jun 09, 2022 2:29 am
by ESP_Sprite
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.
Re: ABZ Encoder
Posted: Thu Jun 09, 2022 9:34 am
by cupracing
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?
Re: ABZ Encoder
Posted: Thu Jun 09, 2022 12:52 pm
by Craige Hales
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.
Re: ABZ Encoder
Posted: Fri Jun 10, 2022 1:05 am
by ESP_Sprite
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)