Energy Management Electronic Device for Islanded Microgrids Based on Renewable Energy Sources and Battery-Based Energy Storage

Energy management systems are one of the most important components in the operation of an electric microgrid. They are responsible for ensuring the supervision of the electrical system, as well as the coordination and reliability of all loads and distributed energy resources in order for the microgrid to be operated as a unified entity. Because of that, an energy management system should be fast enough at processing data and defining control action to guarantee the correct performance of the microgrid. This paper explores the design and implementation of an energy management system deployed over a dedicated electronic device. The proposed energy management device coordinates the distributed energy resources and loads in a residential-scale islanded microgrid, in accordance with a rule-based energy management strategy that ensures reliable and safe operation of the battery-based energy storage system. A hardware-int-he-loop test was performed with a real-time simulation platform to show the operation of the electronic device.


Introduction
Increasing energy requirements, along with a general concern about global warming caused by the use of conventional energy sources based on fossil fuels, have triggered the use of renewable energy sources (RES) (Keyhani, 2016). Particularly, RESs based on photovoltaic (PV) and wind turbine (WT) generation units have been playing an important role, due to their availability and easy integration by means of power electronics conversion stages (Teodorescu, Liserre, and Rodriguez, 2010). Nevertheless, PV and WT generation are characterized by their high variability and dependence on weather conditions, which make it difficult to control and regulate the amount of power obtained (Jurasz, Mikulik, and Krzywda, 2017). Because of that, energy storage systems appear as a viable option to compensate the variability of the RESs (Beaudin, Zareipour, Schellenberg, and Rosehart, 2015). Mainly, energy storage systems (ESS) based on batteries have become the most reliable option to complement the operation of variable RESs since, in general, batteries have a good commitment between power density, for compensating quick changes in the generation profiles, and provide energy density to ensure back up of energy, for supporting the power balance in the electrical system.
Through the integration of distributed RESs, ESSs, and loads as shown in Figure 1, it is possible to configure an islanded microgrid in which all distributed energy resources should operate coordinately, governed by an energy management system (EMS) in order to ensure the reliability of the islanded power system and support the load requirements (de Matos, e Silva, and Ribeiro, 2015). In the microgrid, the EMS is responsible of defining and providing proper control commands to all distributed energy resources, in accordance with predefined strategies or control objectives that range from simple rule-based or reactive methods, to more complex ones based on optimization, or even hybrid methods based on the combination of the former two (Luna, 2016;Rafique and Jianhua, 2018;Hofman, Steinbuch, van Druten, and Serrarens, 2006). Therefore, the EMS becomes an important component of the microgrid, which should be able to perform complex operation with high processing speed, have enough capability for data storing and processing, and rely on communication modules for the integration with other components of the microgrid (Al sumaiti, Ahmed, and Salama, 2014). In spite of this, the EMS comprises different components by itself, such as sensors, smart metering infrastructure, communication channels, the device itself, and the embedded software. In particular, the development of the last two have been of interest for different manufacturers in order to obtain a more compact and efficient embedded onchip-based system (Al sumaiti, Ahmed, and Salama, 2014;Liu, Qiu, Fan, Zhu, and Han, 2016). In order to validate the performance of a designed EMS device, it is possible to use dedicated test platforms in which microgrid behavior, power electronic devices, and primary controllers can be simulated in real-time, while the physical hardware, where the EMS and control actions are embedded, is integrated into a closed-loop in order to emulate a real interaction with the microgrid (Casolino, Russo, Varilone, and Pescosolido, 2018;Wang, Nguyen, Xu, and Shi, 2020). These kinds of experimental platforms are defined as hardware-inthe-loop (HIL) and are commonly used an accepted for the validation of control and management strategies in a real hardware environment (IEEE, 2018). HIL allows a rapid prototyping and performance test of the electronic device by emulating the behavior under real conditions without complex lab setups (Montoya et al., 2020;Estrada, Vázquez, Vaquero, de Castro, and Arau, 2020;Sun et al., 2020).

