Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DtPWM.h
- Committer:
- dontknowhow
- Date:
- 2017-04-04
- Revision:
- 3:d7b9697768d8
- Parent:
- 2:1ef7ff2f120e
- Child:
- 4:a490a36f1cb1
File content as of revision 3:d7b9697768d8:
#include "mbed.h"
#ifndef DTPWM_H
#define DTPWM_H
/**
* Library for fast and high resolution opposite PWM output with
* controllable dead times
*/
/** definitions for interrupt flags, usage in IRS:
* if ( LPC_PWM1->IR & DTPWM_IF0 ) {
* // do something on MR0 interrupt
* LPC_PWM1->IR |= DTPWM_IF0; // reset interrupt flag
* }
*/
#define DTPWM_IF0 (1 << 0U)
#define DTPWM_IF1 (1 << 1U)
#define DTPWM_IF2 (1 << 2U)
#define DTPWM_IF3 (1 << 3U)
#define DTPWM_IF4 (1 << 8U)
#define DTPWM_IF5 (1 << 9U)
#define DTPWM_IF6 (1 << 10U)
/** definitions for interrupt enable flags, usage:
* pwm.setInterrupts(DTPWM_SI0 | DTPWM_SI5); //to set MR0 & MR5 interrupts
*/
#define DTPWM_SI0 (1 << 0U)
#define DTPWM_SI1 (1 << 3U)
#define DTPWM_SI2 (1 << 6U)
#define DTPWM_SI3 (1 << 9U)
#define DTPWM_SI4 (1 << 12U)
#define DTPWM_SI5 (1 << 15U)
#define DTPWM_SI6 (1 << 18U)
#define DTPWM_SIA (DTPWM_SI0 | DTPWM_SI1 | DTPWM_SI2 | DTPWM_SI3 | DTPWM_SI4 | DTPWM_SI5 | DTPWM_SI6)
class DtPWM{
public:
/**
* Create a dtPWM object connected to channel 2 and 4, optionally to LED 2&4
*
* @param ebaled - start pwm enabled, output as soon as object is created (default)
*/
DtPWM(bool enable = true);
/**
* enable pin outputs and start the timer
*
* @channel - determines which channels are enabled.
* 'h' for high (PWM1.2)
* 'l' for low (PWM1.4)
* 'a' for both (PWM1.2 & 1.4) (default)
*/
void enable(char channel = 'a');
/**
* set output pins to low as fast as possible and stop the timer
*/
void disable();
/**
* Set the period, duty cycle, and dead time.
*
* @param p_us - period in micro seconds
* @param d - duty cycle from 0-1 as float
* @param dt_us - dead time between switching in micro seconds
*/
void setDtPWM(double p_us, float d, double dt_us);
/**
* Set which interrupts are enabled
*
* @param flags - OR'd bits for the interrupt register, 0 to disable interrupts
* use the definitions eg. pwm.setInterrupts(DTPWM_SI0 | DTPWM_SI5); to set MR0 & MR5
* @param priority - set interrupt priority level. -1 (default) leaves them unchanged
*/
void setInterrupts(uint32_t flags, int prio = -1);
/**
* Value for maximum duty cycle that fulfils minimum dead times
*/
float d_max;
/**
* Function to just set the duty cycle.
*
* @param d - duty cycle from 0-1 as float no checking is done in this function
*/
void setD(float d);
private:
unsigned int p_tcks; // clock ticks in period
unsigned int dt_tcks; // dead time ticks
};
#endif