Power management and frequency regulation for microgrid and smart grid: A real-time demand response approach