Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions
exploringBB::PWM Class Reference

A class to control a basic PWM output – you must know the exact sysfs filename for the PWM output. More...

#include <PWM.h>

Inheritance diagram for exploringBB::PWM:
Inheritance graph
[legend]

Public Types

enum  POLARITY { ACTIVE_LOW =0, ACTIVE_HIGH =1 }
 

Public Member Functions

 PWM (string pinName)
 
virtual int setPeriod (unsigned int period_ns)
 
virtual unsigned int getPeriod ()
 
virtual int setFrequency (float frequency_hz)
 
virtual float getFrequency ()
 
virtual int setDutyCycle (unsigned int duration_ns)
 
virtual int setDutyCycle (float percentage)
 
virtual unsigned int getDutyCycle ()
 
virtual float getDutyCyclePercent ()
 
virtual int setPolarity (PWM::POLARITY)
 
virtual void invertPolarity ()
 
virtual PWM::POLARITY getPolarity ()
 
virtual void setAnalogFrequency (float frequency_hz)
 
virtual int calibrateAnalogMax (float analogMax)
 
virtual int analogWrite (float voltage)
 
virtual int run ()
 
virtual bool isRunning ()
 
virtual int stop ()
 
virtual ~PWM ()
 

Detailed Description

A class to control a basic PWM output – you must know the exact sysfs filename for the PWM output.

Member Enumeration Documentation

Enumerator
ACTIVE_LOW 
ACTIVE_HIGH 
45 { ACTIVE_LOW=0, ACTIVE_HIGH=1 };
Definition: PWM.h:45
Definition: PWM.h:45

Constructor & Destructor Documentation

exploringBB::PWM::PWM ( string  pinName)
31  {
32  this->name = pinName;
33  this->path = PWM_PATH + this->name + "/";
34  this->analogFrequency = 100000;
35  this->analogMax = 3.3;
36 }
#define PWM_PATH
Definition: PWM.h:30
exploringBB::PWM::~PWM ( )
virtual
127 {}

Member Function Documentation

int exploringBB::PWM::analogWrite ( float  voltage)
virtual
106  {
107  if ((voltage<0.0f)||(voltage>3.3f)) return -1;
108  this->setFrequency(this->analogFrequency);
110  this->setDutyCycle((100.0f*voltage)/this->analogMax);
111  return this->run();
112 }
virtual int setDutyCycle(unsigned int duration_ns)
Definition: PWM.cpp:64
virtual int setFrequency(float frequency_hz)
Definition: PWM.cpp:56
virtual int run()
Definition: PWM.cpp:114
virtual int setPolarity(PWM::POLARITY)
Definition: PWM.cpp:86
Definition: PWM.h:45
int exploringBB::PWM::calibrateAnalogMax ( float  analogMax)
virtual
100  { //must be between 3.2 and 3.4
101  if((analogMax<3.2f) || (analogMax>3.4f)) return -1;
102  else this->analogMax = analogMax;
103  return 0;
104 }
unsigned int exploringBB::PWM::getDutyCycle ( )
virtual
76  {
77  return atoi(read(this->path, PWM_DUTY).c_str());
78 }
string read(string path, string filename)
Definition: util.cpp:57
#define PWM_DUTY
Definition: PWM.h:32
float exploringBB::PWM::getDutyCyclePercent ( )
virtual
80  {
81  unsigned int period_ns = this->getPeriod();
82  unsigned int duty_ns = this->getDutyCycle();
83  return 100.0f * (float)duty_ns/(float)period_ns;
84 }
virtual unsigned int getPeriod()
Definition: PWM.cpp:42
virtual unsigned int getDutyCycle()
Definition: PWM.cpp:76
float exploringBB::PWM::getFrequency ( )
virtual
60  {
61  return this->period_nsToFrequency(this->getPeriod());
62 }
virtual unsigned int getPeriod()
Definition: PWM.cpp:42
unsigned int exploringBB::PWM::getPeriod ( )
virtual
42  {
43  return atoi(read(this->path, PWM_PERIOD).c_str());
44 }
#define PWM_PERIOD
Definition: PWM.h:31
string read(string path, string filename)
Definition: util.cpp:57
PWM::POLARITY exploringBB::PWM::getPolarity ( )
virtual
95  {
96  if (atoi(read(this->path, PWM_POLARITY).c_str())==0) return PWM::ACTIVE_LOW;
97  else return PWM::ACTIVE_HIGH;
98 }
Definition: PWM.h:45
#define PWM_POLARITY
Definition: PWM.h:33
Definition: PWM.h:45
string read(string path, string filename)
Definition: util.cpp:57
void exploringBB::PWM::invertPolarity ( )
virtual
90  {
92  else this->setPolarity(PWM::ACTIVE_LOW);
93 }
virtual PWM::POLARITY getPolarity()
Definition: PWM.cpp:95
Definition: PWM.h:45
virtual int setPolarity(PWM::POLARITY)
Definition: PWM.cpp:86
Definition: PWM.h:45
bool exploringBB::PWM::isRunning ( )
virtual
118  {
119  string running = read(this->path, PWM_RUN);
120  return (running=="1");
121 }
#define PWM_RUN
Definition: PWM.h:34
string read(string path, string filename)
Definition: util.cpp:57
int exploringBB::PWM::run ( )
virtual
114  {
115  return write(this->path, PWM_RUN, 1);
116 }
int write(string path, string filename, string value)
Definition: util.cpp:40
#define PWM_RUN
Definition: PWM.h:34
virtual void exploringBB::PWM::setAnalogFrequency ( float  frequency_hz)
inlinevirtual
68 { this->analogFrequency = frequency_hz; }
int exploringBB::PWM::setDutyCycle ( unsigned int  duration_ns)
virtual
64  {
65  return write(this->path, PWM_DUTY, duty_ns);
66 }
int write(string path, string filename, string value)
Definition: util.cpp:40
#define PWM_DUTY
Definition: PWM.h:32
int exploringBB::PWM::setDutyCycle ( float  percentage)
virtual
68  {
69  if ((percentage>100.0f)||(percentage<0.0f)) return -1;
70  unsigned int period_ns = this->getPeriod();
71  float duty_ns = period_ns * (percentage/100.0f);
72  this->setDutyCycle((unsigned int) duty_ns );
73  return 0;
74 }
virtual int setDutyCycle(unsigned int duration_ns)
Definition: PWM.cpp:64
virtual unsigned int getPeriod()
Definition: PWM.cpp:42
int exploringBB::PWM::setFrequency ( float  frequency_hz)
virtual
56  {
57  return this->setPeriod(this->frequencyToPeriod_ns(frequency_hz));
58 }
virtual int setPeriod(unsigned int period_ns)
Definition: PWM.cpp:38
int exploringBB::PWM::setPeriod ( unsigned int  period_ns)
virtual
38  {
39  return write(this->path, PWM_PERIOD, period_ns);
40 }
#define PWM_PERIOD
Definition: PWM.h:31
int write(string path, string filename, string value)
Definition: util.cpp:40
int exploringBB::PWM::setPolarity ( PWM::POLARITY  polarity)
virtual
86  {
87  return write(this->path, PWM_POLARITY, polarity);
88 }
int write(string path, string filename, string value)
Definition: util.cpp:40
#define PWM_POLARITY
Definition: PWM.h:33
int exploringBB::PWM::stop ( )
virtual
123  {
124  return write(this->path, PWM_RUN, 0);
125 }
int write(string path, string filename, string value)
Definition: util.cpp:40
#define PWM_RUN
Definition: PWM.h:34

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