fsdfds
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
DynamicPwm Class Reference
Class definition for DynamicPwm. More...
#include <DynamicPwm.h>
Public Member Functions | |
void | redirect (PinName pin) |
Redirects the pwm channel to point at a different pin. | |
void | release () |
Frees this DynamicPwm instance for reuse. | |
int | write (float value) |
A lightweight wrapper around the super class' write in order to capture the value. | |
PinName | getPinName () |
Retreives the PinName associated with this DynamicPwm instance. | |
int | getValue () |
Retreives the last value that has been written to this DynamicPwm instance. | |
int | getPeriodUs () |
Retreives the current period in use by the entire PWM module in microseconds. | |
int | getPeriod () |
Retreives the current period in use by the entire PWM module in milliseconds. | |
int | setPeriodUs (int period) |
Sets the period used by the WHOLE PWM module. | |
int | setPeriod (int period) |
Sets the period used by the WHOLE PWM module. | |
Static Public Member Functions | |
static DynamicPwm * | allocate (PinName pin, PwmPersistence persistence=PWM_PERSISTENCE_TRANSIENT) |
Creates a new DynamicPwm instance, or reuses an existing instance that has a persistence level of PWM_PERSISTENCE_TRANSIENT. |
Detailed Description
Class definition for DynamicPwm.
This class addresses a few issues found in the underlying libraries. This provides the ability for a neat, clean swap between PWM channels.
Definition at line 47 of file DynamicPwm.h.
Member Function Documentation
DynamicPwm * allocate | ( | PinName | pin, |
PwmPersistence | persistence = PWM_PERSISTENCE_TRANSIENT |
||
) | [static] |
Creates a new DynamicPwm instance, or reuses an existing instance that has a persistence level of PWM_PERSISTENCE_TRANSIENT.
- Parameters:
-
pin the name of the pin for the pwm to target persistance the level of persistence for this pin PWM_PERSISTENCE_PERSISTENT (can not be replaced until freed, should only be used for system services really.) or PWM_PERSISTENCE_TRANSIENT (can be replaced at any point if a channel is required.)
- Returns:
- a pointer to the first available free pwm channel - or the first one that can be reallocated. If no channels are available, NULL is returned.
DynamicPwm* pwm = DynamicPwm::allocate(PinName n);
Definition at line 129 of file DynamicPwm.cpp.
int getPeriod | ( | ) |
Retreives the current period in use by the entire PWM module in milliseconds.
Example:
DynamicPwm* pwm = DynamicPwm::allocate(PinName n); pwm->setPeriodUs(20000); // will return 20000 pwm->getPeriod();
Definition at line 278 of file DynamicPwm.cpp.
int getPeriodUs | ( | ) |
Retreives the current period in use by the entire PWM module in microseconds.
Example:
DynamicPwm* pwm = DynamicPwm::allocate(PinName n); pwm->getPeriod();
Definition at line 261 of file DynamicPwm.cpp.
PinName getPinName | ( | ) |
Retreives the PinName associated with this DynamicPwm instance.
DynamicPwm* pwm = DynamicPwm::allocate(PinName n); // returns the PinName n. pwm->getPinName();
- Note:
- This should be used to check that the DynamicPwm instance has not been reallocated for use in another part of a program.
Definition at line 230 of file DynamicPwm.cpp.
int getValue | ( | ) |
Retreives the last value that has been written to this DynamicPwm instance.
in the range 0 - 1023 inclusive.
DynamicPwm* pwm = DynamicPwm::allocate(PinName n); pwm->write(0.5); // will return 512. pwm->getValue();
Definition at line 247 of file DynamicPwm.cpp.
void redirect | ( | PinName | pin ) |
Redirects the pwm channel to point at a different pin.
- Parameters:
-
pin the desired pin to output a PWM wave.
DynamicPwm* pwm = DynamicPwm::allocate(PinName n); pwm->redirect(p0); // pwm is now produced on p0
Definition at line 107 of file DynamicPwm.cpp.
void release | ( | ) |
Frees this DynamicPwm instance for reuse.
DynamicPwm* pwm = DynamicPwm::allocate(); pwm->release();
Definition at line 178 of file DynamicPwm.cpp.
int setPeriod | ( | int | period ) |
Sets the period used by the WHOLE PWM module.
Any changes to the period will AFFECT ALL CHANNELS.
- Parameters:
-
period the desired period in milliseconds.
- Returns:
- MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if period is out of range
Example:
DynamicPwm* pwm = DynamicPwm::allocate(PinName n); // period now is 20ms pwm->setPeriod(20);
Definition at line 328 of file DynamicPwm.cpp.
int setPeriodUs | ( | int | period ) |
Sets the period used by the WHOLE PWM module.
- Parameters:
-
period the desired period in microseconds.
- Returns:
- MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if period is out of range
Example:
DynamicPwm* pwm = DynamicPwm::allocate(PinName n); // period now is 20ms pwm->setPeriodUs(20000);
- Note:
- Any changes to the period will AFFECT ALL CHANNELS.
Definition at line 300 of file DynamicPwm.cpp.
int write | ( | float | value ) |
A lightweight wrapper around the super class' write in order to capture the value.
- Parameters:
-
value the duty cycle percentage in floating point format.
- Returns:
- MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range
DynamicPwm* pwm = DynamicPwm::allocate(); pwm->write(0.5);
Definition at line 206 of file DynamicPwm.cpp.
Generated on Wed Jul 13 2022 00:58:03 by 1.7.2