Rev 1081 | Rev 1091 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1081 | Rev 1083 | ||
|---|---|---|---|
| Line 63... | Line 63... | ||
| 63 | } |
63 | } |
| 64 | 64 | ||
| 65 | /* When the timer reaches its compare value the triac should be trigged */ |
65 | /* When the timer reaches its compare value the triac should be trigged */ |
| 66 | ISR (TIMER1_COMPA_vect) |
66 | ISR (TIMER1_COMPA_vect) |
| 67 | { |
67 | { |
| 68 |
|
68 | gpio_set_pin(act_dimmer230_CHAN1_IO); |
| 69 | uint8_t dummycnt = 40; |
69 | uint8_t dummycnt = 40; |
| 70 | while (dummycnt > 0) |
70 | while (dummycnt > 0) |
| 71 | { |
71 | { |
| 72 | dummycnt++; |
72 | dummycnt++; |
| 73 | asm("nop"); |
73 | asm("nop"); |
| 74 | asm("nop"); |
74 | asm("nop"); |
| 75 | } |
75 | } |
| 76 |
|
76 | gpio_clr_pin(act_dimmer230_CHAN1_IO); |
| 77 | 77 | ||
| 78 | TIMSK1=0; //disable timer interrupt |
78 | TIMSK1=0; //disable timer interrupt |
| 79 | state = ACT_DIMMMER230_STATE_IDLE; |
79 | state = ACT_DIMMMER230_STATE_IDLE; |
| 80 | } |
80 | } |
| 81 | 81 | ||
| Line 86... | Line 86... | ||
| 86 | ISR (act_dimmer230_ZC_PCINT_vect) |
86 | ISR (act_dimmer230_ZC_PCINT_vect) |
| 87 | { |
87 | { |
| 88 | /* only execute if zerocross pin is low (after real zerocross). |
88 | /* only execute if zerocross pin is low (after real zerocross). |
| 89 | Calculate the diff from real zero-cross. |
89 | Calculate the diff from real zero-cross. |
| 90 | */ |
90 | */ |
| 91 | if (!( |
91 | if (!gpio_get_state(act_dimmer230_ZC_IO)) |
| 92 | { |
92 | { |
| 93 | xcTimeDiff = TCNT1; |
93 | xcTimeDiff = TCNT1; |
| 94 | xcTimeDiff = xcTimeDiff >> 1; //divide by two |
94 | xcTimeDiff = xcTimeDiff >> 1; //divide by two |
| 95 | if (xcTimeDiff > 600) { |
95 | if (xcTimeDiff > 600) { |
| 96 | xcTimeDiff = 600; |
96 | xcTimeDiff = 600; |
| 97 | } |
97 | } |
| 98 | } |
98 | } |
| 99 | /* only execute if zerocross pin is high (before real zerocross) */ |
99 | /* only execute if zerocross pin is high (before real zerocross) */ |
| 100 | else |
100 | else |
| 101 | { |
101 | { |
| 102 | /* Reset the timer for checking net connection. If no zero-cross has come in 500ms then consider us disconnected */ |
102 | /* Reset the timer for checking net connection. If no zero-cross has come in 500ms then consider us disconnected */ |
| 103 | Timer_SetTimeout(act_dimmer230_NET_CONNECT_TIMEOUT, 500, TimerTypeOneShot, &Net_Connection_callback); |
103 | Timer_SetTimeout(act_dimmer230_NET_CONNECT_TIMEOUT, 500, TimerTypeOneShot, &Net_Connection_callback); |
| 104 | /* Currently we are connected */ |
104 | /* Currently we are connected */ |
| 105 | netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_CONNECTED; |
105 | netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_CONNECTED; |
| Line 242... | Line 242... | ||
| 242 | EEDATA_UPDATE_CRC; |
242 | EEDATA_UPDATE_CRC; |
| 243 | } |
243 | } |
| 244 | #endif |
244 | #endif |
| 245 | 245 | ||
| 246 | /* set dimmer port to output 0 */ |
246 | /* set dimmer port to output 0 */ |
| 247 |
|
247 | gpio_clr_pin(act_dimmer230_CHAN1_IO); |
| 248 |
|
248 | gpio_set_out(act_dimmer230_CHAN1_IO); |
| 249 | /* set zero cross detection port to input, no pullup */ |
249 | /* set zero cross detection port to input, no pullup */ |
| 250 |
|
250 | gpio_set_in(act_dimmer230_ZC_IO); |
| 251 |
|
251 | gpio_clr_pullup(act_dimmer230_ZC_IO); |
| 252 | 252 | ||
| 253 | TIMSK1=0; /* disable timer interrupt */ |
253 | TIMSK1=0; /* disable timer interrupt */ |
| 254 | TCCR1A=0; |
254 | TCCR1A=0; |
| 255 | 255 | ||
| 256 | TCCR1B=(1<<CS11); /* enable timer, set to prescaler 8, must be changed if cpu freq is changed */ |
256 | TCCR1B=(1<<CS11); /* enable timer, set to prescaler 8, must be changed if cpu freq is changed */ |