## 2 Micro-Grid Description and Experimental Setup
### Software Design  
The acquisition software and the triggering processes have been designed to facilitate the recording of interesting waveforms without running out of disk space. The system uses a circular buffer to store the temporarily sampled values in memory. Triggers, running in real time, provide the appropriate signals to store data permanently before overwriting the buffered samples. Therefore, the performance of these triggers must be tuned, as they have to run at the same speed as the acquisition threads. In addition, the software design allows for running in unattended mode, recording the triggered waveforms for later offline analysis. It is worth noting that the signals are stored without filtering or processing for their offline analysis without losing any information.  
The program has been written in Python using the API available in the nidaqmx package. A block diagram can be seen in Figure 3 showing the aforementioned circular buffers, the internal (DC) trigger, the external (AC) trigger and the storage manager.  
The data acquisition is performed by registering an event every N samples (50,000) for each board. Data are read in one callback for board. These two callbacks use multichannel readers to avoid data losses when hardware acquisition runs at high speed, as is the case. Once the data have been read, they are sent via Python Queues. A worker thread reads this (thread-safe) queue and stores the samples in two lists acting as circular buffers.  
The same information is sent to the software trigger modules and a positive response fires the recovery and writing of all pre-trigger information. The trigger signals coming  
Figure 3: Data acquisition software design.  
Figure 2: Part of the measurement system: NI Chassis and MCTS II.  
from the different triggering modules are processed and combined in the _Multi-Trigger coordination_ module to avoid possible overlaps. Finally, once the software trigger has been fired, the subsequent data are written to a disk.  
Triggering mechanisms are modular and can be implemented within the main program, using the Python programming language, or externally using any other language. Thus, the DC signals' triggers have been implemented in Python, Section 3.1. In contrast, those using the AC signals are obtained from a library external to the main program (Section 3.2).  
Triggering using the AC signals is based on the PQ analysis of the three-phase waveforms and is performed by sending the acquired samples to a PQ server that uses CIRCE's libPQ library [16]. This library implements online Power Quality analysis following the stringent class-A requirements of the IEC 61000-4-30 [17] standard. Using these PQ parameters, the server can trigger the acquisition by means of a TCP _ad-hoc_ designed protocol. The PQ server is configured to evaluate the relevant PQ parameters (see Section 3.2). When some of these PQ parameters fall outside the allowed ranges, the PQ server sends back a signal to the DAQ program and stores the parameters causing that signal in a _PostgresQL_ database to trace the cause of the trigger and all the subsequent calculated PQ parameters.  
The system has enough RAM to handle several seconds in the circular buffers. The configuration of the buffers' size is adjusted to capture enough event information before the trigger without compromising the storage capacity. This parameter was chosen as one second based on several laboratory tests and can be tuned once the measurement system is on-site. Considering that the disk capacity is the main limitation, the system was configured for a maximum time of three seconds of continuous data recording in the triggering mode. Moreover, there is also the possibility of continuously writing data to test and debug all the analysis and trigger procedures.