Download PowerSocket - The Media Computing Group
Transcript
3.2 Software design 35 a GPI/O pin is not needed anymore, it can be unallocated with the function gpio free(portpin). To make use of the metrology engine of the EM773, the EM773 SDK contains a module that controls this engine. Before using the metrology engine, it first needs to be configured. This is done by calling metrology init(AHBClkFrequency, Fmains), which needs the clock frequency (AHBClkFrequency) and the frequency of the mains (Fmains). If Fmains is set to EM AUTO, the mains frequency is detected automatically and returned as the result of the initialization function. The second step of the configuration is to call metrology set ranges(ranges). How the parameter ranges is used, is extensively explained in the user manual of the EM773. Before any metering data becomes available, the metrology engine has to be started. This is done with metrology start(). To stop the metering, metrology stop() can be called. To obtain metering data from the metrology engine the function metrology read data(metrology result) has to be used. This function writes the metering data into the variable pointed at by the pointer parameter metrology result, if metering data is available. The function returns whether reading metering data was successful or not. This concludes the part, in which I describe the modules I used from the EM773 SDK. In the next part I will talk about the modules I have added myself. To refresh the data from the metrology engine in a certain time interval and to make it available, I added the module metering to the package METROLOGY. The functionality of the refreshing is based on a timer. The used timer is configured to count milliseconds. An interrupt is fired and the counter resets, when the counter reaches the value of the define METERING INTERRUPT FREQUENCY. The corresponding ISR reads out the data using the function metrology read data(&metering result). The metering data is then available in the The function variable metering result. Initialise Metering() handles the configuration of the complete metering system. This includes calling the functions metrology init(AHBClkFrequency, the module metrology can be used to control the metrology engine init functions must first be called before use after starting the metrology engine, its data can be read with a read method I wrote a module that makes sure update metering data is available the init function of this module, takes care of the complete initialization of the metrology engine