RES
For an islanded, RES-based residential microgrid based, variability in power generation and consumption is not the only fact to consider within the operation of the power system. As a matter of fact, the operation of the batterybased ESS is critical for an islanded microgrid due to its capacity for storing or releasing energy. Hence, the ESS unit commonly assumes the responsibility of regulating the balance between generation and consumption, and, consequently, the regulation of the local power system (Pecas Lopes, Moreira, and Madureira, 2006). Therefore, it is important to consider the limitations and requirements on the operation of the battery-based ESS, since they cannot store an infinite amount of energy and they have important limitations within their operation that should be considered. Particularly, Li-ion batteries and Lead-Acid batteries are the most used in islanded power systems such as microgrids, since they offer a good commitment between deep-cycle and lifespan (Beaudin, Zareipour, Schellenberg, and Rosehart, 2015). On top of that, it is important to consider that those kind of batteries are voltage-limiting devices whose operation limits should not overcome certain typical maximum and minimum boundaries defined by the manufactures under risk of degradation or damage (Battery University, n.d.; Buchmann, 2016). Here is where the coordination and energy management system becomes crucial for the operation of the microgrid; based on this information, a rule-based EMS can be considered for ensuring the proper dispatch and transitions between different states an operation modes of the microgrid (IEEE, 2017).
Several approaches have been proposed for a proper coordination and energy management of distributed energy resources in microgrids in the search for a proper operation of the ESSs within safe ranges (Kim, et al., 2010;Mahmood, Michaelson, and Jiang, 2015;Mao, Huang, and Chang, 2013). Particularly, in Díaz, Luna, Vázquez, and Guerrero (2017), a centralized coordination strategy based on the definition of simple supervisory stages was previously proposed. This strategy was deployed in a laboratory text platform where it showed to be effective at ensuring the regulation of the islanded electrical power system and keeping the ESS within safe operation values.
In accordance with the aforementioned, this article presents the design and implementation of an electronic device that acts as an EMS for a residential-scale isolated microgrid based on variable RESs and a battery-based energy storage system, as shown in Figure 1. Given that the EMS will act as a central control unit, it must take into account the variability of renewable resources together with the loads and execute a management algorithm to ensure the reliability of the isolated energy system. In order to test the electronic device, a simple rule-based management strategy, already presented by Díaz et al. (2017), is embedded into the EMS device. In the following sections, the rule-based management strategy will be outlined for an isolated microgrid whose model has been implemented on a real-time simulation platform (OP4510). Next, based on the requirements derived from the simulation, the design and implementation of the electronic device that will act as EMS are explained. For the validation of the device, the HIL method will be used, connecting the EMS to the ports of the real-time simulation platform OPAL® OP4510. Finally, the results obtained from the validation will be presented. Figure 1 shows the basic structure of the islanded microgrid considered for this application. The microgrid has a DC configuration in order to avoid dealing with problems of reactive power and frequency regulation within the model. The microgrid consists of a hybrid PV-WT generation unit, an ESSs based on batteries, and AC loads integrated through a DC/AC conversion stage. Commonly, ESSs are responsible for ensuring the power balance and the regulation of the common bus in the local power grid. Meanwhile, RESs are more likely to operate as power sources at their maximum power point in order to harvest the maximum amount of available energy. Since ESSs have limited storage capacity, overcharge and over-discharge should be avoided to prevent degradation of the storage units. Since, for islanded applications, Lead-acid and Li-ion batteries are the most used technologies, it is important to consider that they are voltage-limiting devices. Because of that, their operation limits are defined by voltage levels, whose maximum value (V max ) roughly corresponds to a 90% of the state of charge (SoC), while the minimum (V min ) roughly corresponds to a 20% of the SoC (Marra and Yang, 2015). Figure 2 shows the desired profile for the operation of a battery. In this Figure, three stages or operation modes can be identified. The first stage corresponds to a normal charge or discharge of the battery within safe operating limits. In this stage (S1), called MODE I from now on, the battery will absorb or inject power in accordance with the difference between generation and consumption. Because of that, the battery will be charged or discharged. The second stage corresponds to the moment in which the battery has reached its maximum charge limit, defined by V max . This stage will be called MODE II. Here, the charge of the battery should be stopped in order to overpass the maximum voltage limit. Finally, the third stage is when the battery reaches its minimum voltage threshold an then the discharge should be stopped. This this stage is called MODE III.

Description of the desired operation
In light of the above, the operation of the islanded microgrid should be complemented by a management strategy that keeps the operation of the battery within safe regions. As mentioned before, the ESS is responsible for the regulation of the islanded power grid. Therefore, it will operate in voltage control mode, defining the voltage level of the islanded power grid. Then, the battery will be charged when the generation is larger than consumption or discharged in the opposite case. When the battery reaches its maximum level of operation, the ESS will not be able to continue absorbing energy and charging the battery. For that reason, an active power curtailment of RES generation is considered when the battery reaches its maximum voltage in such a way that the generation from PV (P PV ), and WT (P WT ) is balanced with the consumption (P Load ).
The power curtailment of each RES unit can be defined proportionally to its maximum available power (P PVMP ) and (P WTMP ), which can be obtained from maximum power point tracking methods such as the one presented by Trujillo Rodríguez, Díaz Aldana, and Hernández Mora (2015) and Patsios Chaniotis, Rotas, and Kladas (2009) for PV and WT, respectively. Thus, Equation (1) can be rewritten as: where (α PV ) and (α WT ) are defined as the curtailment indexes for PV and WT, respectively, which should be calculated in the EMS responsible for the management strategy. In order to have a contribution of each RES in proportion to its maximum available power (P RESMP ), the following condition is established: Otherwise, when generation is less than consumption, the battery will be discharged until it reaches its minimum voltage level. In this case, the option is to disconnect the load unless there is another dispatchable source available that can supply the load. Once the load has shed, the battery will be charged in accordance to the generation from RES.

