please send questions to the help list in order to keep a record of my mistakes...
Your code is pretty good, but you are sending the previous conversion value at the beginning of the next cycle in the Timer.fired(), so at least the first send() is garbage. I would make a task to do the calculation, format, and send and post it from the dataReady() As far as data and types, as I said I would avoid floating point if possible. Either just send the raw ADC data or use fixed point arithmetic. Depending on the platform you are using, the value is 10 or 12 bits and fits nicely in a short int. What you are getting now is probably the integer value of the first two bytes of a four byte float. Would have to look at the IEEE f.p. specs to see what that means. Also some Voltage components attempt to do the calculation for you and I think all of them turn the sensor on and off as you do with your macros. Look at the actual code, if you can find it, to see... If you use the underlying ADC directly you need to do the on/off switching yourself. MS Debasmit Banerjee wrote: > Hi Mr.Schippling, > > Thanks a lot for your reply! I also wanted to know whether the data in the > VBatt can be stored in an uint? And also, is my code correct in general - > apart from the part that the floating point conversion is incorrect? What I > mean is- do you think the values that I am getting (7,8,9...) are actually > VBatt values, but after conversion, they are producing unreliable numbers? > > Thanks > Debasmit > > -----Original Message----- > From: Michael Schippling [mailto:[email protected]] > Sent: Monday, March 29, 2010 7:04 PM > To: Debasmit Banerjee > Cc: [email protected] > Subject: Re: [Tinyos-help] Mica2: Reading Battery volatge > > Since itoa stands for "Integer to Alpha" you are correct > that you are using the wrong function. You want an ftoa() > which usually doesn't exist. You might be able to use > sprintf(), but it will drag a lot of code into your > module, if it exists. > > I generally advise avoiding floating point on our > controllers because they have only minimal integer > math support. > > MS > > Debasmit Banerjee wrote: >> Hi, >> >> >> >> I am fairly new to TinyOS. I want to read the battery voltage for my >> application. The values I am getting for VBatt vary like 7,8,9,10,11 for >> different batteries I use. I am storing the VBatt in a float. And I am >> sending the value through the serial port to display in a terminal. I am >> using itoa() to convert the float value to string which is sent to the >> serial port using Serial.send() - this might be incorrect because I am >> using itoa() for a float value. I don't know how else to check the value >> of the voltage, but I don't know how to convert float to string. >> >> I don't know whether the problem might be this or something else. >> >> >> >> The code I use is this: >> >> >> >> Sensorboard.h: >> >> >> >> #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) >> >> >> >> >> >> Test.nc: >> >> >> >> TestM.BattControl->Voltage; >> >> TestM.ADCBATT ->Voltage; >> >> >> >> >> >> >> >> TestM.nc: >> >> >> >> uses >> >> { >> >> interface ADC as ADCBATT; >> >> interface StdControl as BattControl; >> >> } >> >> >> >> Implementation >> >> { >> >> float vBatt; >> >> >> >> command result_t StdControl.init() >> >> { >> >> >> >> call BattControl.init(); >> >> return SUCCESS; >> >> } >> >> >> >> command result_t StdControl.start() >> >> { >> >> call BattControl.start(); >> >> return SUCCESS; >> >> } >> >> >> >> command result_t StdControl.stop() >> >> { >> >> call BattControl.stop(); >> >> return SUCCESS; >> >> } >> >> >> >> async event result_t ADCBATT.dataReady(uint16_t datas) >> >> { >> >> vBatt = 1.223*1024/datas; >> >> >> >> return SUCCESS; >> >> } >> >> >> >> event result_t MyTimer.fired() >> >> { >> >> SET_BAT_MONITOR(); >> >> call ADCBATT.getData(); >> >> CLEAR_BAT_MONITOR(); >> >> >> >> itoa(vBatt, temp, 10); >> >> call Serial.Send(temp, strlen(temp)); >> >> >> >> } >> >> >> >> } >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Tinyos-help mailing list >> [email protected] >> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help > _______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
