Rev 900 | Rev 950 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 900 | Rev 901 | ||
|---|---|---|---|
| Line 38... | Line 38... | ||
| 38 | ISR (TIMER1_COMPA_vect) |
38 | ISR (TIMER1_COMPA_vect) |
| 39 | { |
39 | { |
| 40 | //testa hur lång denna loop behöver vara |
40 | //testa hur lång denna loop behöver vara |
| 41 | //verkar fungera upp till 249-250 sen blir det för korta pulser |
41 | //verkar fungera upp till 249-250 sen blir det för korta pulser |
| 42 | act_dimmer230_CHAN1_PORT |= _BV(act_dimmer230_CHAN1_BIT); |
42 | act_dimmer230_CHAN1_PORT |= _BV(act_dimmer230_CHAN1_BIT); |
| 43 | uint8_t dummycnt = |
43 | uint8_t dummycnt = 40; |
| 44 | while (dummycnt > 0) |
44 | while (dummycnt > 0) |
| 45 | { |
45 | { |
| 46 | dummycnt++; |
46 | dummycnt++; |
| - | 47 | asm("nop"); |
|
| 47 | asm("nop"); |
48 | asm("nop"); |
| 48 | } |
49 | } |
| 49 | act_dimmer230_CHAN1_PORT &= ~_BV(act_dimmer230_CHAN1_BIT); |
50 | act_dimmer230_CHAN1_PORT &= ~_BV(act_dimmer230_CHAN1_BIT); |
| 50 | 51 | ||
| 51 | TIMSK1=0; //disable timer interrupt |
52 | TIMSK1=0; //disable timer interrupt |
| Line 119... | Line 120... | ||
| 119 | txMsg.Data[1] = newTimerVal&0xff; |
120 | txMsg.Data[1] = newTimerVal&0xff; |
| 120 | //txMsg.Data[2] = (periodTime>>8)&0xff; |
121 | //txMsg.Data[2] = (periodTime>>8)&0xff; |
| 121 | //txMsg.Data[3] = periodTime&0xff; |
122 | //txMsg.Data[3] = periodTime&0xff; |
| 122 | txMsg.Data[4] = (xcTimeDiff>>8)&0xff; |
123 | txMsg.Data[4] = (xcTimeDiff>>8)&0xff; |
| 123 | txMsg.Data[5] = xcTimeDiff&0xff; |
124 | txMsg.Data[5] = xcTimeDiff&0xff; |
| 124 |
|
125 | StdCan_Put(&txMsg); |
| 125 | 126 | ||
| 126 | #ifdef USEDEMO |
127 | #ifdef USEDEMO |
| 127 | if (demo == 0 || demo == 2) { |
128 | if (demo == 0 || demo == 2) { |
| 128 | democnt++; |
129 | democnt++; |
| 129 | if (democnt==DEMOSTEPS) |
130 | if (democnt==DEMOSTEPS) |
| Line 168... | Line 169... | ||
| 168 | act_dimmer230_ZC_PORT &= ~_BV(act_dimmer230_ZC_BIT); |
169 | act_dimmer230_ZC_PORT &= ~_BV(act_dimmer230_ZC_BIT); |
| 169 | act_dimmer230_ZC_DDR &= ~_BV(act_dimmer230_ZC_BIT); |
170 | act_dimmer230_ZC_DDR &= ~_BV(act_dimmer230_ZC_BIT); |
| 170 | 171 | ||
| 171 | TIMSK1=0; //disable timer interrupt |
172 | TIMSK1=0; //disable timer interrupt |
| 172 | TCCR1A=0; |
173 | TCCR1A=0; |
| 173 | 174 | ||
| 174 | //wait for high (ac leaving zero cross) |
175 | //wait for high (ac leaving zero cross) |
| 175 | while (!(act_dimmer230_ZC_PIN&(1<<act_dimmer230_ZC_BIT))) { } |
176 | while (!(act_dimmer230_ZC_PIN&(1<<act_dimmer230_ZC_BIT))) { } |
| 176 | TCCR1B=(1<<CS11); //enable timer, set to prescaler 8, must be changed if cpu freq is changed |
177 | TCCR1B=(1<<CS11); //enable timer, set to prescaler 8, must be changed if cpu freq is changed |
| 177 | //wait for low (ac approaching zero cross) |
178 | //wait for low (ac approaching zero cross) |
| 178 | while (act_dimmer230_ZC_PIN&(1<<act_dimmer230_ZC_BIT)) { } |
179 | while (act_dimmer230_ZC_PIN&(1<<act_dimmer230_ZC_BIT)) { } |
| Line 229... | Line 230... | ||
| 229 | if (rxMsg->Length == 3) { |
230 | if (rxMsg->Length == 3) { |
| 230 | uint8_t channel = rxMsg->Data[0]; |
231 | uint8_t channel = rxMsg->Data[0]; |
| 231 | uint8_t speed = rxMsg->Data[1]; |
232 | uint8_t speed = rxMsg->Data[1]; |
| 232 | uint8_t direction = rxMsg->Data[2]; |
233 | uint8_t direction = rxMsg->Data[2]; |
| 233 | 234 | ||
| - | 235 | fadeSpeedCntCh1 = 0; |
|
| - | 236 | fadeSpeedCh1 = 0; |
|
| 234 | uint8_t endValue = 0; |
237 | uint8_t endValue = 0; |
| 235 | if (direction == 1) { |
238 | if (direction == 1) { |
| 236 | endValue = ACT_DIMMMER230_MAX_DIM; |
239 | endValue = ACT_DIMMMER230_MAX_DIM; |
| 237 | } else if (direction == 0) { |
240 | } else if (direction == 0) { |
| 238 | endValue = ACT_DIMMMER230_MIN_DIM; |
241 | endValue = ACT_DIMMMER230_MIN_DIM; |
| Line 267... | Line 270... | ||
| 267 | case CAN_CMD_MODULE_DIMMER_ABS_FADE: // AbsFade(channel, speed, endValue) |
270 | case CAN_CMD_MODULE_DIMMER_ABS_FADE: // AbsFade(channel, speed, endValue) |
| 268 | if (rxMsg->Length == 3) { |
271 | if (rxMsg->Length == 3) { |
| 269 | uint8_t channel = rxMsg->Data[0]; |
272 | uint8_t channel = rxMsg->Data[0]; |
| 270 | uint8_t speed = rxMsg->Data[1]; |
273 | uint8_t speed = rxMsg->Data[1]; |
| 271 | uint8_t endValue = rxMsg->Data[2]; |
274 | uint8_t endValue = rxMsg->Data[2]; |
| - | 275 | ||
| - | 276 | fadeSpeedCntCh1 = 0; |
|
| - | 277 | fadeSpeedCh1 = 0; |
|
| 272 | if (speed == 0) { |
278 | if (speed == 0) { |
| 273 | dimmerValueCh1 = endValue; //set dimmer value immediately |
279 | dimmerValueCh1 = endValue; //set dimmer value immediately |
| 274 | } else { |
280 | } else { |
| 275 | fadeTargetCh1 = endValue; |
281 | fadeTargetCh1 = endValue; |
| 276 | if (fadeTargetCh1 != dimmerValueCh1) { |
282 | if (fadeTargetCh1 != dimmerValueCh1) { |
| Line 284... | Line 290... | ||
| 284 | if (fadeTargetCh1 < dimmerValueCh1) { |
290 | if (fadeTargetCh1 < dimmerValueCh1) { |
| 285 | fadeSpeedCh1 = -fadeSpeedCh1; |
291 | fadeSpeedCh1 = -fadeSpeedCh1; |
| 286 | } |
292 | } |
| 287 | } |
293 | } |
| 288 | } |
294 | } |
| 289 | } |
295 | } |
| 290 | break; |
296 | break; |
| 291 | 297 | ||
| 292 | case CAN_CMD_MODULE_DIMMER_REL_FADE: // RelFade(channel, speed, direction, steps) |
298 | case CAN_CMD_MODULE_DIMMER_REL_FADE: // RelFade(channel, speed, direction, steps) |
| 293 | if (rxMsg->Length == 4) { |
299 | if (rxMsg->Length == 4) { |
| 294 | uint8_t channel = rxMsg->Data[0]; |
300 | uint8_t channel = rxMsg->Data[0]; |
| 295 | uint8_t speed = rxMsg->Data[1]; |
301 | uint8_t speed = rxMsg->Data[1]; |
| 296 | uint8_t direction = rxMsg->Data[2]; |
302 | uint8_t direction = rxMsg->Data[2]; |
| 297 | uint8_t steps = rxMsg->Data[3]; |
303 | uint8_t steps = rxMsg->Data[3]; |
| 298 | 304 | ||
| - | 305 | fadeSpeedCntCh1 = 0; |
|
| - | 306 | fadeSpeedCh1 = 0; |
|
| 299 | uint8_t tempDimVal = dimmerValueCh1; |
307 | uint8_t tempDimVal = dimmerValueCh1; |
| 300 | uint8_t tempDimVal2 = dimmerValueCh1; |
308 | uint8_t tempDimVal2 = dimmerValueCh1; |
| 301 | if (direction == 1) { //if increase |
309 | if (direction == 1) { //if increase |
| 302 | tempDimVal2 += steps; //calculate new value |
310 | tempDimVal2 += steps; //calculate new value |
| 303 | if (tempDimVal2 < tempDimVal) { //make overflow test |
311 | if (tempDimVal2 < tempDimVal) { //make overflow test |