Canon offers an excellent automated flash exposure system they call E-TTL. This system does an excellent job in many situations of automatically controlling electronic flash exposure.
If you use a pop-up flash in a Canon DSLR or have put a canon Speedlight (such as a 430EX or 580EX) in the camera hot shoe you are almost certainly using E-TTL flash. In general you should avoid on camera flash, except when you want a bit of fill flash, but this is another subject entirely. You can also use E-TTL mode with the light off camera via an E-TTL extension cable of some kind, or via a wireless E-TTL system of some kind.
The basic concept in E-TTL flash is that you don't know what you are doing, or don't care about the details of what is going on, and are willing to simply trust the camera. This is useful when you cannot give your full attention to setting up flash exposures, or you would like the camera to be controlling the flash due to rapidly changing exposure situations.
Exactly what the algorithms or rules the camera uses when doing E-TTl are essentially undocumented -- but people have figured out a lot of the details.
The first critical concept is the concept of subject and background. As far as the camera is concerned, the subject is whatever the autofocus system decided to focus on (the closest thing with recognizable detail). The camera calculates the flash exposure for the subject, i.e. it calculates flash exposure based on the distance the autofocus system determined for this closest object. As far as the camera is concerned, the rest of the field is background. The camera relies on ambient light to illuminate the background and will if possible try to set up a proper exposure for the background as if there was no flash.
Remember that shutter speed has no effect on flash exposure. You use the aperture to control flash exposure, and the shutter speed to control the ambient. If you are using any kind of automatic mode (Av, Tv, or P), you are giving up control of one or the other.
The camera makes a decision to use the flash as fill (when it measures a lot of light on the subject) or as the main light (when things are pretty dark). It would be worth doing some experiments to investigate this, but rumor has it that when light levels are 10 EV and below, the camera switches to main light and when light levels are 13 EV or higher, it does fill light. Nobody knows what happens at EV 11 or 12. None of this has been spelled out by Canon in any manual or document I am aware of.
Note that "the rules" for Nikon cameras are reported to be quite different.
One setting for EV 10 would be 1/60 f/4
One setting for EV 13 would be 1/60 at f/11
Tom's Digital Photography Info / [email protected]