Hi everybody,

I'm currently developing a driver for a solar radiation sensor (in 
particular, Davis 6450). The sensor is connected to a the micaZ by means 
of a MDA300, but I don't know exactly if it is the same as connecting 
directly to the mote itself. I would like to use single ended  analog 
channel 1 (A1 in MDA300 schematic). The voltage reference for the sensor 
I think is 2.5V.

As I haven't much experience on it, I started to connect a battery AA 
1.5 V to the A1 for positive pole and GND for negative pole so I could 
measure it, and also I could be sure that my software can measure 
properly from where I'm going to connect the sensor in MDA300, and be 
sure that my driver can measure the battery value by means of the ADC. 
Probably I haven't done properly yet, but my driver always get the same 
value, even when I disconnect the battery from the MDA300. So, I guess 
that probably I'm missing something in the code. I used as templeate the 
code from accelerometer in MTS300 platform.

Could you give some advice or hint?  Following I give you the code I used...

Thank you very much in advance,

Regards,

Javier.



SolarC Configuration
------------------------------

generic configuration SolarC(){
     provides interface Read<uint16_t>;
}
implementation{
     components new AdcReadClientC(), SolarDeviceP;

       Read = AdcReadClientC;
       AdcReadClientC.Atm128AdcConfig -> SolarDeviceP;
       AdcReadClientC.ResourceConfigure -> SolarDeviceP;
}

SolarDeviceP
-------------------

configuration SolarDeviceP {
   provides {
     interface ResourceConfigure;
     interface Atm128AdcConfig;
   }
}
implementation {
   components SolarP, MicaBusC;

   ResourceConfigure = SolarP;
   Atm128AdcConfig = SolarP;

   SolarP.SolarPin -> MicaBusC.PW1;
   SolarP.SolarAdc -> MicaBusC.Adc1;
}



SolarP
---------

module SolarP{
     provides {
         interface ResourceConfigure;
         interface Atm128AdcConfig;
     }
     uses {
         interface GeneralIO as SolarPin;
         interface MicaBusAdc as SolarAdc;
     }
}
implementation{

     async command uint8_t Atm128AdcConfig.getChannel() {
         return call SolarAdc.getChannel();
       }

       async command uint8_t Atm128AdcConfig.getRefVoltage() {
         return ATM128_ADC_VREF_OFF;
       }

       async command uint8_t Atm128AdcConfig.getPrescaler() {
            return ATM128_ADC_PRESCALE;
       }

       async command void ResourceConfigure.configure() {
         call SolarPin.makeOutput();
         call SolarPin.set();
       }

       async command void ResourceConfigure.unconfigure() {
         call SolarPin.clr();
       }

}

And my test application that uses this "driver" for reading values from ADC:

module SolarSendC{
   uses interface Read<uint16_t> as Read;
   uses interface ReadNow<uint16_t> as ReadNow;
   uses interface Resource as ReadNowResource;
   uses interface ReadStream<uint16_t> as ReadStream;
   uses interface AMSend as SenderAdcValue;
   uses interface SplitControl as RadioControl;
   uses interface Timer<TMilli> as TimerMeasure;
   uses interface Boot;
   uses interface Leds;
}
implementation{

     #define BUF_SIZE 100
   uint16_t buf[BUF_SIZE];
   bool streamSuccess;

   message_t bufferSend; //send buffer

   bool sendbusy=FALSE; //Flag to use the radio to send

   event void Boot.booted()
   {
     call RadioControl.start();
     streamSuccess = FALSE;
     call TimerMeasure.startPeriodic(1000);

   }

   event void TimerMeasure.fired(){
     call Read.read();
   }

   event void Read.readDone(error_t result, uint16_t data)
   {

     AdcReadingMsg* newMessage = (AdcReadingMsg*) (call 
SenderAdcValue.getPayload(&bufferSend, sizeof(AdcReadingMsg)));
     if (result == SUCCESS)
       call Leds.led0On();

     newMessage->source = TOS_NODE_ID;
     newMessage->value = data;
     call Leds.led2On();
     if (call SenderAdcValue.send(AM_BROADCAST_ADDR, &bufferSend, 
sizeof(AdcReadingMsg)) == SUCCESS) {
         sendbusy = TRUE;
         call Leds.led1Toggle();
     }
   }

   event void ReadNowResource.granted()
   {
     call ReadNow.read();
   }

   async event void ReadNow.readDone(error_t result, uint16_t data)
   {
     if (result == SUCCESS)
       call Leds.led1On();
     call ReadNowResource.release();
   }

   event void ReadStream.bufferDone( error_t result,
              uint16_t* buffer, uint16_t count )
   {
     streamSuccess = TRUE;
   }

   event void ReadStream.readDone(error_t result, uint32_t actualPeriod)
   {
     if (result == SUCCESS && streamSuccess)
       call Leds.led2On();
   }

   event void SenderAdcValue.sendDone(message_t* msg, error_t error) {
      //call Leds.led1Toggle();

      sendbusy = FALSE;

   }

   event void RadioControl.startDone(error_t error) {

   }

   event void RadioControl.stopDone(error_t error) {

   }

}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to