You can reduce your circuit to just a handfull of cheap components as per my appended circuit...
D2 Rectifies the incoming AC from the transformer. It could be full-wave rectification here (rather than the half-wave example), but remember if you have full-wave then you'll get 120Hz and not 60Hz at the juction of D3 and R1.
With 24V input from the Transformer, and 9V from the Battery, D1 is biased-OFF and Battery consumption is zero. If the AC Power fails, D1 immediately biases ON and supplies power without any need for the PIC to get involved.
R1/R2 form a potential divider so that the PIC's AC fail detect pin never gets more than +5v. Chose a PIC pin with Schmit input (which is pretty much most of them). PIC detects AC fail when 60Hz (120Hz) pulses stop arriving at it's chosen pin.
As per your requirement... using just one PIC pin and very few components... If anyone can figure something simpler/cheaper, I'd like to see it...
Melanie




Bookmarks