This is the job of the “governor”. As others have stated, it comes down to making sure the “thing” is spinning at a constant speed. Whether it’s a hydroelectric turbine, a gas turbine, a diesel engine, etc… Those things are designed to produce power up to a certain rating. As long as the “thing” is spinning at a constant speed, it will output power up to that rating. The governor is the device that makes sure it’s spinning at the appropriate speed. As load goes up, generator speed goes down, so the governor will compensate and ensure speed is maintained.
Latest Answers