Microgrids and their interconnection with main grid are gaining importance nowadays. Usually inverters acts as power interface between the renewable energy resources and main electrical network. This paper focuses on design and simulation of a simple and easy to implement controller for the operation of this inverter in MATLAB SIMULINK environment. This controller enables the microgrid to operate in grid parallel as well as in standalone mode. Phase locked loop (PLL) is used to lock grid frequency and phase. A simple but effective quasi-active islanding detection algorithm is used for transition between the modes. Simulation shows the effectiveness of this algorithm combined with the control strategy, in minimizing the non detection zones, through different loading conditions. Simulations also show the algorithm's ability to distinguish between the islanding event and load variations.