From 42e1beb93167e7aa67777e7454f844f3bb03672f Mon Sep 17 00:00:00 2001 From: Toni Lozano Date: Fri, 22 Jan 2016 12:15:33 +0100 Subject: [PATCH] Added PM10 GP2Y1010AU0F sensor driver and demo test --- examples/zolertia/zoul/test-aac-sensor.c | 33 ++----------- .../zoul/{test-pm10.c => test-pm10-sensor.c} | 23 ++++++---- examples/zolertia/zoul/test-vac-sensor.c | 36 +++------------ platform/zoul/dev/adc-sensors.c | 8 ++-- platform/zoul/dev/pm10-sensor.c | 46 ++++++++++++++++--- platform/zoul/dev/pm10-sensor.h | 11 ++--- 6 files changed, 71 insertions(+), 86 deletions(-) rename examples/zolertia/zoul/{test-pm10.c => test-pm10-sensor.c} (82%) diff --git a/examples/zolertia/zoul/test-aac-sensor.c b/examples/zolertia/zoul/test-aac-sensor.c index 243a835f8..661eadf69 100644 --- a/examples/zolertia/zoul/test-aac-sensor.c +++ b/examples/zolertia/zoul/test-aac-sensor.c @@ -1,6 +1,5 @@ /* - * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ - * Copyright (c) 2015, Zolertia - http://www.zolertia.com + * Copyright (c) 2016, Zolertia - http://www.zolertia.com * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,28 +29,17 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* - * - * + * \addtogroup zoul-examples * @{ * * \file * Example demonstrating the Zoul module on the RE-Mote & AAC sensor 0-5V 50Amps AC */ #include "contiki.h" -#include "cpu.h" #include "sys/etimer.h" #include "sys/rtimer.h" #include "dev/leds.h" -#include "dev/uart.h" -#include "dev/button-sensor.h" -#include "dev/zoul-sensors.h" -#include "dev/watchdog.h" -#include "dev/serial-line.h" -#include "dev/sys-ctrl.h" -#include "net/rime/broadcast.h" #include "dev/adc-sensors.h" - - #include #include /*---------------------------------------------------------------------------*/ @@ -65,24 +53,16 @@ static struct etimer et; static uint16_t counter; /*---------------------------------------------------------------------------*/ -PROCESS(zoul_demo_process, "Zoul demo process"); -AUTOSTART_PROCESSES(&zoul_demo_process); +PROCESS(test_aac_sensor_process, "Test AAC sensor process"); +AUTOSTART_PROCESSES(&test_aac_sensor_process); /*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(zoul_demo_process, ev, data) +PROCESS_THREAD(test_aac_sensor_process, ev, data) { PROCESS_BEGIN(); counter = 0; - /* Configure the user button */ - button_sensor.configure(BUTTON_SENSOR_CONFIG_TYPE_INTERVAL, - BUTTON_PRESS_EVENT_INTERVAL); - /* Configure the ADC ports */ /* 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)); @@ -100,8 +80,6 @@ PROCESS_THREAD(zoul_demo_process, ev, data) printf("-----------------------------------------\n" "Counter = 0x%08x\n", counter); - - //printf("ADC3 = %d raw\n", (adc_sensors.value(ANALOG_AAC_SENSOR)/1.76)); printf("AC Amps = %d mA\n", adc_sensors.value(ANALOG_AAC_SENSOR)); @@ -114,7 +92,6 @@ PROCESS_THREAD(zoul_demo_process, ev, data) } /*---------------------------------------------------------------------------*/ /** - * @} * @} * @} */ diff --git a/examples/zolertia/zoul/test-pm10.c b/examples/zolertia/zoul/test-pm10-sensor.c similarity index 82% rename from examples/zolertia/zoul/test-pm10.c rename to examples/zolertia/zoul/test-pm10-sensor.c index d8e64067a..d72ae51b4 100644 --- a/examples/zolertia/zoul/test-pm10.c +++ b/examples/zolertia/zoul/test-pm10-sensor.c @@ -36,7 +36,7 @@ * @{ * * \file - * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper + * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper * * \author * Toni Lozano @@ -46,23 +46,28 @@ #include "contiki.h" #include "dev/leds.h" #include "dev/adc-sensors.h" +#include "dev/zoul-sensors.h" +#include "lib/sensors.h" +#include "dev/pm10-sensor.h" /*---------------------------------------------------------------------------*/ #define ADC_PIN 2 -#define SENSOR_READ_INTERVAL (CLOCK_SECOND / 8) +#define SENSOR_READ_INTERVAL (CLOCK_SECOND) /*---------------------------------------------------------------------------*/ -PROCESS(remote_pm10_sensor_process, "PM10 sensor test process"); -AUTOSTART_PROCESSES(&remote_grove_loudness_process); +PROCESS(test_pm10_sensor_process, "Test PM10 sensor process"); +AUTOSTART_PROCESSES(&test_pm10_sensor_process); /*---------------------------------------------------------------------------*/ static struct etimer et; /*---------------------------------------------------------------------------*/ -PROCESS_THREAD(remote_pm10_sensor_process, ev, data) +PROCESS_THREAD(test_pm10_sensor_process, ev, data) { PROCESS_BEGIN(); + SENSORS_ACTIVATE(pm10); - uint16_t pm10_value; + static uint16_t pm10_value; + /* Configure the ADC ports */ /* Use pin number not mask, for example if using the PA5 pin then use 2 */ - adc_sensors.configure(ANALOG_PM10_SENSOR, ADC_PIN); + printf("return configure, %d \n", pm10.configure(SENSORS_ACTIVE, ADC_PIN)); /* And periodically poll the sensor */ @@ -72,10 +77,10 @@ PROCESS_THREAD(remote_pm10_sensor_process, ev, data) leds_toggle(LEDS_GREEN); - pm10_value = adc_sensors.value(ANALOG_PM10_SENSOR); + pm10_value = pm10.value(NULL); if(pm10_value != ADC_WRAPPER_ERROR) { - printf("%u\n", pm10_value); + printf("PM10 value = %u ppm\n", pm10_value); } else { printf("Error, enable the DEBUG flag in adc-wrapper.c for info\n"); PROCESS_EXIT(); diff --git a/examples/zolertia/zoul/test-vac-sensor.c b/examples/zolertia/zoul/test-vac-sensor.c index aa02fd83a..0f1f9a4eb 100644 --- a/examples/zolertia/zoul/test-vac-sensor.c +++ b/examples/zolertia/zoul/test-vac-sensor.c @@ -1,6 +1,5 @@ /* - * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ - * Copyright (c) 2015, Zolertia - http://www.zolertia.com + * Copyright (c) 2016, Zolertia - http://www.zolertia.com * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,27 +29,17 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* - * - * + * \addtogroup zoul-examples * @{ * * \file * Example demonstrating the Zoul module on the RE-Mote & VAC sensor */ #include "contiki.h" -#include "cpu.h" #include "sys/etimer.h" #include "sys/rtimer.h" #include "dev/leds.h" -#include "dev/uart.h" -#include "dev/button-sensor.h" -#include "dev/zoul-sensors.h" -#include "dev/watchdog.h" -#include "dev/serial-line.h" -#include "dev/sys-ctrl.h" -#include "net/rime/broadcast.h" #include "dev/adc-sensors.h" - #include #include /*---------------------------------------------------------------------------*/ @@ -64,24 +53,16 @@ static struct etimer et; static uint16_t counter; /*---------------------------------------------------------------------------*/ -PROCESS(zoul_demo_process, "Zoul demo process"); -AUTOSTART_PROCESSES(&zoul_demo_process); +PROCESS(test_vac_sensor_process, "test VAC sensor process"); +AUTOSTART_PROCESSES(&test_vac_sensor_process); /*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(zoul_demo_process, ev, data) +PROCESS_THREAD(test_vac_sensor_process, ev, data) { PROCESS_BEGIN(); counter = 0; - /* Configure the user button */ - button_sensor.configure(BUTTON_SENSOR_CONFIG_TYPE_INTERVAL, - BUTTON_PRESS_EVENT_INTERVAL); - /* Configure the ADC ports */ /* 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)); @@ -100,10 +81,8 @@ PROCESS_THREAD(zoul_demo_process, ev, data) printf("-----------------------------------------\n" "Counter = 0x%08x\n", counter); - //Value in raw after voltage divisor - printf("ADC3 = %d V\n", (adc_sensors.value(ANALOG_VAC_SENSOR)/0.0088)); - //AC voltage value, with applied corresponding sensor algorithm - printf("AC voltage = %d V\n", adc_sensors.value(VAC_VAL)); + /*AC voltage value, with applied corresponding sensor algorithm*/ + printf("AC voltage = %d V\n", adc_sensors.value(ANALOG_VAC_SENSOR)); etimer_set(&et, LOOP_INTERVAL); counter++; @@ -114,7 +93,6 @@ PROCESS_THREAD(zoul_demo_process, ev, data) } /*---------------------------------------------------------------------------*/ /** - * @} * @} * @} */ diff --git a/platform/zoul/dev/adc-sensors.c b/platform/zoul/dev/adc-sensors.c index ecefbcff5..220a8dc88 100644 --- a/platform/zoul/dev/adc-sensors.c +++ b/platform/zoul/dev/adc-sensors.c @@ -45,7 +45,6 @@ #include "adc-sensors.h" #include "adc-zoul.h" #include "zoul-sensors.h" - #include #include /*---------------------------------------------------------------------------*/ @@ -108,6 +107,7 @@ convert_to_value(uint8_t index) value /= 100000; return (uint16_t)value; + /* VDD+5 sensors */ case ANALOG_VAC_SENSOR: /* Linear sensor from 0 to 5 V; 0.0088 resolution*/ value *= 88; @@ -116,13 +116,10 @@ convert_to_value(uint8_t index) case ANALOG_AAC_SENSOR: /* Linear sensor from 0 to 5 V;*/ - value *= 1.2; return (uint16_t)value; case ANALOG_PM10_SENSOR: - /* PM10 sensor from 0 to 5 V; 0.0088 resolution*/ - value *= 88; - value /= 10000; + /* PM10 sensor from 0 to 3.9 V;*/ return (uint16_t)value; default: @@ -205,6 +202,7 @@ configure(int type, int value) sensors.sensor[sensors.sensors_num].vdd3 = 1; break; + /*V+5 sensors*/ case ANALOG_VAC_SENSOR: case ANALOG_AAC_SENSOR: case ANALOG_PM10_SENSOR: diff --git a/platform/zoul/dev/pm10-sensor.c b/platform/zoul/dev/pm10-sensor.c index 6c3d2c994..aa8704c50 100644 --- a/platform/zoul/dev/pm10-sensor.c +++ b/platform/zoul/dev/pm10-sensor.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Zolertia + * Copyright (c) 2016, Zolertia * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,11 +31,11 @@ */ /*---------------------------------------------------------------------------*/ /** - * + * \addtogroup zoul-pm10-sensor * @{ * * \file - * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper + * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper * \author * Toni Lozano */ @@ -44,26 +44,58 @@ #include "contiki.h" #include "adc-sensors.h" #include "dev/pm10-sensor.h" +#include "dev/sys-ctrl.h" #include "lib/sensors.h" +#include "dev/gpio.h" +#include "dev/ioc.h" /*---------------------------------------------------------------------------*/ static uint8_t enabled; /*---------------------------------------------------------------------------*/ +#ifdef PM10_SENSOR_CONF_CTRL_PIN +#define PM10_SENSOR_CTRL_PIN PM10_SENSOR_CONF_CTRL_PIN +#else +#define PM10_SENSOR_CTRL_PIN 0x07 +#endif + +#define PM10_SENSOR_PORT GPIO_A_BASE + static int -configure(int value) +configure(int type, int value) { int error; + if(type != SENSORS_ACTIVE) { + return PM10_ERROR; + } + /*Set PA7 as output, used as pulse-driven wave*/ + ioc_set_over(PM10_SENSOR_PORT, PM10_SENSOR_CTRL_PIN, IOC_OVERRIDE_DIS); + GPIO_SOFTWARE_CONTROL(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN)); + GPIO_SET_OUTPUT(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN)); + + GPIO_CLR_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN)); + /* Use pin number not mask, for example if using the PA5 pin then use 5 */ - error = adc_sensors.configure(ANALOG_PM10_SENSORS, value); + error = adc_sensors.configure(ANALOG_PM10_SENSOR, value); return error; } /*---------------------------------------------------------------------------*/ static int -value(void) +value(int type) { uint16_t val; - //TODO: Add here GPIO pulses before measuring + /*Set Pulse Wave pin before measure*/ + GPIO_SET_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN)); + /*Pulse wave delay*/ + clock_delay_usec(280); + /*Data acquisition*/ val = adc_sensors.value(ANALOG_PM10_SENSOR); + /*Clear pulse wave pin*/ + GPIO_CLR_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN)); + + /*Applied constant conversion from UAir project*/ + /*to obtain value in ppm (value in mV * 0.28)*/ + val *= 28; + val /= 1000; return val; } diff --git a/platform/zoul/dev/pm10-sensor.h b/platform/zoul/dev/pm10-sensor.h index 22a89856a..c411428b5 100644 --- a/platform/zoul/dev/pm10-sensor.h +++ b/platform/zoul/dev/pm10-sensor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Zolertia + * Copyright (c) 2016, Zolertia * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,11 +31,8 @@ */ /*---------------------------------------------------------------------------*/ /** - * - * - * * \file - * GP2Y1010AU0F PM-10 sensor driver + * GP2Y1010AU0F PM10 sensor driver * \author * Toni Lozano */ @@ -47,11 +44,9 @@ /* -------------------------------------------------------------------------- */ #define PM10_ERROR -1 -#define PM10_PORT ZOUL_SENSORS_ADC3 -#define PM10_VAL 0x00 #define PM10_SENSOR "PM10 Sensor" /* -------------------------------------------------------------------------- */ -extern const struct sensors_sensor vac; +extern const struct sensors_sensor pm10; /* -------------------------------------------------------------------------- */ #endif /* ifndef VAC_SENSOR_H_ */ /**