light.c

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 
00043 #include <io.h>
00044 
00045 #include "contiki.h"
00046 #include "dev/light.h"
00047 
00048 /*
00049  * Initialize periodic readings from the 2 photo diodes. The most
00050  * recent readings will be stored in ADC internal registers/memory.
00051  */
00052 void
00053 sensors_light_init(void)
00054 {
00055 }
00056 
00057 /* Photosynthetically Active Radiation. */
00058 unsigned
00059 sensors_light1(void)
00060 {
00061   return 0;
00062 }
00063 
00064 /* Total Solar Radiation. */
00065 unsigned
00066 sensors_light2(void)
00067 {
00068   return 0;
00069 }
00070 
00071 /*
00072  * Most of this information taken from
00073  * http://www.moteiv.com/community/Getting_Data_from_Tmote_Sky%27s_Sensors
00074  *
00075  * The Photosynthetically Active Radiation (PAR) sensor as well as the
00076  * Total Solar Radiation (TSR) sensor uses the 2.5V reference voltage
00077  * to produce the raw ADC value.
00078 
00079  * The voltage across each sensor is:
00080  *
00081  * VsensorPAR = ADCValuePAR/4096 * Vref       (1a)
00082  * VsensorTSR = ADCValueTSR/4096 * Vref       (1b)
00083  * where Vref = 2.5V
00084  *
00085  * This voltage creates a current through a resistor R=100KOhm and this
00086  * current has a linear relationship with the light intensity in Lux.
00087  * IPAR = VsensorPAR / 100,000             (2a) 
00088  * ITSR = VsensorTSR / 100,000             (2b) 
00089  *
00090  * S1087    (PAR) lx = 1e6 * IPAR * 1000   (3a)  
00091  * S1087-01 (TSR) lx = 1e5 * ITSR * 1000   (3b)
00092  *
00093  * lxPAR = 10e9 * ADCValuePAR *(1/4096)* Vref * 10e-5  or
00094  * lxPAR = 3125* ADCvaluePAR / 512  
00095  * and 
00096  * lxTSR = 10e8 * ADCValueTSR *(1/4096)* Vref * 10e-5  or
00097  * lxTSR = 625* ADCvalueTSR / 1024  
00098 */
00099 
00100 #if 0
00101 /* Photosynthetically Active Radiation in Lux units. */
00102 unsigned
00103 sensors_light1_lux(void)
00104 {
00105   unsigned temp;
00106   temp = (uint32_t)ADC12MEM0;
00107 
00108   temp = (temp*3125)>> 9; 
00109   return (uint16_t)(temp & 0xFFFF); 
00110 }
00111 
00112 /* Total Solar Radiation in Lux units. */
00113 unsigned
00114 sensors_light2_lux(void)
00115 {
00116   unsigned temp;
00117   temp = (uint32_t)ADC12MEM1;
00118 
00119   temp = (temp*625)>> 10; 
00120   return (uint16_t)(temp & 0xFFFF); 
00121 }
00122 #endif

Generated on Mon Apr 11 14:23:45 2011 for Contiki 2.5 by  doxygen 1.6.1