Page 1 of 1

examples/peripherals/pcnt/main/pcnt_example_main.c Bug

Posted: Tue Mar 03, 2020 2:28 am
by warren
In the following code found at:

https://github.com/espressif/esp-idf/bl ... ple_main.c

the following lines are erroneous:

Code: Select all

            if (evt.status & PCNT_EVT_THRES_1) {
                printf("THRES1 EVT\n");
            }
            if (evt.status & PCNT_EVT_THRES_0) {
                printf("THRES0 EVT\n");
            }
            if (evt.status & PCNT_EVT_L_LIM) {
                printf("L_LIM EVT\n");
            }
            if (evt.status & PCNT_EVT_H_LIM) {
                printf("H_LIM EVT\n");
            }
            if (evt.status & PCNT_EVT_ZERO) {
                printf("ZERO EVT\n");
            }
The names PCNT_EVT_THRES_1 and company are enum values which do not match the bit values in that status word. They are declared as follows:

Code: Select all

typedef enum {
    PCNT_EVT_L_LIM = 0,             /*!< PCNT watch point event: Minimum counter value */
    PCNT_EVT_H_LIM = 1,             /*!< PCNT watch point event: Maximum counter value */
    PCNT_EVT_THRES_0 = 2,           /*!< PCNT watch point event: threshold0 value event */
    PCNT_EVT_THRES_1 = 3,           /*!< PCNT watch point event: threshold1 value event */
    PCNT_EVT_ZERO = 4,              /*!< PCNT watch point event: counter value zero event */
    PCNT_EVT_MAX
} pcnt_evt_type_t;
The following homebrewed values work as intended:

Code: Select all

#define EvtMask_thres1_lat  0b00000100
#define EvtMask_thres0_lat  0b00001000
#define EvtMask_l_lim_lat   0b00010000
#define EvtMask_h_lim_lat   0b00100000
#define EvtMask_zero_lat    0b01000000
#define EvtMask_cnt_mode    0b00000011

Re: examples/peripherals/pcnt/main/pcnt_example_main.c Bug

Posted: Tue Mar 03, 2020 2:40 am
by ESP_houwenxiang
Hi,

What version of IDF are you using?

https://github.com/espressif/esp-idf/bl ... nt_types.h

Re: examples/peripherals/pcnt/main/pcnt_example_main.c Bug

Posted: Tue Mar 03, 2020 7:44 pm
by warren
This is the example you have online at github, from the master branch:

https://github.com/espressif/esp-idf/bl ... ple_main.c

Warren

Re: examples/peripherals/pcnt/main/pcnt_example_main.c Bug

Posted: Sat Mar 07, 2020 12:57 pm
by warren
I found some macros ending in the _M suffix (like PCNT_STATUS_THRES0_M), which seem to be the correct mask values to use.

Code: Select all

if (evt.status & PCNT_STATUS_THRES0_M) {
    printf("THRES0 EVT\n");
}