PikeAero::CBinaryInputOutputPWM Class Reference

Implements a binary input / output pin wired to a PWM. More...

#include <cbinaryinputoutputpwm.h>

Inheritance diagram for PikeAero::CBinaryInputOutputPWM:

Inheritance graph
[legend]
Collaboration diagram for PikeAero::CBinaryInputOutputPWM:

Collaboration graph
[legend]

Public Member Functions

 CBinaryInputOutputPWM (CMachine::InterruptVector vector, PWM_TypeDef *PWMx, CMachine::ubit32 freqency=16000, CMachine::ubit32 dutyCycle=50)
PWM_TypeDefpwm ()
bool running ()
 Is the pwm running.
CMachine::ubit16 setDutyCycle (CMachine::ubit32 dutyCycle=50)
 Calculate the duty cycle from percent. (default 50 percent).
CMachine::ubit16 setFrequency (CMachine::ubit32 frequency=16000)
 Calculate the prescaler requred to get the target frequency. Default is 16 KHz.
void start ()
 Start the pwm.
void stop ()
 Stop the pwm.
virtual ~CBinaryInputOutputPWM ()

Private Attributes

PWM_TypeDefmPWM

Detailed Description

Implements a binary input / output pin wired to a PWM.

Author:
Michael Sharkey <mike@pikeaero.com>

Definition at line 31 of file cbinaryinputoutputpwm.h.


Constructor & Destructor Documentation

PikeAero::CBinaryInputOutputPWM::CBinaryInputOutputPWM ( CMachine::InterruptVector  vector,
PWM_TypeDef PWMx,
CMachine::ubit32  freqency = 16000,
CMachine::ubit32  dutyCycle = 50 
)

Set the Prescaler

Set the duty cycle

Definition at line 24 of file cbinaryinputoutputpwm.cpp.

References PikeAero::PWM_TypeDef::IM, PikeAero::PWM_TypeDef::PEN, PikeAero::PWM_TypeDef::PLS, pwm(), setDutyCycle(), and setFrequency().

00030 : CObject()
00031 , mPWM(PWMx)
00032 {
00033     /* Diable the PWM */
00034     pwm()->PEN = 0;
00035     /* Initialize output polarity */
00036     pwm()->PLS = 0;
00037     /* Disable interrupts */
00038     pwm()->IM = 0;
00039     /** Set the Prescaler */
00040     setFrequency( frequency );
00041     /** Set the duty cycle */
00042     setDutyCycle( dutyCycle );
00043 }

Here is the call graph for this function:

PikeAero::CBinaryInputOutputPWM::~CBinaryInputOutputPWM (  )  [virtual]

Definition at line 46 of file cbinaryinputoutputpwm.cpp.

00047 {
00048 }


Member Function Documentation

PWM_TypeDef* PikeAero::CBinaryInputOutputPWM::pwm (  )  [inline]

Definition at line 42 of file cbinaryinputoutputpwm.h.

References mPWM.

Referenced by CBinaryInputOutputPWM(), running(), setDutyCycle(), setFrequency(), start(), and stop().

00042 {return mPWM;}

Here is the caller graph for this function:

bool PikeAero::CBinaryInputOutputPWM::running (  )  [inline]

Is the pwm running.

Definition at line 51 of file cbinaryinputoutputpwm.h.

References pwm(), and PWM_PE.

00051 {return (pwm()->PEN & PWM_PE) != 0;}

Here is the call graph for this function:

CMachine::ubit16 PikeAero::CBinaryInputOutputPWM::setDutyCycle ( CMachine::ubit32  dutyCycle = 50  ) 

Calculate the duty cycle from percent. (default 50 percent).

Calculate the duty cycle from percent.

Definition at line 66 of file cbinaryinputoutputpwm.cpp.

References PikeAero::PWM_TypeDef::DUT, PikeAero::PWM_TypeDef::PER, and pwm().

Referenced by CBinaryInputOutputPWM().

00067 {
00068     pwm()->DUT = (CMachine::ubit16)(pwm()->PER / (CMachine::real)( 100.0 / dutyCycle ));
00069     return pwm()->DUT;
00070 }

Here is the call graph for this function:

Here is the caller graph for this function:

CMachine::ubit16 PikeAero::CBinaryInputOutputPWM::setFrequency ( CMachine::ubit32  frequency = 16000  ) 

Calculate the prescaler requred to get the target frequency. Default is 16 KHz.

Parameters:
frequency The target frequency expressed in Hz.
Returns:
The prescaler value.

Definition at line 55 of file cbinaryinputoutputpwm.cpp.

References PikeAero::PWM_TypeDef::PER, PikeAero::PWM_TypeDef::PRS0, PikeAero::PWM_TypeDef::PRS1, pwm(), PWM_PR0, and PWM_PR1.

Referenced by CBinaryInputOutputPWM().

00056 {
00057     pwm()->PRS0 = PWM_PR0(0);                   /* (32 MHz / 1) = 32 MHz */
00058     pwm()->PRS1 = PWM_PR1(1);                   /* 32 MHz / 2 = 16 MHz */
00059     pwm()->PER = (128000 / frequency);          /* 16 MHz / frequency */
00060     return pwm()->PER;
00061 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CBinaryInputOutputPWM::start (  )  [inline]

Start the pwm.

Definition at line 45 of file cbinaryinputoutputpwm.h.

References PikeAero::PWM_TypeDef::PEN, pwm(), and PWM_PE.

Referenced by PikeAero::CTaskFuelInjection::start().

00045 {pwm()->PEN |= PWM_PE;}

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CBinaryInputOutputPWM::stop (  )  [inline]

Stop the pwm.

Definition at line 48 of file cbinaryinputoutputpwm.h.

References PikeAero::PWM_TypeDef::PEN, pwm(), and PWM_PE.

00048 {pwm()->PEN &= ~PWM_PE;}

Here is the call graph for this function:


Field Documentation

Definition at line 66 of file cbinaryinputoutputpwm.h.

Referenced by pwm().


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

Generated on Sun Oct 25 13:59:44 2009 for stingray3 by  doxygen 1.5.8