dlmpryor
(Buhay)
20 February 2019 14:21
11
Build a 12 input pulse counter - multiple input pulse counting
Arduino Pulse counter sketch by Trystan, and tested by Glyn.
Use a serial connection to to your EmonPI
## Build a 12 input pulse counter - multiple input pulse counting

_Pulse counting shield: includes a dedicated barebones Arduino and pull down resistors (detailed below)_
### How it works
We can't use the interrupt method to measure 12 pulse inputs as there are only 2 interrupts on the Arduino. Instead, we need to sample very fast and as continuously as possible in order to catch every pulse and measure the pulse rate accurately. To get best performance we need to:
1. Read the digital input pins using fast low level digital input register commands
2. Dedicate the Aduino to pulse counting. e.g. no Ethernet data sending.
3. Streamline the code as much as possible - e.g. no floating point math and minimal serial printing.
**Low level digital input registers**
When first prototyping the multiple input pulse counter we used the standard Arduino digitalRead to read the state of the digital inputs and we also used the pulse counting Arduino to do other things like sending data via Ethernet. After doing some accuracy tests it quickly became apparent the more inputs we read, the worse the accuracy became. The accuracy deteriorated quite rapidly.
Luckily, we can read digital Inputs much faster using direct port manipulation. It's possible to read a register of 8 digital inputs in one command, although it actually drops to 6 inputs per register due to the use of 2 for serial communication ( 0 and 1) and for the clock crystal (14 and 15).
This file has been truncated. show original