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

warren
Posts: 15
Joined: Thu May 02, 2019 3:16 pm

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

Postby warren » Tue Mar 03, 2020 2:28 am

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

ESP_houwenxiang
Posts: 118
Joined: Tue Jun 26, 2018 3:09 am

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

Postby ESP_houwenxiang » Tue Mar 03, 2020 2:40 am

Hi,

What version of IDF are you using?

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

warren
Posts: 15
Joined: Thu May 02, 2019 3:16 pm

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

Postby warren » Tue Mar 03, 2020 7:44 pm

This is the example you have online at github, from the master branch:

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

Warren

warren
Posts: 15
Joined: Thu May 02, 2019 3:16 pm

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

Postby warren » Sat Mar 07, 2020 12:57 pm

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");
}

Who is online

Users browsing this forum: No registered users and 37 guests