Hi all,
 
I'm trying to read the battery voltage to adjust my ADC scale on mica2 motes. I followed the instructions in User Manual to set the BAT_MON pin high. What I am not really sure is do I have to connect ADC7 pin to BAT_MON or this is somehow done internally?
 
Here is the example of my code that doesn't work (I tried to follow the examples already available). Can anyone point out what is wrong with it? I am using this file to read the pressure using TinyDB application.
 
I added the following to my sensorboard file:
 

#define MAKE_BAT_MONITOR_OUTPUT() sbi(DDRA, 5)

#define MAKE_BAT_ADC_INPUT() cbi(DDRF, 7)

#define SET_BAT_MONITOR() sbi(PORTA, 5)

#define CLEAR_BAT_MONITOR() cbi(PORTA, 5)

 

I wired this in my Pressure.nc file

  PressureM.BattControl -> Voltage; 
  PressureM.ADCBATT -> Voltage;

 

And my whole PressureM.nc file is:

 

includes sensorboard;
module PressureM {
  provides {
    interface StdControl;
    interface ADC;             

  }  


  uses {   
      
    interface Leds;
 
    // Battery   
    interface ADC as ADCBATT;
    interface StdControl as BattControl;
    

    //Pressure             
    interface ADC as Pressure; 
    interface ADCControl;                    
    interface Timer;   

 
  }
}
implementation
{
  float Vbatt;      
  float P;  
  uint16_t press;  

  
  command result_t StdControl.init() {
    call Leds.init();
    call BattControl.init();

    call ADCControl.bindPort(TOS_ADC_PRESSURE_PORT, TOSH_ACTUAL_PRESSURE_PORT);
    TOSH_MAKE_PRESSURE_CTL_OUTPUT();
    TOSH_CLR_PRESSURE_CTL_PIN();  //n-channel off --> p-channle off
//TOSH_SET_PRESSURE_CTL_PIN();      //n-channel on --> p-channle on
    dbg(DBG_BOOT, "PRESSURE initialized.\n");
    return call ADCControl.init();
  }
 
  command result_t StdControl.start() {
    call BattControl.start();

    TOSH_SET_PRESSURE_CTL_PIN();    //n-channel on --> p-channle on
//    TOSH_CLR_PRESSURE_CTL_PIN();      //n-channel off --> p-channle off
    return SUCCESS;
  }
 
  command result_t StdControl.stop() {
    TOSH_CLR_PRESSURE_CTL_PIN();    //n-channel off --> p-channle off
//    TOSH_SET_PRESSURE_CTL_PIN();      //n-channel on --> p-channle on
    return SUCCESS;
  }
 
  event result_t Timer.fired()
  {
    return SUCCESS;
  }

  async command result_t ADC.getData()
  {
    call StdControl.start();

//    SET_BAT_MONITOR();           //already done in VoltageM.nc 
    call ADCBATT.getData();           //get the battery voltage;
//    CLEAR_BAT_MONITOR();      //already done in VoltageM.nc 
    call BattControl.stop();

    call Timer.start(TIMER_ONE_SHOT, 12); //AP to extand PW duration from 8ms to 20ms
                                                                //20ms stabilisation
 
    return call Pressure.getData();
  }
  


  default async event result_t ADC.dataReady(uint16_t data)
  {
    return SUCCESS;
  }

  async command result_t ADC.getContinuousData()
  {
    return FAIL;
  }


  async event result_t ADCBATT.dataReady(uint16_t data) {
      Vbatt = 1.223*1024/data;
      return SUCCESS;
  }


 
   async event result_t Pressure.dataReady(uint16_t data){
    P = (float)(data)*Vbatt/1024.0;
    P = (P/Vbatt + 0.32667)/0.01067;     //kPa infineon
 //   P = (P/Vbatt + 0.095)/0.009;          //kPa motorola
    P = P*10;                                      //kPa to mbar
    press = (uint16_t)(P);
    signal ADC.dataReady(press);
    return SUCCESS;
  }
 
}

 

 

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

Reply via email to