Modified ADC measurement of PM10 driver to include adc-zoul direct access

This commit is contained in:
Toni Lozano 2016-01-26 14:08:17 +01:00
parent 8337843d69
commit 1f6dafecb0
5 changed files with 32 additions and 17 deletions

View file

@ -1,12 +1,11 @@
DEFINES+=PROJECT_CONF_H=\"project-conf.h\" DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
CONTIKI_PROJECT = zoul-demo test-tsl2563 test-sht25 test-pwm test-power-mgmt CONTIKI_PROJECT = zoul-demo test-tsl2563 test-sht25 test-pwm test-power-mgmt
ONTIKI_PROJECT += test-bmp085-bmp180 test-motion test-rotation-sensor CONTIKI_PROJECT += test-bmp085-bmp180 test-motion test-rotation-sensor
CONTIKI_PROJECT += test-grove-light-sensor test-grove-loudness-sensor CONTIKI_PROJECT += test-grove-light-sensor test-grove-loudness-sensor
CONTIKI_PROJECT += test-weather-meter test-grove-gyro test-lcd CONTIKI_PROJECT += test-weather-meter test-grove-gyro test-lcd
CONTIKI_PROJECT += test-pm10-sensor test-vac-sensor test-aac-sensor CONTIKI_PROJECT += test-pm10-sensor test-vac-sensor test-aac-sensor
CONTIKI_TARGET_SOURCEFILES += tsl2563.c sht25.c bmpx8x.c motion-sensor.c CONTIKI_TARGET_SOURCEFILES += tsl2563.c sht25.c bmpx8x.c motion-sensor.c
CONTIKI_TARGET_SOURCEFILES += adc-sensors.c weather-meter.c grove-gyro.c CONTIKI_TARGET_SOURCEFILES += adc-sensors.c weather-meter.c grove-gyro.c
CONTIKI_TARGET_SOURCEFILES += rgb-bl-lcd.c pm10-sensor.c CONTIKI_TARGET_SOURCEFILES += rgb-bl-lcd.c pm10-sensor.c

View file

@ -54,7 +54,6 @@
#define LOOP_PERIOD 2 #define LOOP_PERIOD 2
#define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD) #define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD)
#define LEDS_PERIODIC LEDS_GREEN #define LEDS_PERIODIC LEDS_GREEN
#define BUTTON_PRESS_EVENT_INTERVAL (CLOCK_SECOND)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static struct etimer et; static struct etimer et;
@ -72,7 +71,7 @@ PROCESS_THREAD(test_aac_sensor_process, ev, data)
/* Configure the ADC ports */ /* Configure the ADC ports */
/* Use pin number not mask, for example if using the PA5 pin then use 5 */ /* Use pin number not mask, for example if using the PA5 pin then use 5 */
printf("return configure, %d \n", adc_sensors.configure(ANALOG_AAC_SENSOR, ADC_PIN)); adc_sensors.configure(ANALOG_AAC_SENSOR, ADC_PIN);
printf("AAC test application\n"); printf("AAC test application\n");
leds_on(LEDS_PERIODIC); leds_on(LEDS_PERIODIC);

View file

@ -72,7 +72,7 @@ PROCESS_THREAD(test_vac_sensor_process, ev, data)
/* Configure the ADC ports */ /* Configure the ADC ports */
/* Use pin number not mask, for example if using the PA5 pin then use 5 */ /* Use pin number not mask, for example if using the PA5 pin then use 5 */
printf("return configure, %d \n", adc_sensors.configure(ANALOG_VAC_SENSOR, ADC_PIN)); adc_sensors.configure(ANALOG_VAC_SENSOR, ADC_PIN);
printf("VAC test application\n"); printf("VAC test application\n");
leds_on(LEDS_PERIODIC); leds_on(LEDS_PERIODIC);

View file

