libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
PulseWidthReader Class Reference

Record high and low times simultaniously on any number of pins. More...

#include <pulse_width_reader.h>

Public Member Functions

 PulseWidthReader ()
 
void Start (unsigned int Inputmask)
 Launch a new cog to watch and record pulse times. More...
 
void Stop (void)
 Free a cog if running. More...
 
int getHighTime (int index)
 Get the most recent high pulse duration. More...
 
int getLowTime (int index)
 Get the most recent low pulse duration. More...
 

Detailed Description

Record high and low times simultaniously on any number of pins.

Based on ReadPulseWidths.spin v1.0 by David Carrier. Thanks!

Hardware: To read 3.3v signals just connect the signal directly to any I/O pin. To read a 5v signal connect it to any I/O pin through a 3.3kOhm (or higher) resistor. To read a higher voltage, use the following equation to determine the proper series voltage: resistance = (voltage - 3.3v - 0.6v) / 500uA

Example: To use this object, first construct a mask of the pins you are interested in monitoring (in this case pins 2, 10, and 21): mask = (1 << 2) | (1 << 10) | (1 << 21) Then start it: PulseWidthReader pwr(); pwr.Start(mask);

When you want the data simply call: pwr.GetHighTime(2);

The index is the index of the monitored pin out of the count total. In this example the index is: Index | pin 0| 2 1| 10 2| 21

Copyright (c) 2013 Kenneth Bedolla (libpr.nosp@m.opel.nosp@m.ler@k.nosp@m.enne.nosp@m.thbed.nosp@m.olla.nosp@m..com)

Todo:

(SRLM): Make members of this class static (since it monitors all the pins...)

(SRLM): Get rid of the terrible "index" system and create a more intuitive start.

(SRLM): Are there any restrictions? Maximum time? Minimum pulse width? etc.

(SRLM): This class seems to have intermittent test failures when run for the first time. A bug?

Constructor & Destructor Documentation

PulseWidthReader::PulseWidthReader ( )
inline

Member Function Documentation

int PulseWidthReader::getHighTime ( int  index)
inline

Get the most recent high pulse duration.

Index starts at 0.

Parameters
indexThe index (from low to high) of the desired pin (out of all the monitored pins)
Returns
The number of clock cycles of the last high pulse.
int PulseWidthReader::getLowTime ( int  index)
inline

Get the most recent low pulse duration.

Index starts at 0.

Parameters
indexThe index (from low to high) of the desired pin (out of all the monitored pins)
Returns
The number of clock cycles of the last low pulse.
void PulseWidthReader::Start ( unsigned int  Inputmask)
inline

Launch a new cog to watch and record pulse times.

Parameters
InputmaskThe mask of pins to watch.

Here is the call graph for this function:

void PulseWidthReader::Stop ( void  )
inline

Free a cog if running.


The documentation for this class was generated from the following file: