Rev 896 | Rev 899 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 896 | Rev 897 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | #include "act_dimmer230.h" |
2 | #include "act_dimmer230.h" |
| 3 | 3 | ||
| - | 4 | //#define USEDEMO |
|
| - | 5 | ||
| - | 6 | #ifdef USEDEMO |
|
| 4 | uint8_t demo = 0; |
7 | uint8_t demo = 0; |
| - | 8 | //uint8_t demo = 2; //demo one way |
|
| 5 | //uint8_t demo = |
9 | //uint8_t demo = 3; //disable demo |
| - | 10 | uint8_t democnt = 0; |
|
| - | 11 | #define DEMOSTEPS 2 |
|
| - | 12 | #define DEMOSTEPS2 1 |
|
| - | 13 | #endif |
|
| 6 | 14 | ||
| 7 | //uint16_t periodTime = 0; |
15 | //uint16_t periodTime = 0; |
| 8 | //measured during init (by taking the time difference between two zero cross) |
16 | //measured during init (by taking the time difference between two zero cross) |
| 9 | //not used, bad idea, the powerStepTable below asumes 10000 |
17 | //not used, bad idea, the powerStepTable below asumes 10000 |
| 10 | uint16_t xcTimeDiff=0; |
18 | uint16_t xcTimeDiff=0; |
| Line 46... | Line 54... | ||
| 46 | //here new timer value is calculated |
54 | //here new timer value is calculated |
| 47 | 55 | ||
| 48 | if (dimmerValueCh1 > 0 && dimmerValueCh1 <= 127) |
56 | if (dimmerValueCh1 > 0 && dimmerValueCh1 <= 127) |
| 49 | { |
57 | { |
| 50 | newTimerVal += ACT_DIMMMER230_PERIOD_TIME - pgm_read_word(&powerStepTable[dimmerValueCh1-1]); |
58 | newTimerVal += ACT_DIMMMER230_PERIOD_TIME - pgm_read_word(&powerStepTable[dimmerValueCh1-1]); |
| 51 | } |
59 | } |
| 52 | else if (dimmerValueCh1 < 255) |
60 | else if (dimmerValueCh1 < 255) |
| 53 | { |
61 | { |
| 54 | newTimerVal += pgm_read_word(&powerStepTable[254-dimmerValueCh1]); |
62 | newTimerVal += pgm_read_word(&powerStepTable[254-dimmerValueCh1]); |
| 55 | } |
63 | } |
| 56 | else if (dimmerValueCh1 == 255) |
64 | else if (dimmerValueCh1 == 255) |
| Line 69... | Line 77... | ||
| 69 | OCR1A = newTimerVal; |
77 | OCR1A = newTimerVal; |
| 70 | 78 | ||
| 71 | //enable timer and timer interrupt |
79 | //enable timer and timer interrupt |
| 72 | TIFR1=(1<<OCF1A); //clear interrupt flag before enabling interrupt |
80 | TIFR1=(1<<OCF1A); //clear interrupt flag before enabling interrupt |
| 73 | TIMSK1|=(1<<OCIE1A); |
81 | TIMSK1|=(1<<OCIE1A); |
| 74 | 82 | ||
| 75 | state = ACT_DIMMMER230_STATE_TIMER_ON; |
83 | state = ACT_DIMMMER230_STATE_TIMER_ON; |
| 76 | } |
84 | } |
| 77 | 85 | ||
| 78 | #if act_dimmer230_SYNC>0 |
86 | #if act_dimmer230_SYNC>0 |
| 79 | zeroCrossCnt++; |
87 | zeroCrossCnt++; |
| Line 90... | Line 98... | ||
| 90 | //txMsg.Data[3] = periodTime&0xff; |
98 | //txMsg.Data[3] = periodTime&0xff; |
| 91 | txMsg.Data[4] = (xcTimeDiff>>8)&0xff; |
99 | txMsg.Data[4] = (xcTimeDiff>>8)&0xff; |
| 92 | txMsg.Data[5] = xcTimeDiff&0xff; |
100 | txMsg.Data[5] = xcTimeDiff&0xff; |
| 93 | //StdCan_Put(&txMsg); |
101 | //StdCan_Put(&txMsg); |
| 94 | 102 | ||
| - | 103 | #ifdef USEDEMO |
|
| 95 | if (demo == 0) { |
104 | if (demo == 0 || demo == 2) { |
| - | 105 | democnt++; |
|
| - | 106 | if (democnt==DEMOSTEPS) |
|
| - | 107 | { |
|
| - | 108 | democnt = 0; |
|
| - | 109 | uint8_t tempDim=dimmerValueCh1; |
|
| - | 110 | dimmerValueCh1+=DEMOSTEPS2; |
|
| - | 111 | if (dimmerValueCh1<tempDim && demo == 0) { |
|
| 96 | dimmerValueCh1 |
112 | dimmerValueCh1=255; |
| - | 113 | } |
|
| - | 114 | } |
|
| 97 | if (dimmerValueCh1 == 255) { |
115 | if (dimmerValueCh1 == 255 && demo == 0) { |
| 98 | demo = 1; |
116 | demo = 1; |
| 99 | } |
117 | } |
| 100 | } else if (demo == 1) { |
118 | } else if (demo == 1) { |
| - | 119 | democnt++; |
|
| - | 120 | if (democnt==DEMOSTEPS) |
|
| - | 121 | { |
|
| - | 122 | democnt = 0; |
|
| - | 123 | uint8_t tempDim=dimmerValueCh1; |
|
| - | 124 | dimmerValueCh1-=DEMOSTEPS2; |
|
| - | 125 | if (dimmerValueCh1>tempDim) { |
|
| 101 | dimmerValueCh1 |
126 | dimmerValueCh1=0; |
| - | 127 | } |
|
| - | 128 | } |
|
| 102 | if (dimmerValueCh1 == 0) { |
129 | if (dimmerValueCh1 == 0) { |
| 103 | demo = 0; |
130 | demo = 0; |
| 104 | } |
131 | } |
| 105 | } |
132 | } |
| - | 133 | #endif //USEDEMO |
|
| 106 | } |
134 | } |
| 107 | #endif |
135 | #endif |
| 108 | } |
136 | } |
| 109 | } |
137 | } |
| 110 | 138 | ||