123
Fork of LG by
DeviceDither.c@149:abbf7663d27d, 2016-05-03 (annotated)
- Committer:
- Diletant
- Date:
- Tue May 03 05:12:26 2016 +0000
- Revision:
- 149:abbf7663d27d
- Child:
- 156:e68ee0bcdcda
Device & ... update. Not final!!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Diletant | 149:abbf7663d27d | 1 | #include "Device.h" |
Diletant | 149:abbf7663d27d | 2 | extern Device device; |
Diletant | 149:abbf7663d27d | 3 | |
Diletant | 149:abbf7663d27d | 4 | void InitDitherWithDefaults(void){ |
Diletant | 149:abbf7663d27d | 5 | device.dither.settings.enabled = 1; |
Diletant | 149:abbf7663d27d | 6 | device.dither.settings.rise = 32; |
Diletant | 149:abbf7663d27d | 7 | device.dither.settings.fall = 64; |
Diletant | 149:abbf7663d27d | 8 | device.dither.settings.oscillationFrequencyLoop = 1; |
Diletant | 149:abbf7663d27d | 9 | device.dither.settings.outputFrequencyLoop = 1; |
Diletant | 149:abbf7663d27d | 10 | } |
Diletant | 149:abbf7663d27d | 11 | |
Diletant | 149:abbf7663d27d | 12 | void InitDither(void){ |
Diletant | 149:abbf7663d27d | 13 | device.dither.state.enabled = device.dither.settings.enabled; |
Diletant | 149:abbf7663d27d | 14 | device.dither.state.rise = device.dither.settings.rise; |
Diletant | 149:abbf7663d27d | 15 | device.dither.state.fall = device.dither.settings.fall; |
Diletant | 149:abbf7663d27d | 16 | device.dither.state.inPeriodCounter = 0; |
Diletant | 149:abbf7663d27d | 17 | device.dither.state.counter100kHz = 0; |
Diletant | 149:abbf7663d27d | 18 | device.dither.state.pin1 = 0; |
Diletant | 149:abbf7663d27d | 19 | device.dither.state.pin2 = 0; |
Diletant | 149:abbf7663d27d | 20 | device.dither.state.oscillationFrequencyLoop = device.dither.settings.oscillationFrequencyLoop; |
Diletant | 149:abbf7663d27d | 21 | device.dither.state.outputFrequencyLoop = device.dither.settings.outputFrequencyLoop; |
Diletant | 149:abbf7663d27d | 22 | } |
Diletant | 149:abbf7663d27d | 23 | |
Diletant | 149:abbf7663d27d | 24 | void StartDither(void){ |
Diletant | 149:abbf7663d27d | 25 | } |
Diletant | 149:abbf7663d27d | 26 | |
Diletant | 149:abbf7663d27d | 27 | void DitherCycle(void){ |
Diletant | 149:abbf7663d27d | 28 | uint8_t pin1, pin2; |
Diletant | 149:abbf7663d27d | 29 | if ((device.dither.state.counter100kHz > device.dither.settings.rise) && (device.dither.state.counter100kHz < device.dither.settings.fall)){ |
Diletant | 149:abbf7663d27d | 30 | pin1 = 1; pin2 = 1; |
Diletant | 149:abbf7663d27d | 31 | } else { |
Diletant | 149:abbf7663d27d | 32 | pin1 = 0; pin2 = 0; |
Diletant | 149:abbf7663d27d | 33 | } |
Diletant | 149:abbf7663d27d | 34 | if (device.dither.state.inPeriodCounter < 16){ |
Diletant | 149:abbf7663d27d | 35 | pin2 = 0; |
Diletant | 149:abbf7663d27d | 36 | } else { |
Diletant | 149:abbf7663d27d | 37 | pin1 = 0; |
Diletant | 149:abbf7663d27d | 38 | } |
Diletant | 149:abbf7663d27d | 39 | if (!device.dither.state.enabled) { |
Diletant | 149:abbf7663d27d | 40 | pin1 = 0; pin2 = 0; |
Diletant | 149:abbf7663d27d | 41 | } |
Diletant | 149:abbf7663d27d | 42 | if (pin1 > device.dither.state.pin1) LPC_GPIO1->FIOCLR = 1<<25; |
Diletant | 149:abbf7663d27d | 43 | if (pin1 < device.dither.state.pin1) LPC_GPIO1->FIOSET = 1<<25; |
Diletant | 149:abbf7663d27d | 44 | if (pin2 > device.dither.state.pin2) LPC_GPIO1->FIOCLR = 1<<28; |
Diletant | 149:abbf7663d27d | 45 | if (pin2 < device.dither.state.pin2) LPC_GPIO1->FIOSET = 1<<28; |
Diletant | 149:abbf7663d27d | 46 | device.dither.state.pin1 = pin1; |
Diletant | 149:abbf7663d27d | 47 | device.dither.state.pin2 = pin2; |
Diletant | 149:abbf7663d27d | 48 | } |