EasyManuals Logo

Espressif ESP32-S2 User Manual

Espressif ESP32-S2
1695 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #341 background imageLoading...
Page #341 background image
Chapter 2. API Reference
The unit and the channel number this configuration refers to.
GPIO numbers of the pulse input and the pulse gate input.
Two pairs of parameters: pcnt_ctrl_mode_t and pcnt_count_mode_t to define how the counter
reacts depending on the the status of control signal and how counting is done positive / negative edge of the
pulses.
Two limit values (minimum / maximum) that are used to establish watchpoints and trigger interrupts when the
pulse count is meeting particular limit.
Setting up of particular channel is then done by calling a function pcnt_unit_config() with above
pcnt_config_t as the input parameter.
To disable the pulse or the control input pin in configuration, provide PCNT_PIN_NOT_USED instead of the GPIO
number.
Operating the Counter
After doing setup with pcnt_unit_config(), the counter immediately starts to operate. The accumulated pulse
count can be checked by calling pcnt_get_counter_value().
There are couple of functions that allow to control the counters operation: pcnt_counter_pause(),
pcnt_counter_resume() and pcnt_counter_clear()
It is also possible to dynamically change the previously set up counter modes with pcnt_unit_config() by
calling pcnt_set_mode().
If desired, the pulse input pin and the control input pin may be changed on the flyusing pcnt_set_pin().
To disable particular input provide as a function parameter PCNT_PIN_NOT_USED instead of the GPIO number.
Note: For the counter not to miss any pulses, the pulse duration should be longer than one APB_CLK cycle (12.5
ns). The pulses are sampled on the edges of the APB_CLK clock and may be missed, if fall between the edges. This
applies to counter operation with or without a filer.
Filtering Pulses
The PCNT unit features filters on each of the pulse and control inputs, adding the option to ignore short glitches in
the signals.
The length of ignored pulses is provided in APB_CLK clock cycles by calling pcnt_set_filter_value().
The current filter setting may be checked with pcnt_get_filter_value(). The APB_CLK clock is running
at 80 MHz.
The filter is put into operation / suspended by calling pcnt_filter_enable() /
pcnt_filter_disable().
Using Interrupts
There are ve counter state watch events, defined in pcnt_evt_type_t, that are able to trigger an interrupt. The
event happens on the pulse counter reaching specic values:
Minimum or maximum count values: counter_l_lim or counter_h_lim provided in
pcnt_config_t as discussed in Configuration
Threshold 0 or Threshold 1 values set using function pcnt_set_event_value().
Pulse count = 0
To register, enable or disable an interrupt to service the above events, call pcnt_isr_register(),
pcnt_intr_enable(). and pcnt_intr_disable(). To enable or disable events on reaching threshold
values, you will also need to call functions pcnt_event_enable() and pcnt_event_disable().
In order to check what are the threshold values currently set, use function pcnt_get_event_value().
Espressif Systems 330
Submit Document Feedback
Release v4.4

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Espressif ESP32-S2 and is the answer not in the manual?

Espressif ESP32-S2 Specifications

General IconGeneral
BrandEspressif
ModelESP32-S2
CategorySingle board computers
LanguageEnglish