You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The count value and the overflow state of the count value are located in *different* registers, resulting in the software being unable to obtain information from both of them in the same read instruction.
6
+
7
+
The race condition case is as follow:
8
+
9
+
```mermaid
10
+
sequenceDiagram
11
+
participant HW as PCNT Hardware
12
+
participant CPU0_ISR as CPU0_ISR
13
+
participant CPU1_Task as CPU1_Task (pcnt_unit_get_count)
14
+
participant REG as Reg and Soft accum counter State
15
+
16
+
CPU1_Task->>CPU1_Task: Call pcnt_unit_get_count()
17
+
Note over REG: intr_status = 0<br/>cnt_reg = cnt_value<br/>accum_value = old_value
18
+
CPU1_Task->>CPU1_Task: portENTER_CRITICAL_SAFE()
19
+
CPU1_Task->>REG: Read intr_status
20
+
Note over CPU1_Task: intr_status=0, no need to do compensation
21
+
HW->>REG: Overflow interrupt triggered
22
+
Note over REG: intr_status = 1<br/>cnt_reg = 0<br/>accum_value = old_value
23
+
REG->>CPU0_ISR: ISR is called
24
+
CPU0_ISR->>CPU0_ISR: try portENTER_CRITICAL_SAFE() but spin
CPU0_ISR->>REG: Clear interrupt status and update accum_value
31
+
Note over REG: intr_status = 0<br/>accum_value = new_value
32
+
CPU0_ISR->>CPU0_ISR: portEXIT_CRITICAL_SAFE()
33
+
34
+
Note over CPU0_ISR: Process events
35
+
Note over CPU1_Task: Return incorrect count ❌
36
+
37
+
```
38
+
39
+
In the software, we determine whether to perform compensation by checking whether the count value exceeds half of the limit. This can prevent counting errors when the overflow frequency is not high.
Copy file name to clipboardExpand all lines: docs/en/api-reference/peripherals/pcnt.rst
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -329,6 +329,10 @@ The internal hardware counter will be cleared to zero automatically when it reac
329
329
330
330
:cpp:func:`pcnt_unit_clear_count` resets the accumulated count value as well.
331
331
332
+
.. note::
333
+
334
+
When enabling the count overflow compensation, it is recommended to use as large a high/low count limit as possible, as it can avoid frequent interrupt triggering, improve system performance, and avoid compensation failure due to multiple overflows.
0 commit comments