power and programming guide

advertisement
Waspmote Power
Programming Guide
Index
Document Version: v0.6- 07/2012
© Libelium Comunicaciones Distribuidas S.L.
INDEX
1. Introduction.......................................................................................................................................... 3
2. General Considerations........................................................................................................................ 4
2.1. Waspmote Libraries......................................................................................................................................................................4
2.1.1. Waspmote PWR Files....................................................................................................................................................4
2.1.2. Constructor......................................................................................................................................................................4
2.1.3. Pre-Defined Constants................................................................................................................................................4
2.1.4. Sleep options..................................................................................................................................................................4
3. Waspmote Low Power Modes.............................................................................................................. 5
3.1. Sleep..................................................................................................................................................................................................5
3.2. Deep Sleep......................................................................................................................................................................................5
3.3. Hibernate.........................................................................................................................................................................................6
4. Modules Power Modes......................................................................................................................... 8
4.1. GPS Module.....................................................................................................................................................................................8
4.2. SD Card.............................................................................................................................................................................................8
4.3. Sensors..............................................................................................................................................................................................9
4.4. XBee...................................................................................................................................................................................................9
4.5. Accelerometer................................................................................................................................................................................9
4.6. GPRS Module............................................................................................................................................................................... 10
5. Extended Functions............................................................................................................................ 11
5.1. Set sensor board power........................................................................................................................................................... 11
5.2. Set Watchdog.............................................................................................................................................................................. 11
5.3. Clear Interruptions..................................................................................................................................................................... 11
5.4. Get battery level......................................................................................................................................................................... 11
5.5. Close I2C........................................................................................................................................................................................ 12
5.6. Setting Low Battery Threshold.............................................................................................................................................. 12
5.7. Checking if Hibernate............................................................................................................................................................... 12
6. Code examples and extended information...................................................................................... 13
-2-
v0.6
Introduction
1. Introduction
Waspmote has 4 different power modes:
••
ON: Consumption: 9mA
••
Sleep: The main program is stopped. Waspmote can receive interruptions by sensors and timers. This mode is controlled by
the Watchdog and is suitable for cycles from 32ms to 8s. Consumption is 62μA.
••
Deep Sleep: The main program is stopped. Waspmote can receive interruptions by sensors and by timers. This mode is
controlled for the RTC and is suitable for cycles of more than 8s. Consumption: 62μA.
••
Hibernate: The microcontroller and the modules are completely powered off. The RTC is able to wake the mote up again
when the programmed alarm is launched. This mode is suitable for long inactivity periods, from 8s to minutes, hours or
even days, months or even years. Energy is driven from the auxiliary battery. Consumption: 0,7μA.
Consumption
Micro
Cycle
Interruptions
ON
9mA
ON
-
All
Sleep
62μA
ON
32ms - 8s
Sensors and Watchdog
Deep Sleep
62μA
ON
8s - min/hours/days
Sensors and RTC
Hibernate
0,7μA
OFF
8s - min/hours/days
RTC
Most of the modules (GPRS, GPS, XBee, Accelerometer, ...) have 4 different power modes:
••
ON: Full functionality.
••
Sleep: this mode reduces the power consumption setting the modules in a special working mode which does not implement
all the functionalities. This mode is specific for each module and it is implemented by the manufacturer.
••
Hibernate: this mode reduces to the lowest possible power consumption without disconnecting the module. This mode is
specific for each module and it is implemented by the manufacturer.
••
OFF: Digital switches controlled by the microprocessor have been added to control independently the modules, being
able to turn them completely off. These switches control the following modules: XBee, GPS, Battery Monitor, 3V Sensors, 5V
Sensors and RTC General Switch.
*Note: Once the laboratory phase is completed and before the definitive installation, it is advised not to set the programming
jumper in order to reduce the power consumption of Waspmote to the minimum.
-3-
v0.6
General Considerations
2. General Considerations
2.1. Waspmote Libraries
2.1.1. Waspmote PWR Files
WaspPWR.h ; WaspPWR.cpp
2.1.2. Constructor
To start using Waspmote PWR library, an object from class ‘WaspPWR’ must be created. This object, called ‘PWR’, is created inside
Waspmote PWR library and it is public to all libraries. It is used through the guide to show how Waspmote PWR library works.
When creating this constructor, no variables are initialized by default.
2.1.3. Pre-Defined Constants
There are some constants defined in ‘WaspPWR .h’ to help understanding the code when reading the first time. These constants
are related to the internal Watchdog and battery level indicator.
2.1.4. Sleep options
Some constants have been defined to be used as input parameter in Sleep and Deep Sleep functions.
••
ALL_OFF: switches off all the switches in Waspmote. It closes UARTs too.
••
SENS_OFF: switches off the switches related with sensor board.
••
UART0_OFF: closes UART0 and switches off the switch related to the XBee.
••
UART1_OFF: closes UART1 and switches off the switch related to the GPS and multiplexer.
••
BAT_OFF: switches off the switch related to the battery level monitor.
••
RTC_OFF: switches off the switch related to the RTC.
-4-
v0.6
Waspmote Low Power Modes
3. Waspmote Low Power Modes
3.1. Sleep
Sleep (sensor interruption)
Before setting this state, some interruption by sensor should be programmed to be able to wake up the microcontroller from
this state.
The switches to switch off must be specified as input parameters.
This function returns nothing.
Example of use
{
PWR.sleep(UARTØ_OFF | BAT_OFF); // Sleep switching off UARTØ and battery monitor
}
Sleep (Watchdog interruption)
It enables Watchdog interruption to be able to wake the microcontroller up after the time specified.
‘timer’ --> it specifies the time before the Watchdog activates the interruption. Possible interval values goes from 32ms to 8s:
WTD_16MS0
WTD_32MS1
WTD_64MS2
WTD_128MS3
WTD_250MS4
WTD_500MS5
WTD_1S6
WTD_2S7
WTD_4S8
WTD_8S9
The switches to switch off must be specified as input parameters.
This function returns nothing.
Example of use
{
PWR.sleep(WTD_32MS, ALL_OFF); // Sleep switching off all the modules, waking up after 32 miliseconds
}
3.2. Deep Sleep
It enables RTC interruption to be able to wake the microcontroller up when the RTC alarm is launched. Possible interval values
start at 8s:
‘time2wake’ --> it specifies the time at which the RTC alarm will be activated. It must follow the next format: “DD:HH:MM:SS”
‘offset’ --> it specifies if ‘time2wake’ is added to the actual time or if this time is set as the alarm
‘mode’ --> it specifies the mode for RTC alarm
-5-
v0.6
Waspmote Low Power Modes
It uses Alarm1 on the RTC due to this Alarm has more precision than Alarm2
The switches to switch off must be specified as an input parameter.
It returns nothing.
Example of use
{
PWR.deepSleep(“00:00:00:10”, RTC_OFFSET, RTC_ALM1_MODE2,ALL_OFF);// Sleep switching all off, waking up after 10 seconds
PWR.deepSleep(“15:17:00:00”, RTC_ABSOLUTE, RTC_ALM1_MODE2,ALL_OFF);// Sleep switching all off, waking up at 17:00 on day 15th.
}
3.3. Hibernate
It switches the general switch off and enables RTC interruption.
When this function is called, Waspmote has no power and when RTC alarm is activated, the power will return to the board. This
will cause Waspmote initializes again, restarting the code from the beginning. Possible interval values go from 8s to minutes,
hours or even days.
‘time2wake’ --> it specifies the time at which the RTC alarm will be activated. It must follow the next format: “DD:HH:MM:SS”
‘offset’ --> it specifies if ‘time2wake’ is added to the actual time or if this time is set as the alarm
‘mode’ --> it specifies the mode for RTC alarm
It uses Alarm1 on the RTC due to this Alarm has more precision than Alarm2.
It returns nothing.
Example of use
{
PWR.hibernate(“00:00:00:10”, RTC_OFFSET, RTC_ALM1_MODE2);
// Disconnect general switch, waking up after 10 seconds
PWR.hibernate(“15:17:00:00”, RTC_ABSOLUTE, RTC_ALM1_MODE2,ALL_OFF);
// Disconnect general switch, waking up at 17:00 on day 15th.
}
When using hibernate, it is mandatory to use PWR.ifHibernate() function at the beginning of setup program function.
‘ifHibernate’ checks if we come from a normal reset or an hibernate reset.
Example of use
void setup()
{
// Checks if we come from a normal reset or an hibernate reset
PWR.ifHibernate();
...
}
It is necessary to follow the next steps when executing the program for first time after uploading it to Waspmote:
1.
2.
3.
4.
5.
Connect the battery.
Connect the button battery.
Switch Waspmote on.
Wait for red led to light on and off (this is made inside ifHibernate function).
Once red led is off, remove hibernate jumper.
-6-
v0.6
Waspmote Low Power Modes
If the hibernate mode is used in a script, RTC alarms must only be used to set the wake up from the hibernate mode. When the
hibernate jumper is not connected, any RTC alarm arriving while the code is running could cause internal collisions. The RTC
alarm is supposed to happen when Wasp is hibernating.
There are several way to set alternative alarms:
••
••
••
use the Watchdog
compare current time and date with previous conditions
use the function millis()
-7-
v0.6
Modules Power Modes
4. Modules Power Modes
Most of the modules are capable of controlling their consumption, by using a switch to disconnect them or using lowconsumption modes.
4.1. GPS Module
GPS module has a switch to manage the power on it. When GPS is no longer going to be used, it is recommended to disconnect
its switch to save more battery.
GPRS and GPS are multiplexed to the same UART, so a multiplexer has been used to manage them. To select GPRS module,
the multiplexer should be set to (1,1) and to select GPS module, the multiplexer should be set to (0,1). This operation is made
internally by ‘begin’ function.
This module has 2 operation modes: ON and OFF. These modes can be controlled connecting or disconnecting the switch.
Mode
Consumption
Features
ON
36mA
Default Mode. GPS is fully operational
OFF
0μA
Module disconnected from the battery
When GPS module is initialized, using ‘GPS .init()’, normal mode is selected by default. To start using the GPS module, it is
necessary to execute ‘GPS .setMode(GPS_ON)’ first and then ‘GPS .init()’.
To change the operation mode, ‘GPS .setMode’ should be used.
Example of use
{
GPS.setMode(GPS_ON); // Set GPS ON
GPS.init(); // opens UART1 and sets the proper value in the multiplexer
GPS.setMode(GPS_OFF); // Set GPS OFF
}
4.2. SD Card
SD Card has no switch, being connected directly to one of the microcontroller pin to power it.
This module has 2 operation modes: on and off. These modes can be controlled setting the corresponding microcontroller pin
to the appropriate value.
Mode
Consumption
Features
ON
0,14mA
SD is ON. Read and write allowed
OFF
0μA
Module disconnected from the battery
When SD Card is initialized using ‘SD.begin()’, on mode is selected by default. To start using the SD Card, it is necessary to execute
‘SD.begin()’ first, and then ‘SD.setMode(SD_ON)’ to power up the card.
To change the operation mode, ‘SD.setMode’ should be used.
Example of use
{
SD.begin(); // sets the corresponding pins as inputs
SD.setMode(SD_ON); // Powers SD card up
SD.setMode(SD_OFF); // Powers SD card down
}
-8-
v0.6
Modules Power Modes
4.3. Sensors
Sensors can be connected to Waspmote directly or using one of the sensor boards developed by Libelium. These sensor boards
can be powered by 5V or 3,3V. To turn these boards ON and OFF two different switches can be activated:
Example of use
{
PWR.setSensorPower(SENS_3V3,SENS_ON); // Sets the 3,3V switch ON
PWR.setSensorPower(SENS_5V,SENS_OFF); // Sets the 5V switch OFF
}
4.4. XBee
XBee module has a switch to manage the power on it. When XBee is not going to be used for sometime, it is recommended to
disconnect its switch to save more battery.
This module has 3 operation modes: normal, sleep and off. These modes can be controlled sending some commands to the
module or connecting/disconnecting the switch.
Mode
Consumption
Features
ON
37-64mA
Modules ON. Fully operational.
SLEEP
0,1-0,93mA
Can not receive or send packets
OFF
0μA
Module disconnected from the battery
When XBee module is initialized using ‘XBee.setMode()’, on mode should be selected. To start using the XBee module, it is
necessary to execute ‘Xbee.setMode(XBEE_ON)’.
To change the operation mode, ‘XBee.setMode’ should be used.
Example of use
{
Xbee.setMode(XBEE_ON); // Powers XBee up
XBee.setMode(XBEE_SLEEP); // Set XBee to sleep mode
XBee.setMode(XBEE_OFF); // Powers XBee off
}
4.5. Accelerometer
This module has 2 operation modes: hibernate and on. These modes can be controlled setting some internal registers to defined
values.
Mode
Consumption
Features
ON
0,65mA
Modules ON. Fully operational.
HIBERNATE
~0μA
Can not obtain acceleration values.
Can not generate interruptions.
When accelerometer is initialized, using ‘ACC.begin()’, continuous mode is selected by default. To start using the accelerometer,
it is necessary to execute ‘ACC.begin()’ first, and then ‘ACC.setMode(ACC_ON)’.
To change the operation mode, ‘ACC.setMode’ should be used.
-9-
v0.6
Modules Power Modes
Example of use
{
ACC.begin(); // opens I2C bus
ACC.setMode(ACC_ON); // Set accelerometer to continuous mode
ACC.setMode(ACC_HIBERNATE); // Set accelerometer to the lowest consumption mode
}
4.6. GPRS Module
GPRS module is connected to the battery directly, so it has not a switch to cut the power off.
GPRS and GPS are multiplexed to the same UART, so a multiplexer has been used to manage them. To select GPRS module,
the multiplexer should be set to (1,1) and to select GPS module, the multiplexer should be set to (0,1). This operation is made
internally by ‘begin’ function.
This module has 3 operation modes: normal, sleep and hibernate. These modes can be controlled sending some AT commands
to the module.
Mode
Consumption
Features
ON
10-400mA
Default Mode. GPRS is fully operational.
SLEEP (STAND-BY)
1-2mA
When GSM/GPRS is not used, enters this mode automatically. From time to time, it
communicates with carrier to maintain the connection.
HIBERNATE
56μA
It can not receive or make calls, neither communicate with it.
When GPRS module is initialized, using ‘GPRS.begin()’, normal mode is selected by default. To start using GPRS module, it is
necessary to execute ‘GPRS.begin()’ first, and then ‘GPRS.setMode(GPRS_ON)’.
To change the operation mode, ‘GPRS.setMode’ should be used.
Example of use
{
GPRS.begin(); // opens UART1 and sets the proper value in the multiplexer
GPRS.setMode(GPRS_ON); // Set GPRS to continuous mode
GPRS.setMode(GPRS_HIBERNATE); // Set GPRS to the lowest consumption mode
GPRS.setMode(GPRS_SLEEP); // Set GPRS to sleep mode
}
-10-
v0.6
Extended Functions
5. Extended Functions
There are some functions defined in ‘Energy’ library to extend the functionality of Waspmote.
5.1. Set sensor board power
It sets ON or OFF the switches related to sensor board. As explained previously, Waspmote sensor boards have two switches to
manage 5V and 3,3V power.
This function returns nothing.
Example of use
{
PWR.setSensorPower(SENS_3V3,SENS_ON);// Switches on 3,3V switch
PWR.setSensorPower(SENS_5V,SENS_OFF);// Switches off 5V switch
}
5.2. Set Watchdog
It enables or disables Watchdog interruption.
‘mode’ --> if mode=WTD_ON, it enables Watchdog interruption. If mode=WTD_OFF, it disables Watchdog interruption.
‘timer’ --> it specifies the time before the Watchdog activates the interruption. Possible values are:
WTD_16MS
0
WTD_32MS
1
WTD_64MS
2
WTD_128MS
3
WTD_250MS
4
WTD_500MS
5
WTD_1S6
WTD_2S7
WTD_4S8
WTD_8S9
This function returns nothing.
Example of use
{
PWR.setWatchdog(WTD_ON,WTD_2S); // Enables Watchdog to generate interruption after 2 seconds
}
5.3. Clear Interruptions
It clears all captured interrupts to allow new interrupts on that modules.
Example of use
{
PWR.clearInts; // Clears interruptions on modules that have generated one
}
5.4. Get battery level
It gets the % of remaining battery.
-11-
v0.6
Extended Functions
It gives a value of 1024 for 3,3V. A resistor bridge is put to down max 4,2V battery level around 2,07V on 100% battery charge.
Minimum value for good battery is 3,3V, so with resistor bridge is set to 1,65V.
Values (in this case) are from 512 to 651.
Example of use
{
uint8_t battery_level=0;
battery_level =PWR.getBatteryLevel();// battery_level contains the % of remaining battery
}
5.5. Close I2C
It closes I2C, setting SDA and SCL to ‘0’.
This function returns nothing.
Example of use
{
PWR.closeI2C(); // closes I2C
}
5.6. Setting Low Battery Threshold
It initializes the low battery detector, setting the low battery threshold.
This function returns nothing.
This function must be used to get the highest energy saving.
Example of use
{
PWR.setLowBatteryThreshold(); // sets the low battery threshold
}
5.7. Checking if Hibernate
It sets ‘intFlag’ if Hibernate is reset is detected, and inits some pins to enable Hibernate mode.
When setting Hibernate mode, an EEPROM address is set to a special value to determine if reset has been generated by Hibernate
or normal reset.
This function must be used in ‘setup’ part of the main code to check each time ‘setup’ is executed if Hibernate mode has generated
the reset of Waspmote.
If this function is not used, Waspmote will not start when the Hibernate jumper is removed.
Example of use
{
PWR.ifHibernate();
// checks if reset has been generated by Hibernate mode and inits Hibernate
}
-12-
v0.6
Code examples and extended information
6. Code examples and extended information
For more information about the Waspmote hardware platform go to the Support section:
http://www.libelium.com/support/waspmote
Extended information about the API libraries and complete code examples can be found at:
http://www.libelium.com/development/waspmote
-13-
v0.6
Download