# PulseCounter

パルスカウンタは、マイコンのCPUが稼働していない時もパルスを読み取り計数する回路です。パルスカウンターは２系統あります。PC0は`PulseCounter0`, PC1は`PulseCounter1`に割り当てられます。

ま&#x305F;**`PulseCounter`**&#x306F;**`PulseCounter1`**&#x306E;別名です。

## メソッド

### begin()

```cpp
void begin(uint16_t refct = 0, 
           E_PIN_INT_MODE edge = PIN_INT_MODE::FALLING,
           uint8_t debounce = 0)
```

オブジェクトを初期化し、計数を開始します。１番目のパラメータ`refct`は割り込みやavailable判定の基準となるカウント数です。この数を超えたときにアプリケーションに報告されます。また`refct`には0を指定することもできます。この場合は、スリープ起床要因にはなりません。

２番目のパラメータ`edge`は割り込みが立ち会がり(`PIN_INT_MODE::RISING`)か立下り(`PIN_INT_MODE::FALLING`)を指定します。

３番目の`debounce`は、0,1,2,3の値をとります。1,2,3の設定はノイズの影響を小さくするため値の変化の検出に連続した同じ値を要する設定です。

|  設定 | 連続サンプル数 | 最大検出周波数 |
| :-: | :-----: | :-----: |
| `0` |    -    |  100Khz |
| `1` |    2    |  3.7Khz |
| `2` |    4    |  2.2Khz |
| `3` |    8    |  1.2Khz |

### end()

```cpp
void end()
```

検出を中止します。

### available()

```cpp
inline bool available()
```

指定カウント数(`begin()`の`refct`)が０の場合は、カウントが１以上で`true`を返します。

指定カウント数(`begin()`の`refct`)が1以上の場合は、検出回数が指定カウント数を超えた場合に`true`となります。

### read()

```cpp
uint16_t read()
```

カウント値を読み出します。読み出し後にカウント値を０にリセットします。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mwx.twelite.info/v0.1.3/api-reference/predefined_objs/pulsecounter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
