In SX Microcontrollers, SX/B Compiler and SX-Key Tool, g_daubach wrote: Kramer, IMO, the comparator can be used for detecting low battery situations. But some thoughts are in order: Usually, one comparator input is connected to a reference voltage where the other is connected to the voltage to be monitored, i.e. Vdd in this case. The reference voltage, on the other hand, also has to be derived from Vdd by some means in a way that it is still stable enough when the supply voltage is reaching the battery-low warning level. I have attached a schematic showing one solution that might work - please note, I did not test this in reality. Let's assume for this example that the low-voltage warning level shall be 3.0 Volts: The reference voltage is derived from the voltage drop of about 0.6V across a silicon diode. With R1 = 22kOhm, the current through R1/D1 is about 100ľA @ 3V Vdd, and about 200ľA @ 5V Vdd. The voltage divider built by R2/R3 must be dimensioned that the voltage at RB2 comes down to 0.6V when the supply voltage drops close to 3V. With R2 = 22KOhm and R3 = 5.6kOhm, the current through R2/R3 is about 100ľA, and the voltage across R3 is about 0.6V. You might consider using a 10kOhm trim potentiometer for R3 to fine-tune the battery-low warning level. With supply voltages above 3V, the level at RB2 (the positive comparator input) will be above 0.6V. As RB1 (the negative comparator input) is held at 0.6V, the comparator output (RB0) will be high as long as the supply voltage is above the threshold, and it will go low when the supply voltage drops below the warning level. If you want inverted logic, just swap the RB1 and RB2 pins. There are various methods how to check the comparator status in the software. IMO, this is not time-critical at all. Therefore, it can be done within some program loop that is executed from time to time, and it must not necessarily handled by an ISR. On the other hand, port B bits, like RB0, the comparator output, can be used to trigger interrupts. So if you like, you can configure the SX in a way that an interrupt is fired when the supply voltage drops below the warning level. When a low-level situation has been detected, you can react on that with whatever comes to your mind, like sending a message via a serial port. I'm always amused by appliances that indicate a low-voltage situation by activating a "Battery Low LED". The current required for this LED makes sure that the battery will be dead even faster :-) . BTW: When doing things like this, make sure that the SX brownout detection feature is turned off (DEVICE BOROFF), or set to a value below the battery-low level (e.g. DEVICE BOR22 or BOR26). Otherwise, the SX would reset before detecting the battery-low status. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=94020#m94028 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)