LOGGER  Logger
Data Logging using ESP8266
Macros | Functions
pincounter.cpp File Reference
#include <arduino.h>
#include "pincounter.h"
#include "sensorlibrary.h"
#include "services.h"
#include "huzzahpins.h"

Macros

#define pincounterEdit   1
 version of this module
 
#define MINIMUM_PULSE_LENGTH   10
 Minimum time a pin must be low to count as a pulse (in ms).
 
#define NUM_PULSE_RING   16
 

Functions

EXTERNDEF void pincounterCountPulse (uint8_t pulseID)
 
EXTERNDEF void pincounterInit ()
 Initialize the counting services, call once at system startup.
 
EXTERNDEF uint32_t pincounterPulses (uint8_t *, uint8_t pinID)
 
EXTERNDEF uint32_t pincounterFrequency (uint8_t *, uint8_t pinID)
 
EXTERNDEF void pincounterSetPulsesSinceBoot (uint8_t pinID, uint32_t pulses, uint8_t sensorID)
 
EXTERNDEF void pincounterDump ()
 Dump the status of the pin counting routines.
 

Detailed Description

Services associated with counting the number of times a pin transitions.

Macro Definition Documentation

#define NUM_PULSE_RING   16

Each time a pulse starts a time stamp delta is logged in a ring buffer. A running total of the members of the ring buffer is kept. The average is the running total divided by the number of entries. The running total is kept in the ISR so there will be no issues with the stamp values changing out from under the logging. NUM_PULSE_RING is the number of elements to average pulses over.

Function Documentation

EXTERNDEF void pincounterCountPulse ( uint8_t  pulseID)

Routine to call when a pin has transitioned to low. It is safe to call this from an ISR, but, typically it is called from code that polls sensor devices at a higher level.

Parameters
pulseIDpulse ID is used as a table index
EXTERNDEF uint32_t pincounterFrequency ( uint8_t *  ,
uint8_t  pinID 
)

Report the frequency in thousands of pulses per minute that the counter is observing. There is some smoothing of the frequency by averaging over multiple counts.

The first parameter is to make the call compatible with sensor reading

Parameters
pinIDID of pin to read
Returns
pulses per minute * 100
EXTERNDEF uint32_t pincounterPulses ( uint8_t *  unused,
uint8_t  pinID 
)

Report the number of pulses seen. Pulses are counted at each falling edge.

Parameters
unusedto make the call compatible with sensor reading
pinIDID of pin to read
Returns
Number of edges seen since boot.
EXTERNDEF void pincounterSetPulsesSinceBoot ( uint8_t  pinID,
uint32_t  pulses,
uint8_t  sensorID 
)

Set the number of pulses seen since boot.

Parameters
pinIDID of pin to set count for
pulsespulses since boot for the pin
sensorIDsensor that detects these pulses