Rev 1995 | Rev 2168 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1995 | Rev 2163 | ||
|---|---|---|---|
| Line 86... | Line 86... | ||
| 86 | MeasurmentBufferPointer++; |
86 | MeasurmentBufferPointer++; |
| 87 | if (MeasurmentBufferPointer >= 32) MeasurmentBufferPointer = 0; |
87 | if (MeasurmentBufferPointer >= 32) MeasurmentBufferPointer = 0; |
| 88 | lastMeasurment = Timer_GetTicks() - PreviusTimerValue; |
88 | lastMeasurment = Timer_GetTicks() - PreviusTimerValue; |
| 89 | MeasurmentBuffer[MeasurmentBufferPointer] = (uint16_t) (lastMeasurment & 0x0000FFFF); |
89 | MeasurmentBuffer[MeasurmentBufferPointer] = (uint16_t) (lastMeasurment & 0x0000FFFF); |
| 90 | PreviusTimerValue = Timer_GetTicks(); |
90 | PreviusTimerValue = Timer_GetTicks(); |
| - | 91 | #if sns_power_100_PULSES_PER_KWH == 1 |
|
| - | 92 | EnergyCounter+=10; |
|
| - | 93 | if (EnergyCounter % 1024 == 0) |
|
| - | 94 | StoreInEEPROM = 1; |
|
| - | 95 | #endif |
|
| 91 | #if sns_power_1000_PULSES_PER_KWH == 1 |
96 | #if sns_power_1000_PULSES_PER_KWH == 1 |
| 92 | EnergyCounter++; |
97 | EnergyCounter++; |
| 93 | if (EnergyCounter % 1024 == 0) |
98 | if (EnergyCounter % 1024 == 0) |
| 94 | StoreInEEPROM = 1; |
99 | StoreInEEPROM = 1; |
| 95 | #endif |
100 | #endif |
| 96 | #if sns_power_10000_PULSES_PER_KWH == 1 |
101 | #if sns_power_10000_PULSES_PER_KWH == 1 |
| 97 | tmpCounter++; |
102 | tmpCounter++; |
| 98 | #if sns_power_SEND_1_MIN_AVG == 1 |
103 | #if sns_power_SEND_1_MIN_AVG == 1 |
| 99 | avgCounter++; |
104 | avgCounter++; |
| Line 102... | Line 107... | ||
| 102 | EnergyCounter++; |
107 | EnergyCounter++; |
| 103 | if (EnergyCounter % 1024 == 0) |
108 | if (EnergyCounter % 1024 == 0) |
| 104 | StoreInEEPROM = 1; |
109 | StoreInEEPROM = 1; |
| 105 | tmpCounter = 0; |
110 | tmpCounter = 0; |
| 106 | } |
111 | } |
| 107 | #endif |
112 | #endif |
| 108 | 113 | ||
| 109 | #ifdef sns_power_LED_PIN |
114 | #ifdef sns_power_LED_PIN |
| 110 | gpio_toggle_pin(sns_power_LED_PIN); // toggle pin |
115 | gpio_toggle_pin(sns_power_LED_PIN); // toggle pin |
| 111 | #endif |
116 | #endif |
| 112 | } |
117 | } |
| 113 | } |
118 | } |
| 114 | } |
119 | } |
| 115 | 120 | ||
| 116 | #ifdef POWER_SNS_PIN_ch2 |
121 | #ifdef POWER_SNS_PIN_ch2 |
| 117 | void sns_power_pcint_callback_ch2(uint8_t id, uint8_t status) |
122 | void sns_power_pcint_callback_ch2(uint8_t id, uint8_t status) |
| 118 | { |
123 | { |
| 119 | if (status == 0) |
124 | if (status == 0) |
| 120 | { |
125 | { |
| 121 | if (Timer_GetTicks() - PreviusTimerValue_ch2 >= 16) |
126 | if (Timer_GetTicks() - PreviusTimerValue_ch2 >= 16) |
| 122 | { |
127 | { |
| 123 | MeasurmentBufferPointer_ch2++; |
128 | MeasurmentBufferPointer_ch2++; |
| 124 | if (MeasurmentBufferPointer_ch2 >= 32) MeasurmentBufferPointer_ch2 = 0; |
129 | if (MeasurmentBufferPointer_ch2 >= 32) MeasurmentBufferPointer_ch2 = 0; |
| 125 | lastMeasurment_ch2 = Timer_GetTicks() - PreviusTimerValue_ch2; |
130 | lastMeasurment_ch2 = Timer_GetTicks() - PreviusTimerValue_ch2; |
| 126 | MeasurmentBuffer_ch2[MeasurmentBufferPointer_ch2] = (uint16_t) (lastMeasurment_ch2 & 0x0000FFFF); |
131 | MeasurmentBuffer_ch2[MeasurmentBufferPointer_ch2] = (uint16_t) (lastMeasurment_ch2 & 0x0000FFFF); |
| 127 | PreviusTimerValue_ch2 = Timer_GetTicks(); |
132 | PreviusTimerValue_ch2 = Timer_GetTicks(); |
| - | 133 | #if sns_power_100_PULSES_PER_KWH == 1 |
|
| - | 134 | EnergyCounter_ch2+=10; |
|
| - | 135 | #endif |
|
| 128 | #if sns_power_1000_PULSES_PER_KWH == 1 |
136 | #if sns_power_1000_PULSES_PER_KWH == 1 |
| 129 | EnergyCounter_ch2++; |
137 | EnergyCounter_ch2++; |
| 130 | #endif |
138 | #endif |
| 131 | #if sns_power_10000_PULSES_PER_KWH == 1 |
139 | #if sns_power_10000_PULSES_PER_KWH == 1 |
| 132 | tmpCounter_ch2++; |
140 | tmpCounter_ch2++; |
| Line 177... | Line 185... | ||
| 177 | #if sns_power_PIN_PULLUP==1 |
185 | #if sns_power_PIN_PULLUP==1 |
| 178 | gpio_set_pullup(POWER_SNS_PIN); // Enable pull-up |
186 | gpio_set_pullup(POWER_SNS_PIN); // Enable pull-up |
| 179 | #endif |
187 | #endif |
| 180 | 188 | ||
| 181 | Pcint_SetCallbackPin(sns_power_PCINT, POWER_SNS_PIN, &sns_power_pcint_callback); |
189 | Pcint_SetCallbackPin(sns_power_PCINT, POWER_SNS_PIN, &sns_power_pcint_callback); |
| 182 | 190 | ||
| 183 | MeasurmentBufferPointer = 0; |
191 | MeasurmentBufferPointer = 0; |
| 184 | #ifdef POWER_SNS_PIN_ch2 |
192 | #ifdef POWER_SNS_PIN_ch2 |
| 185 | gpio_set_in(POWER_SNS_PIN_ch2); // Set to input |
193 | gpio_set_in(POWER_SNS_PIN_ch2); // Set to input |
| 186 | #if sns_power_PIN_PULLUP_ch2==1 |
194 | #if sns_power_PIN_PULLUP_ch2==1 |
| 187 | gpio_set_pullup(POWER_SNS_PIN_ch2); // Enable pull-up |
195 | gpio_set_pullup(POWER_SNS_PIN_ch2); // Enable pull-up |
| Line 223... | Line 231... | ||
| 223 | */ |
231 | */ |
| 224 | //32 times average |
232 | //32 times average |
| 225 | uint32_t Avg32 = 0; |
233 | uint32_t Avg32 = 0; |
| 226 | for (uint8_t i = 0; i<32;i++) { |
234 | for (uint8_t i = 0; i<32;i++) { |
| 227 | Avg32 += MeasurmentBuffer[i]; |
235 | Avg32 += MeasurmentBuffer[i]; |
| 228 | } |
236 | } |
| 229 | Avg32 /= 32; |
237 | Avg32 /= 32; |
| - | 238 | #if sns_power_100_PULSES_PER_KWH == 1 |
|
| - | 239 | Avg32 = (36000000UL/Avg32); |
|
| - | 240 | #endif |
|
| 230 | #if sns_power_1000_PULSES_PER_KWH == 1 |
241 | #if sns_power_1000_PULSES_PER_KWH == 1 |
| 231 | Avg32 = (3600000/Avg32); |
242 | Avg32 = (3600000/Avg32); |
| 232 | #endif |
243 | #endif |
| 233 | #if sns_power_10000_PULSES_PER_KWH == 1 |
244 | #if sns_power_10000_PULSES_PER_KWH == 1 |
| 234 | Avg32 = (360000/Avg32); |
245 | Avg32 = (360000/Avg32); |
| 235 | #endif |
246 | #endif |
| 236 | 247 | ||
| 237 | 248 | ||
| 238 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); |
249 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); |
| 239 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
250 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
| 240 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_POWER; |
251 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_POWER; |
| 241 | txMsg.Header.ModuleId = sns_power_ID; |
252 | txMsg.Header.ModuleId = sns_power_ID; |
| 242 | txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_ELECTRICPOWER; |
253 | txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_ELECTRICPOWER; |
| 243 | txMsg.Length = 8; |
254 | txMsg.Length = 8; |
| - | 255 | #if sns_power_100_PULSES_PER_KWH == 1 |
|
| - | 256 | uint32_t tmp = 36000000UL/MeasurmentBuffer[MeasurmentBufferPointer]; |
|
| - | 257 | #endif |
|
| 244 | #if sns_power_1000_PULSES_PER_KWH == 1 |
258 | #if sns_power_1000_PULSES_PER_KWH == 1 |
| 245 | uint32_t tmp = 3600000/MeasurmentBuffer[MeasurmentBufferPointer]; |
259 | uint32_t tmp = 3600000/MeasurmentBuffer[MeasurmentBufferPointer]; |
| 246 | #endif |
260 | #endif |
| 247 | #if sns_power_10000_PULSES_PER_KWH == 1 |
261 | #if sns_power_10000_PULSES_PER_KWH == 1 |
| 248 | uint32_t tmp = 360000/MeasurmentBuffer[MeasurmentBufferPointer]; |
262 | uint32_t tmp = 360000/MeasurmentBuffer[MeasurmentBufferPointer]; |
| Line 261... | Line 275... | ||
| 261 | uint32_t Avg32_ch2 = 0; |
275 | uint32_t Avg32_ch2 = 0; |
| 262 | for (uint8_t i = 0; i<32;i++) { |
276 | for (uint8_t i = 0; i<32;i++) { |
| 263 | Avg32_ch2 += MeasurmentBuffer_ch2[i]; |
277 | Avg32_ch2 += MeasurmentBuffer_ch2[i]; |
| 264 | } |
278 | } |
| 265 | Avg32_ch2 /= 32; |
279 | Avg32_ch2 /= 32; |
| - | 280 | #if sns_power_100_PULSES_PER_KWH == 1 |
|
| - | 281 | Avg32_ch2 = (36000000UL/Avg32_ch2); |
|
| - | 282 | #endif |
|
| 266 | #if sns_power_1000_PULSES_PER_KWH == 1 |
283 | #if sns_power_1000_PULSES_PER_KWH == 1 |
| 267 | Avg32_ch2 = (3600000/Avg32_ch2); |
284 | Avg32_ch2 = (3600000/Avg32_ch2); |
| 268 | #endif |
285 | #endif |
| 269 | #if sns_power_10000_PULSES_PER_KWH == 1 |
286 | #if sns_power_10000_PULSES_PER_KWH == 1 |
| 270 | Avg32_ch2 = (360000/Avg32_ch2); |
287 | Avg32_ch2 = (360000/Avg32_ch2); |
| 271 | #endif |
288 | #endif |
| 272 | 289 | ||
| 273 | txMsg.Header.ModuleId = sns_power_ID_ch2; |
290 | txMsg.Header.ModuleId = sns_power_ID_ch2; |
| - | 291 | #if sns_power_100_PULSES_PER_KWH == 1 |
|
| - | 292 | tmp = 36000000UL/MeasurmentBuffer_ch2[MeasurmentBufferPointer_ch2]; |
|
| - | 293 | #endif |
|
| 274 | #if sns_power_1000_PULSES_PER_KWH == 1 |
294 | #if sns_power_1000_PULSES_PER_KWH == 1 |
| 275 | tmp = 3600000/MeasurmentBuffer_ch2[MeasurmentBufferPointer_ch2]; |
295 | tmp = 3600000/MeasurmentBuffer_ch2[MeasurmentBufferPointer_ch2]; |
| 276 | #endif |
296 | #endif |
| 277 | #if sns_power_10000_PULSES_PER_KWH == 1 |
297 | #if sns_power_10000_PULSES_PER_KWH == 1 |
| 278 | tmp = 360000/MeasurmentBuffer_ch2[MeasurmentBufferPointer_ch2]; |
298 | tmp = 360000/MeasurmentBuffer_ch2[MeasurmentBufferPointer_ch2]; |