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

[TW#12853] PCNT with PCNT_UNIT_5 #638

Closed
HFRibeiro opened this issue May 23, 2017 · 4 comments
Closed

[TW#12853] PCNT with PCNT_UNIT_5 #638

HFRibeiro opened this issue May 23, 2017 · 4 comments

Comments

@HFRibeiro
Copy link

Hello,
using the pcnt example when i change the PCNT_TEST_UNIT from PCNT_UNIT_0 to PCNT_UNIT_5 it doesn't work anymore, the same happens with the PCNT_UNIT_6 and PCNT_UNIT_7, the other ones from 0 to 4 work well.

Is there a special configuration for this pcnt units?

Thanks

@negativekelvin
Copy link
Contributor

Driver bug. Problem is the pcnt signals are not in a contiguous block.

int input_sig_index = (channel == 0 ? PCNT_SIG_CH0_IN0_IDX + 4 * unit : PCNT_SIG_CH1_IN0_IDX + 4 * unit);

@HFRibeiro
Copy link
Author

Perfect!

By reading the http://www.espressif.com/sites/default/files/documentation/esp32_chip_pin_list_en.pdf
I thought that could be the problem.

I was just not sure what to change to solve it, thanks for the hint.

So I change the code in the pcnt.c from this:
int input_sig_index = (channel == 0 ? PCNT_SIG_CH0_IN0_IDX + 4 * unit : PCNT_SIG_CH1_IN0_IDX + 4 * unit); int ctrl_sig_index = (channel == 0 ? PCNT_CTRL_CH0_IN0_IDX + 4 * unit : PCNT_CTRL_CH1_IN0_IDX + 4 * unit);

To this:

int input_sig_index = 0; int ctrl_sig_index = 0; if(unit<5) { input_sig_index = (channel == 0 ? PCNT_SIG_CH0_IN0_IDX + 4 * unit : PCNT_SIG_CH1_IN0_IDX + 4 * unit); ctrl_sig_index = (channel == 0 ? PCNT_CTRL_CH0_IN0_IDX + 4 * unit : PCNT_CTRL_CH1_IN0_IDX + 4 * unit); } else { input_sig_index = (channel == 0 ? PCNT_SIG_CH0_IN0_IDX + 4 * unit + 12 : PCNT_SIG_CH1_IN0_IDX + 4 * unit + 12); ctrl_sig_index = (channel == 0 ? PCNT_CTRL_CH0_IN0_IDX + 4 * unit +12 : PCNT_CTRL_CH1_IN0_IDX + 4 * unit + 12); }

and the problem is solved!
Thanks once again @negativekelvin

@HFRibeiro
Copy link
Author

By the way,
the pcnt_counter_clear doesn't work, but if you use the code suggested by @SpenZerX on the forum it works fine.
esp_err_t pcnt_counter_clear(pcnt_unit_t pcnt_unit) { PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG); PCNT_ENTER_CRITICAL(&pcnt_spinlock); PCNT.ctrl.val |= (BIT(PCNT_PLUS_CNT_RST_U0_S + (pcnt_unit * 2))); PCNT.ctrl.val &= (~(BIT(PCNT_PLUS_CNT_RST_U0_S + (pcnt_unit * 2)))); PCNT_EXIT_CRITICAL(&pcnt_spinlock); return ESP_OK; }

@FayeY FayeY changed the title PCNT with PCNT_UNIT_5 [TW#12853] PCNT with PCNT_UNIT_5 May 25, 2017
@igrr
Copy link
Member

igrr commented Jun 22, 2017

Fixed in 769944b.

@igrr igrr closed this as completed Jun 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants