Serial Wombat Arduino Library

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
SerialWombatPulseTimer Class Reference

A Class which uses a Serial Wombat pin to measure the length of a pulse high and low time. More...

`#include <SerialWombatPulseTimer.h>`

Inheritance diagram for SerialWombatPulseTimer:
[legend]
Collaboration diagram for SerialWombatPulseTimer:
[legend]

## Public Member Functions
| SerialWombatPulseTimer (SerialWombatChip &serialWombat)
| Class constructor for SerialWombatPulseTimer.
int16_t | begin (uint8_t pin, SerialWombatPulseTimerUnits units=SW_PULSETIMER_uS, bool pullUpEnabled=false)
| Initialization routine for SerialWombatPulseTimer.
void | refresh ()
| Retreive the latest values for HighCounts, LowCounts, Pulses, and MeasurementOverflowOccured.
void | refreshHighCountsLowCounts ()
| Retreive the High and Low counts from the Serial Wombat chip in a single transaction.
void | refreshHighCountsPulses ()
uint16_t | readHighCounts ()
uint16_t | readLowCounts ()
uint16_t | readPulses ()
Public Member Functions inherited from SerialWombatPin
| SerialWombatPin (SerialWombatChip &serialWombatChip)
| Instantiates a Serial Wombat Pin.
| SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
| Instantiates a Serial Wombat Pin.
uint16_t | readPublicData ()
| Read the 16 Bit public data associated with this pin.
void | pinMode (uint8_t mode, bool pullDown=false, bool openDrain=false)
| Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings.
void | digitalWrite (uint8_t val)
| Set output pin High or Low.
int | digitalRead ()
| Reads the state of the Pin.
uint16_t | writePublicData (uint16_t value)
| Write a 16 bit value to this pin.
uint8_t | pin ()
| Returns the current SW pin number. Used primarily for virtual calls by derived classes.
uint8_t | swPinModeNumber ()
| Returns the Mode number. Used primarily by derived classes to populate packet data.
int16_t | initPacketNoResponse (uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
int16_t | disable ()
| Disables the pin mode (if applicable)
int16_t | enablePullup (bool enabled)
| Enables the weak pull up on a pin. Implemented on SW18AB only.
int16_t | enablePullDown (bool enabled)
| Enables the weak pull down on a pin. Implemented on SW18AB only.
int16_t | enableOpenDrain (bool enabled)
| Enables open drain mode on a pin. Implemented on SW18AB only.

## Public Attributes
uint16_t | HighCounts = 0
uint16_t | LowCounts = 0
uint16_t | Pulses = 0
bool | MeasurementOverflowOccurred = false

## Additional Inherited Members
Protected Attributes inherited from SerialWombatPin
uint8_t | _pin = 255
SerialWombatChip & | _sw
uint8_t | _pinMode = 0

## Detailed Description

A Class which uses a Serial Wombat pin to measure the length of a pulse high and low time.

This class is used to measure the length of pulses in mS or in uS. On the Serial Wombat 4A/B the precision is about 8uS in uS mode, with an accuracy of +/- 2% because of variation in the Serial Wombat chip's internal oscillator.

One SerialWombatPulseTimer should be declared per Serial Wombat pin in this mode.

A video Tutorial on this pin mode is available:

https://youtu.be/YtQWUub9gYw

This pinmode is useful for measuring RC Servo outputs, PWM frequency and duty cycle, or any other signal where the pulse width is relevant. It is designed to measure repetitive signals. It is not intended to read a number of differing independent pulse widths that come one after another, such as WS2812 or similar output.

Warning
  Care must be taken when using this pinmode with high frequency ( > 5 kHz) signals or pins that may be left floating on the Serial Wombat 4A / 4B because the Serial Wombat 4A and 4B chip uses an interrupt internally to capture transition timestamps. Excessively frequent pin transitions may cause the interrupt handler to starve the main processing loop, impacting function of all pin modes and communications.

The Serial Wombat chip can be queried for overflow frames. If overflow frames are occuring, then the system is overloaded.

The Serial Wombat 4A and 4B chips can measure a maxium of 8 transitions per mS across all pulse input pins. More frequent transitions than this may result in incorrect measurements. The MeasurementOverflowOccurred flag is set if at any time more than 8 transitions occured without processing.

The Serial Wombat 18AB chip uses a DMA based sampling scheme with samples taken at 57600 Hz. It has lower resolution than the Serial Wombat 4A/B (17 uS resolution), but can measure up to 18 simultaneous pulse trains and is not subject to being overloaded by faster signals.

The number of pulses over time can be used for rough frequency measurements.

Consecutive High and low periods can be used to calculate duty cycle, although there is no indication whether high or low was most recent.

Definition at line 82 of file SerialWombatPulseTimer.h.

## Constructor & Destructor Documentation

## ◆ SerialWombatPulseTimer()

SerialWombatPulseTimer::SerialWombatPulseTimer | ( | SerialWombatChip & | serialWombat | ) |
| inline

Class constructor for SerialWombatPulseTimer.

Parameters

  serialWombat | The Serial Wombat chip on which the SerialWombatPulseTimer pinmode will be run

Definition at line 89 of file SerialWombatPulseTimer.h.

## Member Function Documentation

## ◆ begin()

int16_t SerialWombatPulseTimer::begin | ( | uint8_t | pin,
|  | SerialWombatPulseTimerUnits | units = SW_PULSETIMER_uS,
|  | bool | pullUpEnabled = false )
| inline

Initialization routine for SerialWombatPulseTimer.

Parameters

  pin | The Serial Wombat pin used for pulse measurments. All 4 pins on the SW4A/SW4B and all 20 pins on the SW18AB may be used.
  units | SW_PULSETIMER_uS or SW_PULSETIMER_mS. Default uS
  pullUpEnabled | TRUE = Pull Up Enabled, FALSE = Pull Up Disabled. Default disabled.

Definition at line 100 of file SerialWombatPulseTimer.h.

## ◆ readHighCounts()

uint16_t SerialWombatPulseTimer::readHighCounts | ( |  | ) |
| inline

Definition at line 160 of file SerialWombatPulseTimer.h.

## ◆ readLowCounts()

uint16_t SerialWombatPulseTimer::readLowCounts | ( |  | ) |
| inline

Definition at line 172 of file SerialWombatPulseTimer.h.

## ◆ readPulses()

uint16_t SerialWombatPulseTimer::readPulses | ( |  | ) |
| inline

Definition at line 186 of file SerialWombatPulseTimer.h.

## ◆ refresh()

void SerialWombatPulseTimer::refresh | ( |  | ) |
| inline

Retreive the latest values for HighCounts, LowCounts, Pulses, and MeasurementOverflowOccured.

This happens in two packets to the Serial Wombat chip, so data may not be coherent

Definition at line 112 of file SerialWombatPulseTimer.h.

## ◆ refreshHighCountsLowCounts()

void SerialWombatPulseTimer::refreshHighCountsLowCounts | ( |  | ) |
| inline

Retreive the High and Low counts from the Serial Wombat chip in a single transaction.

This command will retreive consecutive high and low periods from the Serial Wombat chip. It it not guaranteed which is the most recent.

Definition at line 130 of file SerialWombatPulseTimer.h.

## ◆ refreshHighCountsPulses()

void SerialWombatPulseTimer::refreshHighCountsPulses | ( |  | ) |
| inline

Definition at line 145 of file SerialWombatPulseTimer.h.

## Member Data Documentation

## ◆ HighCounts

uint16_t SerialWombatPulseTimer::HighCounts = 0

Definition at line 197 of file SerialWombatPulseTimer.h.

## ◆ LowCounts

uint16_t SerialWombatPulseTimer::LowCounts = 0

Definition at line 203 of file SerialWombatPulseTimer.h.

## ◆ MeasurementOverflowOccurred

bool SerialWombatPulseTimer::MeasurementOverflowOccurred = false

Definition at line 211 of file SerialWombatPulseTimer.h.

## ◆ Pulses

uint16_t SerialWombatPulseTimer::Pulses = 0

Definition at line 210 of file SerialWombatPulseTimer.h.