Operation modes
In accordance with the operation modes described above, it is possible to define a finite state machine (FSM) programmed into the energy management system, which coordinates the operation of the distributed energy resources within the islanded microgrid. The states in the FSM correspond to the operation modes, described as: • Mode I: The ESSs is charged (S1) or discharged (S2) based on the imbalance between supply and demand.
• Mode II: The ESS is fully charged and the power generation should be curtailed to avoid overcharge. The curtailment index is calculated.
• Mode III. The ESS reaches its minimum charge levels of charge and the load should be disconnected to avoid over-discharge.
The transitions between states or operation modes are defined by discrete events: • From Mode I to Mode II: The battery voltage (V batt ) reaches its maximum value (V max ).
• From Mode II to Mode I: The maximum available generation from RES becomes less than the load consumption (P Load < P PVMP + P WTMP ) • From Mode I to Mode III: The battery voltage (V batt ) reaches its minimum value (V max ).
• From Mode III to Mode I: The SoC of the battery reaches a value of 50%.

Microgrid Simulation
The microgrid model has been built in Simulink, where two 24-hour PV and WT generation profiles will be used with data sampled in 5-minute periods and two 24-hour load profiles with data sampled every hour. Since the battery operation is one of the most important issues to consider in the operation of the microgrid, a detailed model of a Li-ion battery, able to emulate the internal losses and the slow and fast dynamics, has been used as proposed in Kim and Qiao (2011). The RESs are modeled and controlled as power sources; they are able to provide a generation profile. Meanwhile, the load has been modeled as an inverter controlled as a power load. The SoC is estimated by the commonly used ampere-hour (Ah) counting method as: where SoC(0) is the initial SoC, C bat is the capacity in (A · h), η batt is the charging/discharging efficiency, and I batt (τ) is the instantaneous current in the battery.
To avoid running the simulation during the full 24-hour period, its time has been scaled. Therefore, a real hour corresponds to 12 seconds in the simulation. Thus, the shortest period of change in values corresponds to 5 minutes of the generation profiles, which in the simulation corresponds to 1 second. In order to warn EMS that there was a change in the microgrid, a digital square signal with a period of 0,5 seconds will be generated for synchronization. With this, at least two values will be processed by the EMS before a change occurs in the simulation.
The Simulink-based microgrid model has been embedded in the OPAL® OP4510 real-time simulation platform. Therefore, by taking advantage of the analog and digital input and output ports of the OP4510, it is possible to have a real interaction with external devices. The embedded microgrid model provides measured variables such as the instantaneous power output of the PV and WT generators (P PVMP and P WTMP ), the state of charge of the battery (SoC), the battery voltage (V batt ), and the power consumed by the load (P Load ) through analog outputs. Also, external control instruction can be received by the microgrid, such as the curtailment indexes of the two generators(α PV and α WT ) through analog inputs, and the on/off control signal for the load through a digital input, as well as generating a synchronization signal to enable the communication with external devices through a digital output. Table 1 summarizes the input and output ports used for the interaction with the microgrid.

Source: Authors
The model defined for the rule-based management strategy requires the energy management device to perform mathematical operations such as solving a system of equations composed by Equation (2) and (3), which allow obtaining the curtailment indexes of the generators when the microgrid operates in MODE II. In addition, the energy management device should be able to capture and generate both analog and digital signals for proper interaction with the simulation platform.

