Back to Getting Started

Back to Examples

This example demonstrates setting up and making use of the Battery Board

This examples helps you in learning APIs and application firmware that can be used to:

  • To figure out the adc functionality and test and measure the battery voltage from the CR2540 on the battery board.

Fig. 1: TOP VIEW Fig. 2: BOTTOM VIEW

Before you proceed with this tutorial, you must have Koliada visual studio plugin and Koliada toolchain setup. For more information on the setup check out Koliada Getting started. This tutorial is currently based on the TI CC2541 which uses the 8051.

Before working on this example, make sure you have set the latest KoliadaESDK(TM). More information on setSDK setup and setting the path is shown here.

Note: After making sure the SDK path is set, you must know that the board config must be flashed only if you are using any I/O pins. In this particular example there are no I/O configurations for the adc or battery board, so you can directly flash the application firmware.

Select the SDK using the SDK Dropdown button at the top.

You can find the application firmware for Battery/adc test under KoliadaESDK(TM)→examples→TestBattery.

Now compile the project and hit download to target.

You should see the following output on your serial terminal

In this example we should be testing the operation of the battery board and the motion sensor.

As you can see from the above output image, the voltage value of the battery CR2450(if battery board switch is in ON position) or voltage value through USB board(if battery board switch placed in OFF position) will be continuously printed out every timer interval which is every second.

We can walkthrough TestBattery.c now.

Application Firmware (TestBattery)

The main.c calls TestBattery() function in TestBattery.c

void TestBattery()
	{
	printf(">>%s\n", __func__);
 
        objectCreate(BatteryTimer, kIntervalTimer, TICKS(1000));
	OnEvent(BatteryTimer, (HANDLER) BatteryTimerHandler);
 
	cmStartTimer(BatteryTimer);
 
	// wait for system events
	//printf("press button(s) ->\n");
	WaitEvent(0, 0);// never returns
	}
 
 

The objectCreate(BatteryTimer, kIntervalTimer, TICKS(1000)); creates a timer under the name BatteryTimer(which is supposed to happen when ever every second). On this timer event (OnEvent(BatteryTimer, (HANDLER) BatteryTimerHandler);) the BatteryTimerHandler will be called. Also once the timer event is defined and eventhandlers are set for Batterytimer we need to enable/start the timer using cmStartTimer(BatteryTimer).

Now since all the events are set the system goes to event listening mode. This is done by using WaitEvent(0, 0); .

DefineTimer(BatteryTimer);
void BatteryTimerHandler(TIMER t)
	{
    long a, vdd;
    word v;
   a = adc(0x00 | 0x30 | 0x0f) >> 3;;
   vdd = (((a * 1000)/4096 * 1150 * 3)+500)/1000;
   v = vdd/1000;
   printf("the voltage on the line is %d.%ld v\n", v, vdd-v *1000);
	}

We setup the adc line to measure the VDD output voltage through SPIP pins using adc(0x00 | 0x30 | 0x0f) » 3;;.

and we print the voltage on the input voltage line(which can be either from the battery or the USB). We have now accomplished setting up and accessing the batteryBoard. Now you can use the battery board for a different application and observe your results.

More Examples

More Boards

      Copyright © 2018-2019 Koliada, LLC
  • piep/examples/battery.txt
  • Last modified: 2019/04/16 01:14
  • by venkat