Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * This file is part of the Contiki operating system. 00030 * 00031 * 00032 * \file 00033 * Dummy light-sensor to allow as many programs for sky to compile for Z1 00034 * 00035 * \author 00036 * Enric M. Calvo <ecalvo@zolertia.com>, adapted from previous work 00037 * 00038 * @(#)$Id: light.c,v 1.0 2011/02/27 ecalvo $ 00039 */ 00040 00041 #include <stdlib.h> 00042 #include "contiki.h" 00043 #include "dev/light.h" 00044 00045 /* 00046 * Initialize periodic readings from the 2 photo diodes. The most 00047 * recent readings will be stored in ADC internal registers/memory. 00048 */ 00049 void 00050 sensors_light_init(void) 00051 { 00052 } 00053 00054 /* Photosynthetically Active Radiation. */ 00055 unsigned 00056 sensors_light1(void) 00057 { 00058 return 0; 00059 } 00060 00061 /* Total Solar Radiation. */ 00062 unsigned 00063 sensors_light2(void) 00064 { 00065 return 0; 00066 } 00067 00068 /* 00069 * Most of this information taken from 00070 * http://www.moteiv.com/community/Getting_Data_from_Tmote_Sky%27s_Sensors 00071 * 00072 * The Photosynthetically Active Radiation (PAR) sensor as well as the 00073 * Total Solar Radiation (TSR) sensor uses the 2.5V reference voltage 00074 * to produce the raw ADC value. 00075 00076 * The voltage across each sensor is: 00077 * 00078 * VsensorPAR = ADCValuePAR/4096 * Vref (1a) 00079 * VsensorTSR = ADCValueTSR/4096 * Vref (1b) 00080 * where Vref = 2.5V 00081 * 00082 * This voltage creates a current through a resistor R=100KOhm and this 00083 * current has a linear relationship with the light intensity in Lux. 00084 * IPAR = VsensorPAR / 100,000 (2a) 00085 * ITSR = VsensorTSR / 100,000 (2b) 00086 * 00087 * S1087 (PAR) lx = 1e6 * IPAR * 1000 (3a) 00088 * S1087-01 (TSR) lx = 1e5 * ITSR * 1000 (3b) 00089 * 00090 * lxPAR = 10e9 * ADCValuePAR *(1/4096)* Vref * 10e-5 or 00091 * lxPAR = 3125* ADCvaluePAR / 512 00092 * and 00093 * lxTSR = 10e8 * ADCValueTSR *(1/4096)* Vref * 10e-5 or 00094 * lxTSR = 625* ADCvalueTSR / 1024 00095 */ 00096 00097 #if 0 00098 /* Photosynthetically Active Radiation in Lux units. */ 00099 unsigned 00100 sensors_light1_lux(void) 00101 { 00102 unsigned temp; 00103 temp = (uint32_t)ADC12MEM0; 00104 00105 temp = (temp*3125)>> 9; 00106 return (uint16_t)(temp & 0xFFFF); 00107 } 00108 00109 /* Total Solar Radiation in Lux units. */ 00110 unsigned 00111 sensors_light2_lux(void) 00112 { 00113 unsigned temp; 00114 temp = (uint32_t)ADC12MEM1; 00115 00116 temp = (temp*625)>> 10; 00117 return (uint16_t)(temp & 0xFFFF); 00118 } 00119 #endif