@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2016, Zolertia <http://www.zolertia.com> * Copyright (c) 2016, Zolertia <http://www.zolertia.com>
* All rights reserved. * All rights reserved.
* *
@ -43,6 +43,8 @@
#include <stdio.h> #include <stdio.h>
#include "contiki.h" #include "contiki.h"
#include "adc-sensors.h" #include "adc-sensors.h"
#include "adc-zoul.h"
#include "zoul-sensors.h"
#include "dev/pm10-sensor.h" #include "dev/pm10-sensor.h"
#include "dev/sys-ctrl.h" #include "dev/sys-ctrl.h"
#include "lib/sensors.h" #include "lib/sensors.h"
@ -52,7 +54,7 @@
#define PM10_SENSOR_PORT_BASE GPIO_PORT_TO_BASE(PM10_SENSOR_CTRL_PORT) #define PM10_SENSOR_PORT_BASE GPIO_PORT_TO_BASE(PM10_SENSOR_CTRL_PORT)
#define PM10_SENSOR_PIN_MASK GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN) #define PM10_SENSOR_PIN_MASK GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static uint8_t enabled; static int pm10_channel;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
configure(int type, int value) configure(int type, int value)
@ -68,20 +70,20 @@ configure(int type, int value)
GPIO_SET_OUTPUT(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); GPIO_SET_OUTPUT(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK);
GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK);
enabled = 1; pm10_channel = (1 << value);
return adc_sensors.configure(ANALOG_PM10_SENSOR, value); return adc_zoul.configure(SENSORS_HW_INIT, pm10_channel);
} }
enabled = 0; pm10_channel = 0;
return PM10_SUCCESS; return PM10_SUCCESS;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
value(int type) value(int type)
{ {
uint16_t val; uint32_t val;
if(!enabled) { if(!pm10_channel) {
return PM10_ERROR; return PM10_ERROR;
} }
@ -90,17 +92,30 @@ value(int type)
/* Pulse wave delay */ /* Pulse wave delay */
clock_delay_usec(PM10_SENSOR_PULSE_DELAY); clock_delay_usec(PM10_SENSOR_PULSE_DELAY);
/* Data acquisition */ /* Data acquisition */
val = adc_sensors.value(ANALOG_PM10_SENSOR); val = (uint32_t)adc_zoul.value(pm10_channel);
/* Clear pulse wave pin */
GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); if(val == ZOUL_SENSORS_ERROR) {
printf("PM10 sensor: failed retrieving data\n");
return PM10_ERROR;
}
/* Default voltage divisor relation is 5/3 aprox, change at adc_wrapper.h,
* calculations below assume a decimation rate of 512 (12 bits ENOB) and
* AVVD5 voltage reference of 3.3V
*/
val *= PM10_EXTERNAL_VREF;
val /= PM10_EXTERNAL_VREF_CROSSVAL;
/* Applied constant conversion from UAir project /* Applied constant conversion from UAir project
* to obtain value in ppm (value in mV * 0.28) * to obtain value in ppm (value in mV * 0.28)
*/ */
val *= 28; val *= 28;
val /= 1000; val /= 1000;
return val; /* Clear pulse wave pin */
GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK);
return (uint16_t)val;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
SENSORS_SENSOR(pm10, PM10_SENSOR, value, configure, NULL); SENSORS_SENSOR(pm10, PM10_SENSOR, value, configure, NULL);

View file

@ -51,6 +51,8 @@
#define PM10_SUCCESS 0 #define PM10_SUCCESS 0
#define PM10_SENSOR "PM10 Sensor" #define PM10_SENSOR "PM10 Sensor"
#define PM10_SENSOR_PULSE_DELAY 280 #define PM10_SENSOR_PULSE_DELAY 280
#define PM10_EXTERNAL_VREF 5000
#define PM10_EXTERNAL_VREF_CROSSVAL 3300
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
#ifdef PM10_SENSOR_CONF_CTRL_PIN #ifdef PM10_SENSOR_CONF_CTRL_PIN
#define PM10_SENSOR_CTRL_PIN PM10_SENSOR_CONF_CTRL_PIN #define PM10_SENSOR_CTRL_PIN PM10_SENSOR_CONF_CTRL_PIN