123

Dependencies:   mbed

Fork of LG by igor Apu

Revision:
149:abbf7663d27d
Child:
156:e68ee0bcdcda
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DeviceDither.c	Tue May 03 05:12:26 2016 +0000
@@ -0,0 +1,48 @@
+#include "Device.h"
+extern Device device;
+
+void InitDitherWithDefaults(void){
+  device.dither.settings.enabled = 1;
+  device.dither.settings.rise = 32;
+  device.dither.settings.fall = 64;
+  device.dither.settings.oscillationFrequencyLoop = 1;
+  device.dither.settings.outputFrequencyLoop = 1;
+}
+
+void InitDither(void){
+  device.dither.state.enabled = device.dither.settings.enabled;
+  device.dither.state.rise = device.dither.settings.rise;
+  device.dither.state.fall = device.dither.settings.fall;
+  device.dither.state.inPeriodCounter = 0;
+  device.dither.state.counter100kHz = 0;
+  device.dither.state.pin1 = 0;
+  device.dither.state.pin2 = 0;
+  device.dither.state.oscillationFrequencyLoop = device.dither.settings.oscillationFrequencyLoop;
+  device.dither.state.outputFrequencyLoop = device.dither.settings.outputFrequencyLoop;
+}
+
+void StartDither(void){
+}
+
+void DitherCycle(void){
+  uint8_t pin1, pin2;
+  if ((device.dither.state.counter100kHz > device.dither.settings.rise) && (device.dither.state.counter100kHz < device.dither.settings.fall)){
+    pin1 = 1; pin2 = 1;  
+  } else {
+    pin1 = 0; pin2 = 0;
+  }
+  if (device.dither.state.inPeriodCounter < 16){
+      pin2 = 0;
+  } else {
+      pin1 = 0;
+  }
+  if (!device.dither.state.enabled) {
+    pin1 = 0; pin2 = 0;
+  }
+  if (pin1 > device.dither.state.pin1) LPC_GPIO1->FIOCLR = 1<<25;
+  if (pin1 < device.dither.state.pin1) LPC_GPIO1->FIOSET = 1<<25;
+  if (pin2 > device.dither.state.pin2) LPC_GPIO1->FIOCLR = 1<<28;
+  if (pin2 < device.dither.state.pin2) LPC_GPIO1->FIOSET = 1<<28;
+  device.dither.state.pin1 = pin1;
+  device.dither.state.pin2 = pin2;
+}
\ No newline at end of file