[Tinyos-help] how to get 3 ADC Port value from Tmote sky‏

Chen Bleed bleed1979 at hotmail.com
Thu Sep 13 06:25:27 PDT 2007


I want to get three value from tmote sky.I use 3-axis accelerator sensor, and I need the X, Y, Z Output.I'm unable to  get three values at one time, so i try to get one value at one time, then get  three times to be a cycle.(If anyone get some solutione like get three values at one time, please tell my how to do.)This program seems to get only one value.Please help me to solve this problem. ***************** IntMsg.h *****************typedef struct IntMsg {  uint16_t val;  //uint16_t src;  uint16_t testval;  //uint16_t testval2;  //uint16_t testval3;} IntMsg; enum {  AM_INTMSG = 153};  ***************** SensorX.h *****************enum{  TOS_ADC_SENSORX_PORT = unique("ADCPort"),   TOSH_ACTUAL_ADC_SENSORX_PORT = ASSOCIATE_ADC_CHANNEL(/*    INPUT_CHANNEL_A3,*/    INPUT_CHANNEL_A2,    REFERENCE_VREFplus_AVss,    REFVOLT_LEVEL_1_5  ),};  ***************** SensorY.h *****************enum{  TOS_ADC_SENSORY_PORT = unique("ADCPort"),   TOSH_ACTUAL_ADC_SENSORY_PORT = ASSOCIATE_ADC_CHANNEL(/*    INPUT_CHANNEL_A1, */	    INPUT_CHANNEL_A0,    REFERENCE_VREFplus_AVss,    REFVOLT_LEVEL_1_5  ),};  ***************** SensorZ.h *****************enum{  TOS_ADC_SENSORZ_PORT = unique("ADCPort"),   TOSH_ACTUAL_ADC_SENSORZ_PORT = ASSOCIATE_ADC_CHANNEL(/*    INPUT_CHANNEL_A2,*/    INPUT_CHANNEL_A1,    REFERENCE_VREFplus_AVss,    REFVOLT_LEVEL_1_5  ),}; ***************** ProjectOther.nc *****************includes IntMsg;includes SensorX;includes SensorY;includes SensorZ; configuration ProjectOther {	} implementation{  components Main, ProjectOtherM, TimerC, LedsC, ADCC, GenericComm as Comm;    Main.StdControl -> ProjectOtherM.StdControl;  ProjectOtherM.Timer -> TimerC.Timer[unique("Timer")];  Main.StdControl -> TimerC.StdControl;  ProjectOtherM.Leds -> LedsC.Leds;  ProjectOtherM.SendMsg -> Comm.SendMsg[AM_INTMSG];  ProjectOtherM.SubControl -> Comm.Control;  ProjectOtherM.ADC -> ADCC.ADC[TOS_ADC_SENSORX_PORT];  ProjectOtherM.ADC -> ADCC.ADC[TOS_ADC_SENSORY_PORT];  ProjectOtherM.ADC -> ADCC.ADC[TOS_ADC_SENSORZ_PORT];  ProjectOtherM.ADCControl -> ADCC;  } ***************** ProjectOtherM.nc *****************includes IntMsg;includes SensorX;includes SensorY;includes SensorZ; module ProjectOtherM {	provides {		interface StdControl;		interface IntOutput;	}	uses {	  interface StdControl as SubControl;	  interface SendMsg;	  interface Timer;	  interface Leds;	  interface ADC;	  interface ADCControl;	}} implementation {	int state;	bool pending, flag_y, flag_g, flag_r;	TOS_Msg msg_data;	uint16_t ADCval;		void readIRSensor();	task void chooseADCChannel();		/* interface StdControl */	command result_t StdControl.init() {		atomic ADCval = 0;		atomic state = 1;		pending = FALSE;		call Leds.init();        call Leds.redOff();        call Leds.yellowOff();        call Leds.greenOff();        call ADCControl.init(); 		return call SubControl.init();	}		command result_t StdControl.start() {		call Timer.start(TIMER_REPEAT, 1000);		return call SubControl.start();	}		command result_t StdControl.stop() {		return call SubControl.stop();	}		/* interface IntOutput */	command result_t IntOutput.output(uint16_t value) {		IntMsg *message = (IntMsg *)msg_data.data;				if(!pending)		{		  pending = TRUE;	  		  readIRSensor();	  		  atomic {		  	message->val = ADCval;	        /*message->src = TOS_LOCAL_ADDRESS;*/	         if(!(state%3)) message->testval = 0x0099;	         else if((state%3)==1) message->testval = 0x0088;	         else message->testval = 0x0077;	      }	      	      if (call SendMsg.send(0x0111, sizeof(IntMsg), &msg_data))	        return SUCCESS;	      	      pending = FALSE;		}		return FAIL;	}	/* interface ADC */	void readIRSensor(){		call Leds.greenToggle();        call ADC.getData();	}    async event result_t ADC.dataReady( uint16_t data ) {      ADCval = data;      post chooseADCChannel();      return SUCCESS;    }		task void chooseADCChannel()	{ 	  if(!(state%3)) call ADCControl.bindPort( TOS_ADC_SENSORX_PORT, TOSH_ACTUAL_ADC_SENSORX_PORT );      else if((state%3)==1)call ADCControl.bindPort( TOS_ADC_SENSORY_PORT, TOSH_ACTUAL_ADC_SENSORY_PORT );      else call ADCControl.bindPort( TOS_ADC_SENSORZ_PORT, TOSH_ACTUAL_ADC_SENSORZ_PORT );      	}		/* interface SendMsg */	event result_t SendMsg.sendDone(TOS_MsgPtr msg, result_t success) {	  if (pending && msg == &msg_data)      {	    pending = FALSE;	    if(success == 0) atomic state--;      }      return SUCCESS;	}		/* interface Timer */	event result_t Timer.fired() {	  if (call IntOutput.output(state))        atomic state++;       dbg(DBG_USR1,"state=%i\n",state);       dbg(DBG_USR1,"ADCval=%i\n",ADCval);      return SUCCESS;	}}
_________________________________________________________________
2 GB 超大容量 、創新便捷、安全防護垃圾郵件和病毒 — 立即升級 Windows Live Hotmail
http://mail.live.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.millennium.berkeley.edu/pipermail/tinyos-help/attachments/20070913/c8a7de50/attachment-0001.html


More information about the Tinyos-help mailing list