Frank Vannieuwkerke / SoftPdmOut

Dependents:   mbed-shiny

Files at this revision

API Documentation at this revision

Comitter:
frankvnk
Date:
Sun Dec 28 18:01:50 2014 +0000
Parent:
5:408b68033540
Commit message:
Dmax : Rescale level when DMAX changes.; only stop/start PulseWidth when running.

Changed in this revision

SoftPdmOut.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 408b68033540 -r 85236b955cf6 SoftPdmOut.cpp
--- a/SoftPdmOut.cpp	Sun Dec 28 15:57:53 2014 +0000
+++ b/SoftPdmOut.cpp	Sun Dec 28 18:01:50 2014 +0000
@@ -41,7 +41,14 @@
 
 void SoftPdmOut::PulseWidth(uint32_t level)
 {
-    _PulseWidth = level;
+    if(!_running)                // When pdm is inactive, only change the pulse width and don't start the pdm
+        _PulseWidth = level;
+    else
+    {
+        stop();
+        _PulseWidth = level;
+        start();
+    }
 }
 
 uint32_t SoftPdmOut::getPulseWidth(void)
@@ -51,8 +58,9 @@
 
 void SoftPdmOut::Dmax(uint32_t level)
 {
+    _Level = (uint32_t)((float)_Level * ((float)level / (float)_Dmax));  // Rescale level : level = level * (new level / current DMAX)
     _Dmax = level;
-    _accumulator  = 0;              // zero out the error accumulator
+    _accumulator  = 0;                  // zero out the error accumulator
 }
 
 uint32_t SoftPdmOut::getDmax(void)