Mark Uckermann / DtPWM
Revision:
2:1ef7ff2f120e
Parent:
0:f4cf8380dbee
Child:
3:d7b9697768d8
--- a/DtPWM.h	Tue Mar 28 11:20:52 2017 +0000
+++ b/DtPWM.h	Wed Mar 29 12:34:52 2017 +0000
@@ -3,10 +3,38 @@
 #ifndef DTPWM_H
 #define DTPWM_H
 
-/** Library for fast and high resolution opposite PWM output with 
-  * controllable dead times
-  */
-  
+/** 
+* 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:
     /**
@@ -17,6 +45,17 @@
     DtPWM(bool led = false);
     ~DtPWM(); 
     
+    
+    /**
+    * enable pin outputs and start the timer
+    */
+    void enable();
+    
+    /**
+    * set output pins to low as fast as possible and stop the timer
+    */
+    void disable();
+    
     /**
     * Set the period, duty cycle, and dead time.
     *
@@ -27,12 +66,21 @@
     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;
     
     /**
-    * Fast way to change the duty cycle.
+    * Function to just set the duty cycle.
     *
     * @param d - duty cycle from 0-1 as float no checking is done in this function
     */