Rev 2168 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2168 | Rev 2175 | ||
|---|---|---|---|
| Line 36... | Line 36... | ||
| 36 | #endif |
36 | #endif |
| 37 | #if sns_power_USEEEPROM==1 |
37 | #if sns_power_USEEEPROM==1 |
| 38 | #include "sns_power_eeprom.h" |
38 | #include "sns_power_eeprom.h" |
| 39 | struct eeprom_sns_power EEMEM eeprom_sns_power = |
39 | struct eeprom_sns_power EEMEM eeprom_sns_power = |
| 40 | { |
40 | { |
| 41 | { |
- | |
| 42 |
|
41 | { /// Define initialization values on the EEPROM variables here, this will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips. Write the values in the exact same order as the struct is defined in the *.h file. |
| 43 | (uint8_t)sns_power_SEND_PERIOD, // reportInterval |
42 | (uint8_t)sns_power_SEND_PERIOD, // reportInterval |
| 44 | 0, // EnergyCounterUpper |
43 | 0, // EnergyCounterUpper |
| 45 | 0, // EnergyCounterLower |
44 | 0, // EnergyCounterLower |
| 46 | #ifdef POWER_SNS_PIN_ch2 |
45 | #ifdef POWER_SNS_PIN_ch2 |
| 47 | 0, // EnergyCounterUpper_ch2 |
46 | 0, // EnergyCounterUpper_ch2 |
| Line 82... | Line 81... | ||
| 82 | #endif |
81 | #endif |
| 83 | } |
82 | } |
| 84 | #endif |
83 | #endif |
| 85 | 84 | ||
| 86 | void sns_power_pcint_callback(uint8_t id, uint8_t status) |
85 | void sns_power_pcint_callback(uint8_t id, uint8_t status) |
| 87 | { |
86 | { |
| 88 | if (status == 0) |
87 | if (status == 0) |
| 89 | { |
88 | { |
| 90 | if (Timer_GetTicks() - PreviusTimerValue >= 16) |
89 | if (Timer_GetTicks() - PreviusTimerValue >= 16) |
| 91 | { |
90 | { |
| 92 | MeasurmentBufferPointer++; |
91 | MeasurmentBufferPointer++; |
| 93 | if (MeasurmentBufferPointer >= 32) MeasurmentBufferPointer = 0; |
92 | if (MeasurmentBufferPointer >= 32) MeasurmentBufferPointer = 0; |
| 94 | lastMeasurment = Timer_GetTicks() - PreviusTimerValue; |
93 | lastMeasurment = Timer_GetTicks() - PreviusTimerValue; |
| 95 | MeasurmentBuffer[MeasurmentBufferPointer] = (uint16_t) (lastMeasurment & 0x0000FFFF); |
94 | MeasurmentBuffer[MeasurmentBufferPointer] = (uint16_t) (lastMeasurment & 0x0000FFFF); |
| 96 | PreviusTimerValue = Timer_GetTicks(); |
95 | PreviusTimerValue = Timer_GetTicks(); |
| 97 | #if sns_power_100_PULSES_PER_KWH == 1 |
96 | #if sns_power_100_PULSES_PER_KWH == 1 |
| 98 | EnergyCounter+=10; |
97 | EnergyCounter+=10; |
| 99 |
|
98 | //if (EnergyCounter % 1024 == 0) |
| - | 99 | if (EnergyCounter & (1024-1) == 0) |
|
| 100 | StoreInEEPROM = 1; |
100 | StoreInEEPROM = 1; |
| 101 | #endif |
101 | #endif |
| 102 | #if sns_power_1000_PULSES_PER_KWH == 1 |
102 | #if sns_power_1000_PULSES_PER_KWH == 1 |
| 103 | EnergyCounter++; |
103 | EnergyCounter++; |
| 104 |
|
104 | //if (EnergyCounter % 1024 == 0) |
| - | 105 | if (EnergyCounter & (1024-1) == 0) |
|
| 105 | StoreInEEPROM = 1; |
106 | StoreInEEPROM = 1; |
| 106 | #endif |
107 | #endif |
| 107 | #if sns_power_10000_PULSES_PER_KWH == 1 |
108 | #if sns_power_10000_PULSES_PER_KWH == 1 |
| 108 | tmpCounter++; |
109 | tmpCounter++; |
| 109 | #if sns_power_SEND_1_MIN_AVG == 1 |
110 | #if sns_power_SEND_1_MIN_AVG == 1 |
| 110 | avgCounter++; |
111 | avgCounter++; |
| 111 | #endif |
112 | #endif |
| 112 | if(tmpCounter >= 10) { |
113 | if(tmpCounter >= 10) { |
| 113 | EnergyCounter++; |
114 | EnergyCounter++; |
| 114 |
|
115 | //if (EnergyCounter % 1024 == 0) |
| - | 116 | if (EnergyCounter & (1024-1) == 0) |
|
| 115 | StoreInEEPROM = 1; |
117 | StoreInEEPROM = 1; |
| 116 | tmpCounter = 0; |
118 | tmpCounter = 0; |
| 117 | } |
119 | } |
| 118 | #endif |
120 | #endif |
| 119 | 121 | ||
| 120 | #ifdef sns_power_LED_PIN |
122 | #ifdef sns_power_LED_PIN |
| 121 | gpio_toggle_pin(sns_power_LED_PIN); // toggle pin |
123 | gpio_toggle_pin(sns_power_LED_PIN); // toggle pin |
| 122 | #endif |
124 | #endif |
| 123 | } |
125 | } |
| 124 | } |
126 | } |
| 125 | } |
127 | } |
| 126 | 128 | ||
| Line 162... | Line 164... | ||
| 162 | 164 | ||
| 163 | void sns_power_Init(void) |
165 | void sns_power_Init(void) |
| 164 | { |
166 | { |
| 165 | #if sns_power_USEEEPROM==1 |
167 | #if sns_power_USEEEPROM==1 |
| 166 | if (EEDATA_OK) |
168 | if (EEDATA_OK) |
| 167 | { |
- | |
| 168 |
|
169 | { /// Use stored data to set initial values for the module |
| 169 | sns_power_ReportInterval = eeprom_read_byte(EEDATA.reportInterval); |
170 | sns_power_ReportInterval = eeprom_read_byte(EEDATA.reportInterval); |
| 170 | EnergyCounter = eeprom_read_word(EEDATA16.EnergyCounterLower); |
171 | EnergyCounter = eeprom_read_word(EEDATA16.EnergyCounterLower); |
| 171 | EnergyCounter += (((uint32_t)(eeprom_read_word(EEDATA16.EnergyCounterUpper)))<<16); |
172 | EnergyCounter += (((uint32_t)(eeprom_read_word(EEDATA16.EnergyCounterUpper)))<<16); |
| 172 | #ifdef POWER_SNS_PIN_ch2 |
173 | #ifdef POWER_SNS_PIN_ch2 |
| 173 | EnergyCounter_ch2 = eeprom_read_word(EEDATA16.EnergyCounterLower_ch2); |
174 | EnergyCounter_ch2 = eeprom_read_word(EEDATA16.EnergyCounterLower_ch2); |