Michael,
Your advice on moving the stop() to dataReady()
helped. I need to adjust the reading as it varies around 200 mbar for pressure
with a battery voltage, giving a false readings. However I made a mistake in a
code, that's why you were probably confused. The Pressure.dataReady()
should look like this to compensate for a bttery voltage drop:
async event result_t
Pressure.dataReady(uint16_t data){
P = (float)(data)*Vbatt/1024.0;
P = (P/3 + 0.32667)/0.01067; //kPa infineon
// P = (P/3 + 0.095)/0.009; //kPa motorola
P = P*10; //kPa to mbar
press = (uint16_t)(P);
signal ADC.dataReady(press);
return SUCCESS;
}
P = (float)(data)*Vbatt/1024.0;
P = (P/3 + 0.32667)/0.01067; //kPa infineon
// P = (P/3 + 0.095)/0.009; //kPa motorola
P = P*10; //kPa to mbar
press = (uint16_t)(P);
signal ADC.dataReady(press);
return SUCCESS;
}
Thanks a million.
Amra
----- Original Message -----
From: "Michael Schippling" <[EMAIL PROTECTED]>
To: "Amra Pasic" <[EMAIL PROTECTED]>
Cc: "tinyos help" <[email protected]>
Sent: Monday, December 12, 2005 7:42
PM
Subject: Re: [Tinyos-help] battery voltage on
mica2
> of the mica2 schematic. It took me a little while to figure it
> out because the logic is wonky. What you are reading is a
> fixed voltage reference. It 'works' because the ADC reference
> is the battery itself, so as the bat drops the ref seems to
> rise in value...at least that's the conclusion I came to...
>
> Assuming that you are not getting a trustworthy Voltage reading,
> I think your problem is calling BattControl.stop() right after
> starting your conversion. This shuts off the BAT_MON pin which
> powers the voltref, possibly before the ADC has had time to
> sample it. I'm also not sure what the StdControl.start() is for
> in that method.
>
> If power is an issue then you might want to do the BattControl.start()
> in the getData() and the stop() in dataReady().
>
> And...now that I look, are you calling ADC.getData() anywhere?
> My usual layout is to get the timer going in the main start()
> and have the timer.fired() initiate a conversion by calling
> some getData(). Then either round-robin each ADC in the fired()
> or chain them through the dataReady()s.
>
> If your sensor is powered from the same battery and is reasonably
> linear with voltage (it looks like your calc assumes that), then
> why do you need to adjust the readings at all?
>
> One last quibble: floats are expensive...you could do everything
> in fixed point...but that's just me.
> MS
>
>
> Amra Pasic wrote:
>> 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
>
_______________________________________________ Tinyos-help mailing list [email protected] https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