EMS Device Design and Operation
Considering the requirements mentioned above, it is established that the EMS device will consist of a processing unit with an integrated operating system that allows executing scripts in a high-level language in order to implement the coordination strategy state machine in an agile way and perform the necessary calculations. As a processing unit, an Orange Pi Zero single board computer (SBC) is used, which has an Allwinner H2 + ARM® Cortex®A7 QuadCore processor with 512Mb of RAM memory running the Armbian operating system. This SBC was selected taking into account that it is an open source development board with a low cost ($12 dollars per unit), with a high processing capacity due to its technical characteristics, and with high availability in the market. Although the processing capacity of the SBC is high, it does not have analog I/O pins. Therefore, it is necessary to integrate an additional component with this kind of pins. As a coupling interface is used, an STM32L476RG microcontroller that has an Arm® Cortex®M4 processor with a maximum working frequency of 80Mhz, 1Mb of flash memory and 128Kb of RAM memory, which is mounted on an STM32L476 NUCLEO development board from STMicroelectronics®. This microcontroller has 3 units, 12 bits ADCs with a working frequency of up to 5Msps and up to 24 input channels, a 12 bits DAC with 2 output channels, as well as multiple communication protocols and GPIO pins. Because the voltage window for both the ADC and the DAC in the microcontroller is 0 to 3,3 VDC, the analog inputs and outputs values of the OPAL® OP4510 simulation platform have been scaled to this range to avoid damaging the EMS. The SPI protocol is selected for communication between the SBC and the microcontroller with a frequency of 1Mhz. The SBC performs the communication as master. A complete representation of the device integrated with the simulation platform is shown in Figure 3. Figure 3. Structure of the EMS electronic device integrate to the microgrid.

Source: Authors
The state machine that executes the rule-based management strategy is implemented on the SBC with a Python3 script. The Numpy library is added to the script, which allows to operate vectors and matrices, and is suitable for solving the equation systems to obtain the curtailment indices of the generators. Within the state machine script, the communication functions with the microcontroller are added to get the analog values and send the curtailment indexes.
A pseudo-code of the Python3 script is shown in Pseudocode 1. In the microcontroller, a firmware is implemented with the C language using the HAL libraries provided by STMicroelectronics®, which allows to perform the SPI communication with the SBC, read the pins of the ADC channels, and set the analog curtailment indexes using the two channels of the DAC. A pseudo-code of the microcontroller firmware is shown in Pseudo-code 2. The operation of the EMS integrated with the simulation platform can be described as follows: with one of the digital pins of the microcontroller, the synchronization pulse of the simulation is received. This indicates that it has to read the analog variables through the 5 channels of the ADC, which takes approximately 50 us. At the end of the reading, the microcontroller activates a pin connected to the SBC that indicates that there is data ready to be processed. The SBC, acting as an SPI master, receives this data in a fixed size frame. The received data is converted to the real values (because they are scaled to values between 0 and 3,3 V) and the current mode of the state machine is verified. If it is in MODE I, the curtailment indexes ((α PV ) and (α WT )) are 1 and the load is on; if it is in MODE II, the new vales of the curtailment indexes are calculated; and if it is in MODE III, the state of the load is changed to off. This procedure is performed in period of less than 100 ms, the curtailment indexes and the state of the load are sent to the microcontroller in another fixed size frame where they are processed. The curtailment indexes are setting in the outputs of the 2 channels of the DAC and the state of the load in a digital pin, where a value 1 corresponds to load on and 0 to load off. These steps are executed in less than 20 us. Including the sending and receiving times of SPI frames that take approximately 300 us, the complete processing time of each sample is less than 150 ms, with which the samples that have to be taken every 0,5 seconds can be processed correctly.

Experimental Validation
A hardware-in-the-loop (HiL) test platform has been used for validating the operation of the EMS electronic device. The test platform is composed of the EMS electronic device, a real-time simulation OPAL® OP4510, and a console for data acquisition and visualization as shown in Figure 4.  The microgrid model has been built in Simulink and embeds into a real-time simulation platform. Table 2 presents the main parameters of the islanded microgrid.
The operation of the system has been tested by using different generation a load profiles. In the case of the generation, the profiles change every 5 minutes, and, in the case of the load, the profile changes every hour.  6 show the results obtained from the experimental platform with two different generation and load profiles. In Figures 5 and 6, it is possible to see that, when the battery reaches its maximum voltage value (V batt = V max ), the operation of the microgrid changes to MODE II. As a consequence, the power generation from RESs (P PV ) and (P WT ) is curtailed below their maximum available power (P PVMP ) and (P WTMP ) to keep the power balance in the system, and preventing the battery from overcharging. It can be seen that even in the accelerated simulation of the microgrid, explained in a previous section, the EMS devices manage to deal with all the required processes in the ruled-based management system.

Conclusions
The capability of the HIL method to represent real variables of a Simulink simulation as electrical outputs allows the execution of tests to hardware control devices in real-time. This fact minimizes the initial need to have a real system plant, which comprises a system of medium complexity devices in the case of a microgrid.
It is possible to implement a rule-based management strategy based on state machines focused on improving the lifespan of the energy storage resource, which is one of the most critical components in the microgrid. This, by taking advantage of the processing capacity of a single board computer working in conjunction with a microcontroller. On top of that, it is important to consider the possible limitations in the selection of the electronic device, such as the ability of the device to generate responses in real-time. In particular, it is important to consider the processing times, data representation, and resolution of ADC and DAC converters for more accurate answers.