How to use PCNT with no CTRL pin

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

How to use PCNT with no CTRL pin

Postby kolban » Sun Aug 12, 2018 4:45 am

As I study the Pulse Counter (PCNT) functions, I find that a Pulse Counter has a data pin and a control pin. The data pin is used as the sense input for pulses and the control pin is used as a control to determine a set of rules for how to change the counter. If the control pin is high, one set of rules can be used. If the control pin is low, a different set of rules can be used. Great ... fantastic flexibility. Now let us assume that I have no need for extra function and exclusively only wish to to use the data pin. Since the control pin can have a value of 1 or 0, if I specify the control pin as PCNT_PIN_NOT_USED, does this imply rules for control pin logically 1 or control pin logically 0 or something else?

Very related question ... can I specify the control pin as either 0x30 (48) - constant 0 and 0x38 (56) - constant 1?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

PatrikB
Posts: 16
Joined: Tue Aug 07, 2018 7:43 pm

Re: How to use PCNT with no CTRL pin

Postby PatrikB » Sun Aug 12, 2018 2:09 pm

Hi,

We are using the pulse counter without the control pin, configured like this

Code: Select all

    pcnt_config_t pcnt_config = {
        .pulse_gpio_num = ROTATION_CNT_IO,
        .ctrl_gpio_num = -1,
        .channel = PCNT_CHANNEL_0,
        .unit = PCNT_UNIT_ROTATION,
        .pos_mode = PCNT_COUNT_INC, // Count up on the positive edge
        .neg_mode = PCNT_COUNT_DIS, // Keep the counter value on the negative edge
    };
From pcnt.h in the SDK

Code: Select all

/**
 * @brief Pulse Counter configuration for a single channel
 */
typedef struct {
    int pulse_gpio_num;             /*!< Pulse input GPIO number, if you want to use GPIO16, enter pulse_gpio_num = 16, a negative value will be ignored */
    int ctrl_gpio_num;              /*!< Control signal input GPIO number, a negative value will be ignored */
    pcnt_ctrl_mode_t lctrl_mode;    /*!< PCNT low control mode */
    pcnt_ctrl_mode_t hctrl_mode;    /*!< PCNT high control mode */
    pcnt_count_mode_t pos_mode;     /*!< PCNT positive edge count mode */
    pcnt_count_mode_t neg_mode;     /*!< PCNT negative edge count mode */
    int16_t counter_h_lim;          /*!< Maximum counter value */
    int16_t counter_l_lim;          /*!< Minimum counter value */
    pcnt_unit_t unit;               /*!< PCNT unit number */
    pcnt_channel_t channel;         /*!< the PCNT channel */
} pcnt_config_t;

Who is online

Users browsing this forum: No registered users and 103 guests