PWM Class Reference

#include <PWM.h>

Inheritance diagram for PWM:

Inheritance graph
[legend]
Collaboration diagram for PWM:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 PWM (unsigned channel)
 PWM (unsigned slot, unsigned channel)
virtual ~PWM ()
void SetRaw (unsigned char value)
unsigned char GetRaw (void)
void SetPeriodMultiplier (PeriodMultiplier mult)

Protected Member Functions

void SetMaxPositivePwm (int maxPositivePwm)
 The maximum raw PWM value for forward direction.
void SetMinPositivePwm (int minPositivePwm)
 The minimum raw PWM value for forward direction.
void SetCenterPwm (int centerPwm)
 The raw PWM value that represents idle.
void SetMaxNegativePwm (int maxNegativePwm)
 The maximum raw PWM value for reverse direction.
void SetMinNegativePwm (int minNegativePwm)
 The minimum raw PWM value for reverse direction.
void SetPosition (float pos)
float GetPosition (void)
void SetSpeed (float speed)
float GetSpeed (void)

Static Protected Attributes

static const unsigned kDefaultPwmPeriod = 766
static const unsigned kDefaultMinPwmHigh = 103


Detailed Description

Class implements the PWM generation in the FPGA. Values supplied as arguments for PWM outputs range from -1.0 to 1.0. They are mapped to the hardware dependent values, in this case 0-255 for the FPGA. Changes are immediately sent to the FPGA, and the update occurs at the next FPGA cycle. There is no delay.

As of revision 0.1.4 of the FPGA, the FPGA interprets the 0-255 values as follows: 255 = full "forward" 254 to 129 = linear scaling from "full forward" to "center" 128 = center value 127 to 2 = linear scaling from "center" to "full reverse" 1 = full "reverse" 0 = disabled (i.e. PWM output is held low)


Constructor & Destructor Documentation

PWM::PWM ( unsigned  channel  ) 

Allocate a PWM in the default module give a channel. Using a default module allocate a PWM given the channel number. The default module is the first slot numerically in the cRIO chassis.

Parameters:
channel The PWM channel on the digital module.

PWM::PWM ( unsigned  slot,
unsigned  channel 
)

Allocate a PWM given a module and channel. Allocate a PWM using a module and channel number.

Parameters:
slot The slot the digital module is plugged into.
channel The PWM channel on the digital module.

PWM::~PWM (  )  [virtual]

Free the PWM channel. Free the resource associated with the PWM channel and set the value to 0.


Member Function Documentation

void PWM::SetRaw ( unsigned char  value  ) 

Set the PWM value directly to the hardware.

Write a raw value to a PWM channel.

Parameters:
value Raw PWM value. Range 0 - 255.

unsigned char PWM::GetRaw ( void   ) 

Get the PWM value directly from the hardware.

Read a raw value from a PWM channel.

Returns:
Raw PWM control value. Range: 0 - 255.

void PWM::SetPeriodMultiplier ( PeriodMultiplier  mult  ) 

Slow down the PWM signal for old devices.

Parameters:
mult The period multiplier to apply to this channel

void PWM::SetPosition ( float  pos  )  [protected]

Set the PWM value based on a position.

This is intended to be used by servos.

Precondition:
SetMaxPositivePwm() called.

SetMinNegativePwm() called.

Parameters:
pos The position to set the servo between 0.0 and 1.0.

float PWM::GetPosition ( void   )  [protected]

Get the PWM value in terms of a position.

This is intended to be used by servos.

Precondition:
SetMaxPositivePwm() called.

SetMinNegativePwm() called.

Returns:
The position the servo is set to between 0.0 and 1.0.

void PWM::SetSpeed ( float  speed  )  [protected]

Set the PWM value based on a speed.

This is intended to be used by speed controllers.

Precondition:
SetMaxPositivePwm() called.

SetMinPositivePwm() called.

SetCenterPwm() called.

SetMaxNegativePwm() called.

SetMinNegativePwm() called.

Parameters:
speed The speed to set the speed controller between -1.0 and 1.0.

float PWM::GetSpeed ( void   )  [protected]

Get the PWM value in terms of speed.

This is intended to be used by speed controllers.

Precondition:
SetMaxPositivePwm() called.

SetMinPositivePwm() called.

SetMaxNegativePwm() called.

SetMinNegativePwm() called.

Returns:
The most recently set speed between -1.0 and 1.0.


Member Data Documentation

const unsigned PWM::kDefaultPwmPeriod = 766 [static, protected]

kDefaultPwmPeriod is "ticks" where each tick is 6.525us 20ms periods (50 Hz) are the "safest" setting in that this works for all devices 20ms periods seem to be desirable for Vex Motors 20ms periods are the specified period for HS-322HD servos, but work reliably down to 10.0 ms; starting at about 8.5ms, the servo sometimes hums and get hot; by 5.0ms the hum is nearly continuous 10ms periods work well for Victor 884 5ms periods allows higher update rates for Luminary Micro Jaguar speed controllers

This is the 1x period (5ms). In hardware, the period scaling is implemented as an output squelch to get longer periods for old devices. Set to 5 ms period / 6.525us clock = 766

const unsigned PWM::kDefaultMinPwmHigh = 103 [static, protected]

kDefaultMinPwmHigh is "ticks" where each tick is 6.525us There are 127 pwm values less than the center, so... The minimum output pulse length is 1.5ms - 127 * 6.525us = 0.671ms 0.671ms / 6.525us per tick = 103


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

Generated on Thu Oct 2 14:01:29 2008 for WPI Robotics Library by  doxygen 1.5.5