myWRIO
C++ framework for NationalInstruments myRIO
myRIO::PWM Class Reference

Outputs a PWM signal (3.3V) More...

#include <PWM.h>

Public Member Functions

 PWM (uint32_t out, double frequency, double duty_cycle, short prescaler=0b110)
 Create PWM signal. More...
 
void setDutyCycle (double dutyCycle)
 Set the Duty Cycle. More...
 
void setPrescaler (short prescaler)
 Set the clock prescaler Will try to keep the old frequency. More...
 
void setFrequency (double frequency)
 Set the Frequency Will try to keep the current duty cycle. More...
 
 ~PWM ()
 Destructor Desactivate the channel. More...
 

Private Attributes

uint32_t out
 Pin PWM. More...
 
uint16_t max
 Max value that the PWM counts the counter that generates the PWM signal counts up to the max value to generate the signal that we want. More...
 
double dutyCycle
 PWM Duty Cycle. More...
 
double frequency
 PWM Frequency. More...
 
uint16_t prescaler
 PWM Clock prescaler. More...
 
uint32_t outcs
 PWM Clock Select register. More...
 
uint32_t outmax
 PWM Max register. More...
 
uint32_t outcmp
 PWM Compare register. More...
 

Detailed Description

Outputs a PWM signal (3.3V)

Examples
example_pwm.cpp, and project_car.cpp.

Definition at line 33 of file PWM.h.

Constructor & Destructor Documentation

◆ PWM()

PWM::PWM ( uint32_t  out,
double  frequency,
double  duty_cycle,
short  prescaler = 0b110 
)

Create PWM signal.

Parameters
outthe pin where the PWM signal will be created (PWM0, PWM1)
frequencythe frequency of the PWM signal
duty_cyclethe duty cycle of the signal; for 50%, duty_cycle = 50
prescalerthe clock prescaler. Must be a power of 2 between 1 and 64 in bits : 0b001 = 1, 0b010 = 2, 0b011 = 4...

Definition at line 12 of file PWM.cpp.

◆ ~PWM()

PWM::~PWM ( )

Destructor Desactivate the channel.

Definition at line 132 of file PWM.cpp.

Member Function Documentation

◆ setDutyCycle()

void PWM::setDutyCycle ( double  dutyCycle)

Set the Duty Cycle.

Parameters
dutyCyclethe duty cycle to set

Definition at line 103 of file PWM.cpp.

◆ setFrequency()

void PWM::setFrequency ( double  frequency)

Set the Frequency Will try to keep the current duty cycle.

Parameters
frequencythe frequency to set

Definition at line 112 of file PWM.cpp.

◆ setPrescaler()

void PWM::setPrescaler ( short  clockDiv)

Set the clock prescaler Will try to keep the old frequency.

Parameters
clockDivthe prescaler. Must be 1, 2, 4, 8, 16, 32 or 64

Definition at line 124 of file PWM.cpp.

Member Data Documentation

◆ dutyCycle

double myRIO::PWM::dutyCycle
private

PWM Duty Cycle.

Definition at line 44 of file PWM.h.

◆ frequency

double myRIO::PWM::frequency
private

PWM Frequency.

Definition at line 45 of file PWM.h.

◆ max

uint16_t myRIO::PWM::max
private

Max value that the PWM counts the counter that generates the PWM signal counts up to the max value to generate the signal that we want.

Definition at line 42 of file PWM.h.

◆ out

uint32_t myRIO::PWM::out
private

Pin PWM.

Definition at line 41 of file PWM.h.

◆ outcmp

uint32_t myRIO::PWM::outcmp
private

PWM Compare register.

Definition at line 49 of file PWM.h.

◆ outcs

uint32_t myRIO::PWM::outcs
private

PWM Clock Select register.

Definition at line 47 of file PWM.h.

◆ outmax

uint32_t myRIO::PWM::outmax
private

PWM Max register.

Definition at line 48 of file PWM.h.

◆ prescaler

uint16_t myRIO::PWM::prescaler
private

PWM Clock prescaler.

Definition at line 46 of file PWM.h.


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