Bell protocol has changed over the years, and was for a long time dependent on each RR's policy. Examples I recall from long ago is SP would ring the bells as long as the lights were flashing, and ATSF would ring during flashing but if there were gates it was only while gates were going down or up, with a few seconds of ringing before gate activation. Current local practice (CN) is bells ring before and while gates are lowering only.
The logic behind ringing when gates are raising is to remind pedestrians about the counterweight.
I'm sure there are now FRA and/or NHTSA rules determining when bells are rung, or not, and possible relationships to "quiet zones" when applicable.