Move SDM120 modbus updates out of ticker interrupt

Move SDM120 modbus updates out of ticker interrupt (#6282)
This commit is contained in:
Theo Arends 2019-09-07 16:31:39 +02:00
parent 4837e8e6d8
commit fc2be92478
2 changed files with 13 additions and 19 deletions

View File

@ -88,7 +88,7 @@ struct ENERGY {
unsigned long kWhtoday; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = Energy.daily
unsigned long period = 0; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = Energy.daily
uint8_t tenth_second = 0;
uint8_t fifth_second = 0;
uint8_t command_code = 0;
uint8_t data_valid = 0;
@ -165,16 +165,13 @@ void EnergyUpdateTotal(float value, bool kwh)
/*********************************************************************************************/
void Energy100ms(void)
void Energy200ms(void)
{
Energy.power_on = (power != 0) | Settings.flag.no_power_on_check;
Energy.tenth_second++;
if (30 == Energy.tenth_second) {
Energy.tenth_second = 0;
}
if ((Energy.tenth_second % 10) == 0) {
Energy.fifth_second++;
if (5 == Energy.fifth_second) {
Energy.fifth_second = 0;
XnrgCall(FUNC_ENERGY_EVERY_SECOND);
@ -209,13 +206,7 @@ void Energy100ms(void)
}
}
if (Energy.tenth_second &1) {
XnrgCall(FUNC_EVERY_200_MSECOND);
}
if ((Energy.tenth_second % 3) == 0) {
XnrgCall(FUNC_EVERY_300_MSECOND);
}
}
void EnergySaveState(void)
@ -728,7 +719,7 @@ void EnergySnsInit(void)
Energy.kWhtoday_delta = 0;
Energy.period = Energy.kWhtoday_offset;
EnergyUpdateToday();
ticker_energy.attach_ms(100, Energy100ms);
ticker_energy.attach_ms(200, Energy200ms);
}
}
@ -907,6 +898,9 @@ bool Xdrv03(uint8_t function)
case FUNC_LOOP:
XnrgCall(FUNC_LOOP);
break;
case FUNC_EVERY_250_MSECOND:
XnrgCall(FUNC_EVERY_250_MSECOND);
break;
#ifdef USE_ENERGY_MARGIN_DETECTION
case FUNC_SET_POWER:
Energy.power_steady_counter = 2;

View File

@ -78,7 +78,7 @@ struct SDM220 {
/*********************************************************************************************/
void SDM120Every300ms(void)
void SDM120Every250ms(void)
{
bool data_ready = Sdm120Modbus->ReceiveReady();
@ -262,8 +262,8 @@ int Xnrg09(uint8_t function)
case FUNC_INIT:
Sdm120SnsInit();
break;
case FUNC_EVERY_300_MSECOND:
if (uptime > 4) { SDM120Every300ms(); }
case FUNC_EVERY_250_MSECOND:
if (uptime > 4) { SDM120Every250ms(); }
break;
#ifdef USE_SDM220