Unverified Commit a0e88b3e authored by George Oikonomou's avatar George Oikonomou Committed by GitHub
Browse files

Merge pull request #902 from g-oikonomou/bugfix/zoul-pm

Fix zoul battery voltage conversion and add example
parents ff709d29 5c9785a7
......@@ -62,7 +62,7 @@
#define PM_ENABLE_AS_OUTPUT GPIO_SET_OUTPUT(PM_ENABLE_PORT_BASE, \
PM_ENABLE_PIN_MASK)
#define PM_ENABLE_LINE_CMD PM_ENABLE_LINE_SET; \
clock_delay_usec(100);
clock_delay_usec(100);
/* -------------------------------------------------------------------------- */
#define PM_NUMBITS(X) (1 << ((X)-1))
......@@ -215,7 +215,7 @@ pm_get_num_cycles(void)
}
PM_ENABLE_LINE_CLR;
PRINTF("PM: Sleep cycles: 0x%02x%02x%02x%02x\n", lbuf[0], lbuf[1], lbuf[2],
lbuf[3]);
lbuf[3]);
return retval;
}
/* -------------------------------------------------------------------------- */
......@@ -249,6 +249,8 @@ pm_shutdown_now(uint8_t type)
int8_t
pm_get_voltage(uint16_t *state)
{
float result = 0x00;
if(!initialized) {
return PM_ERROR;
}
......@@ -260,10 +262,12 @@ pm_get_voltage(uint16_t *state)
*state = (uint16_t)lbuf[0] << 8;
*state += lbuf[1];
/* Delay required for the command to finish */
clock_delay_usec(3000);
/* Compensation */
result = *state - PM_VBAT_OFF;
result /= PM_VBAT_MULT;
*state = (uint16_t)(result * 100);
PRINTF("PM: Voltage %u [%u][%u]\n", *state, lbuf[0], lbuf[1]);
PM_ENABLE_LINE_CLR;
return PM_SUCCESS;
}
......
......@@ -132,6 +132,12 @@ typedef enum {
PM_USBSUSPEND /* USB in suspend mode */
} pm_charge_current_states;
/*
* VBAT Curve compensation
*/
#define PM_VBAT_MULT (float)-181.9
#define PM_VBAT_OFF (float)1294.72
/** @} */
/* -------------------------------------------------------------------------- */
/** \name Power Management functions
......
......@@ -4,7 +4,7 @@ CONTIKI_PROJECT += test-grove-light-sensor test-grove-loudness-sensor
CONTIKI_PROJECT += test-weather-meter test-grove-gyro test-lcd test-iaq
CONTIKI_PROJECT += test-pm10-sensor test-vac-sensor test-aac-sensor
CONTIKI_PROJECT += test-zonik test-dht22 test-ac-dimmer
CONTIKI_PROJECT += test-bme280
CONTIKI_PROJECT += test-bme280 test-vbat
CONTIKI_TARGET_SOURCEFILES += tsl256x.c sht25.c bmpx8x.c motion-sensor.c
CONTIKI_TARGET_SOURCEFILES += adc-sensors.c weather-meter.c grove-gyro.c
......
/*
* Copyright (c) 2016, Zolertia - http://www.zolertia.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* An example showing how to get VBAT Voltage functionality on
* RE-Mote Platform
* \author
* Erik Bellido <ebellido@zolertia.com>
* Aitor Mejias <amejias@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
/* This is the main contiki header, it should be included always */
#include "contiki.h"
#include "power-mgmt.h"
#include "dev/i2c.h"
#include "sys/etimer.h"
/*---------------------------------------------------------------------------*/
/*#define freq I2C_SCL_NORMAL_BUS_SPEED */
static struct etimer et;
/* RE-Mote revision B, low-power PIC version */
#define PM_EXPECTED_VERSION 0x20
/*---------------------------------------------------------------------------*/
/* We are going to create three different processes, with its own printable
* name. Processes are a great way to run different applications and features
* in parallel
*/
PROCESS(test_VBAT_process, "Test VBAT process");
/* But we are only going to automatically start the first two */
AUTOSTART_PROCESSES(&test_VBAT_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_VBAT_process, ev, data)
{
static uint8_t aux = 0x00;
static uint16_t voltage = 0x00;
PROCESS_BEGIN();
if(pm_enable() != PM_SUCCESS) {
printf("PM Failed \n");
} else if(pm_enable() == PM_SUCCESS) {
printf("Process PM started\n");
}
if((pm_get_fw_ver(&aux) == PM_ERROR) || (aux != PM_EXPECTED_VERSION)) {
printf("PM: unexpected version 0x%02X\n", aux);
}
printf("PM: firmware version 0x%02X OK\n", aux);
while(1) {
etimer_set(&et, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
/*-------------------voltage VBAT --------------*/
if(pm_get_voltage(&voltage) != PM_SUCCESS) {
printf("PM: error retrieving voltage\n");
} else {
printf("%u.%u V\n", voltage / 100, voltage % 100);
}
}
PROCESS_END();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment