Mark Uckermann / DtPWM
Revision:
3:d7b9697768d8
Parent:
2:1ef7ff2f120e
Child:
4:a490a36f1cb1
diff -r 1ef7ff2f120e -r d7b9697768d8 DtPWM.cpp
--- a/DtPWM.cpp	Wed Mar 29 12:34:52 2017 +0000
+++ b/DtPWM.cpp	Tue Apr 04 22:20:38 2017 +0000
@@ -1,17 +1,14 @@
 #include "DtPWM.h"
 
-DtPWM::DtPWM(bool led){
+DtPWM::DtPWM(bool enabled){
     LPC_SC->PCONP|=(1<<6);                          //enable power on PWM1
     LPC_SC->PCLKSEL0|=(1<<12);                      //run PWM1 clock at prescaler 1 (96MHz)
     
-                                           
     
-    
-    // enable LED output as well
-    if (led) {
-        LPC_PINCON->PINSEL3|=(2<<14) | (2<<8); 
-        LPC_PINCON->PINMODE3|=(2<<14) | (2<<8);  
-    }
+    /* enable LED output as well
+    LPC_PINCON->PINSEL3|=(2<<14) | (2<<8); 
+    LPC_PINCON->PINMODE3|=(2<<14) | (2<<8);  
+    */
     
     
     LPC_PWM1->MCR|=(1<<1);   //no interrupt, no reset, no stop at TC compare match
@@ -26,8 +23,12 @@
     
     LPC_PWM1->TCR|= (1<<3);     //enable PWM timer mode
     
-    enable(); //enable output
-
+    if (enabled) {
+        enable(); //enable output
+    }
+    else {
+        disable();
+    }
 }
 
 
@@ -48,11 +49,22 @@
     
 }
 
-void DtPWM::enable() {
+void DtPWM::enable(char channel) {
+    
+    LPC_PINCON->PINSEL4 |= (1<<6) | (1<<2);   //PWM on channel 2 and 4 (GPIO P2.1, P2.3)
+    LPC_PINCON->PINMODE4 |= (2<<6) | (2<<2);  //no pull ups/pull downs 
     
-    LPC_PINCON->PINSEL4|=(1<<6) | (1<<2);   //PWM on channel 2 and 4 (GPIO P2.1, P2.3)
-    LPC_PINCON->PINMODE4|=(2<<6) | (2<<2);  //no pull ups/pull downs 
-    LPC_PWM1->PCR|=(1<<12) | (1<<10);       // enable PWM output 2 & 4;
+    if( channel == 'h' ) {
+        LPC_PWM1->PCR &= ~(1<<12);      // disable PWM output 4
+        LPC_PWM1->PCR |= (1<<10);       // enable PWM output 2     
+    }
+    else if( channel == 'l' ) {
+        LPC_PWM1->PCR &= ~(1<<10);      // disable PWM output 2
+        LPC_PWM1->PCR |= (1<<12);       // enable PWM output 4    
+    }
+    else if( channel == 'a' ) {
+        LPC_PWM1->PCR |= (1<<12) | (1<<10);       // enable PWM output 2 & 4;
+    }
     
     // set PGIO on these pins to low for fast PWM turn off
     LPC_GPIO2->FIODIR0 |= (1 << 1) | (1 << 3); // set P2.1 & P2.3 as outputs