All Forums
 Microsoft Windows CE
 CE Sample Applications and Utilities
 Detecting power failure on the Bitsy
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

akidder

1519 Posts

Posted - 18 Dec 2002 :  18:27:34  Show Profile  Email Poster
Q: My Bitsy system uses backup power on the VBatt_Pos input.
1. How can my application know if main power has failed?
2. How can it wake up automatically when power is restored?


There are several options available to you. Some involve external hardware. The one detailed in this example has the advantage that it uses the resources already on the Bitsy and doesn't require external circuitry to recover from power failures.

Application Description

This example assumes that you are monitoring the DCIn_Pos line with ADSmartIO A/D PA0. You could also use an external, digital voltage level sensor connected to a digital I/O.

This application polls the A/D regularly using the MainPowerOk() function. When power fails, the application puts the system to sleep. If you want your system to wake up when power is restored, the system can wake up periodically and test if the power failure has ended.

The following pseudocode illustrates this concept. It includes options for both manual and automatic wakeup from power fail.


//-------------------------------------------------------------------
//
// This routine checks the main power once per second and puts
// system to sleep if main power has been removed.
//
// "Critical systems" are application-specific hardware or data that
// must be prepared for turning off external power. These functions
// are optional.
//
// Note that serial and Ethernet port drivers will re-initialize
// themselves upon wakeup, so you don't need to do anything special
// with them. However, if you have to reinitialize (or de-initialize)
// the devices on the other end of the serial port, the
// "CriticalSystems" functions are the place to do it (if the hardware
// been powered off, it may have have forgotten how you configured it).
//
// As long as backup power is not interrupted while the system is
// asleep, data will be intact and the application will resume
// running where it left off when the system reawakens.
//
//-------------------------------------------------------------------
void PowerManagementThread()
{
while (TRUE)
{
if (MainPowerOk())
Sleep (1000); // check main power once every second
else
{
ShutDownCriticalSystems();
Sleep(250); // make sure everything has settled (optional)

// PutSystemToSleepForTime(60); // sleep for sixty seconds, then check power again
PutSystemToSleep(); // sleep until awakened with the RqOnOff signal
Sleep(250); // system goes to sleep somewhere during this time

// system is awake now; check main power immediatly
if (MainPowerOk())
RestartCriticalSystems();
}
}
}

//-------------------------------------------------------------------
// This routine reads an A/D input connected to the power input and
// determines if the main power is still valid. Assumes that the
// power input is connected to the A/D input through a 1/11 voltage
// divider (e.g. 100k and 10k resistors).
//-------------------------------------------------------------------
BOOl MainPowerOk()
{
UINT reading;
float voltage, minVoltage=8.0, vRef=2.5, multiplier=11.0;

reading = SIOAnalogConversion(1); // assumes channel 0 (PA0) connected to DCIN_Pos
voltage = reading/1023 * Vref * multiplier;

if (voltage > minVoltage)
return TRUE
else
return FALSE;

}


//-------------------------------------------------------------------
// Puts system to sleep. System must be awakened manually (RqOnOff)
//-------------------------------------------------------------------
void PutSystemToSleep()
{
keybd_event(VK_OFF,0,0,0); // simulate pressing the "power off" key
}


//-------------------------------------------------------------------
// Puts system to sleep. Wakes after sleepDur seconds (minimum
// is 15 seconds)
//-------------------------------------------------------------------
void PutSystemToSleepForTime(int sleepDur);
{
// see topic.asp?TOPIC_ID=649 for
// an example of how to wake at regular intervals
}

For further reading, see the CE power management topic index.

Drew Kidder
ADS Technology Transfer

Edited by akidder 11-Feb-2003: add link to topic index

kurtwl

28 Posts

Posted - 26 May 2004 :  04:01:05  Show Profile  Email Poster
BitsyX, CE Ver 4.20 (0), BitsyX CE 4.20.07 (EVC4)
Using ADSmartIO Wrapper class

In a previous version of CE,
reading = SioAnalogConversion(Channel 7)

voltage = (reading/1023.0f) * ref * multiplier;
ref = 2.5f and multiplier = 7.2f
gave me a battery voltage that was within 80 mV.

Since V4.20.07 the voltage derived like this is higher by 'full' volts, and is not a consistant offset.

I 'guessed' the channel from the BitsyX manual as it is on PA7.
Is this how the channels are supposed to be worked out?


Reading ReadPortA and looking a bit 5, gives me DC_GOOD.

Additionally using SetKeyPadSize(1,1) with a 1 key keypad does let me see the keypress (since the 4.20.07 update)

Additional to the 'rubbish' voltage read, if the key is pressed repeatedly, there are occasional moments when DC_GOOD drops.

I have only one ADSmartIO instance, have dispensed with threads and only have one loop watching for the keypress (which also acts as the 'timer') with SetSSPTimeout set to 200, and doing the other things.

Given that the smartio library is not thread safe, and i want to watch for:
DC_GOOD, the battery voltage, RQONOFF, the Sleep/Power events from CE, and the keypress,
Can it be done (as the SIOAnalogConversion and KeyPad ports seem to overlap)?
Has something changed in the SioAnalog chanel 7, is that even the right one? (The SmartIO documentation does not even list the Bitsy as relevant)

Can I use multiple threads to do what I want?
Is SioAnalogConversion for BatteryVoltage on channel 7 'broken'?
Given that SetKeypadSize of any legal dimension caused errors (on debug port) before, but the voltage thing worked, has the fix for the keypad upset other things?

Continuing the saga:
If I remove all KeyPad related smartio functions from the application, running on a freshly booted Bitsy, the voltage reads are fine.
Add ReadKeypad or SetKeypadSize and run again, and the volage is squiffied. Remove and rerun, still squiffed. Reboot and run, fine.

Reboot , run keypadless application, voltage ok. run the KeyMon sample application, and immediately the voltages get trunced.

Edited by - kurtwl on 27 May 2004 09:19:20
Go to Top of Page
  Topic  
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.05 seconds. Snitz Forums 2000