Author Topic: How To save power in LwMesh WSNDemo  (Read 2881 times)

0 Members and 1 Guest are viewing this topic.

Offline vishalTopic starter

  • Regular Contributor
  • *
  • Posts: 102
  • Country: in
How To save power in LwMesh WSNDemo
« on: August 07, 2017, 10:57:38 am »
Hi ,
  I am using the Lwmesh stack for avr-atmega256rfr2 MCU.I loaded the stack and the device is used for some applications.It includes continuously sending streaming data and on demand based response from the device.But the problem we are facing is we are not able to save battery(Since the devices are battery powered).In WSNDemo-application code we found that the end device go to sleep using timer2.We don't have the timer2 so we used  watch dog timer to sleep the device using 4 second delay as follows.
Code: [Select]
cli();
wdt_reset();
WDTCSR=(1<<WDCE)|(1<<WDE)
WDTCSR=(1<<WDIE)|(1<<WDE)|(1<<WDP3);
sei();
This also not useful to save battery.Do we have any better mechanism to save battery life
« Last Edit: August 07, 2017, 11:22:55 am by vishal »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: How To save power in LwMesh WSNDemo
« Reply #1 on: August 07, 2017, 08:29:13 pm »
What is this code supposed to achiever? TC2 is used to wake up from sleep, but you need to start the sleep first, before you can wake up from it.
Alex
 

Offline vishalTopic starter

  • Regular Contributor
  • *
  • Posts: 102
  • Country: in
Re: How To save power in LwMesh WSNDemo
« Reply #2 on: August 08, 2017, 04:52:23 am »
I have changed HAL_sleep code as follows:
Code: [Select]
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sei();
sleep_cpu();
sleep_disable();
But We cant save the battery life .The battery life is now one or two days with coordinator.If there is no coordinator connector it will  drain after 2 or 3 hours.Do we get a better battery life with timer2?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: How To save power in LwMesh WSNDemo
« Reply #3 on: August 08, 2017, 05:00:22 am »
Have you actually measured current consumption? Or you are measuring it by days of working?

It is really hard to say what you are doing wrong without debugging.

That also looks like ASF stuff, and I have no clue what any of this does, and I don't care to find out.
Alex
 

Offline vishalTopic starter

  • Regular Contributor
  • *
  • Posts: 102
  • Country: in
Re: How To save power in LwMesh WSNDemo
« Reply #4 on: August 11, 2017, 09:39:45 am »
Yes I have measured the current consumption.It takes 1micro ampere while sleeping and 20 milli ampere when it wakes up.I am using avr-atmega256rfr2 MCU .I have modified the halSleep.c with the following code
Code: [Select]
   void HAL_Sleep(){
     halSleepTimerEvent=false;
     while(1){
               set_sleep_mode(SLEEP_MODE_PWR_DOWN);
               sleep_enable();
               sei();
               sleep_cpu();
               sleep_disable();
               if(halSleepTimerEvent){
                    return;
           }
   }

 }
ISR(WDT_vect){
    halSleepTimerEvent=true;
}

The Peer2Peer.c file with watchdog timer functionality also attached.Can you please tell us whether we need reset of any components while it wakes up.When we added the sleep routing the appDataInd() function is not working.Here we are waiting 10secs after sleep to receive data via appDataInd().But its not receiving any data once it wake up.What is the mistake here.Please help
« Last Edit: August 11, 2017, 09:47:06 am by vishal »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: How To save power in LwMesh WSNDemo
« Reply #5 on: August 11, 2017, 04:58:23 pm »
1 uA is as low as you will realistically go.

You never call NWK_SleepReq(), so transceiver will never sleep. I have no idea why you are getting 1uA with this code.
Alex
 

Offline vishalTopic starter

  • Regular Contributor
  • *
  • Posts: 102
  • Country: in
Re: How To save power in LwMesh WSNDemo
« Reply #6 on: August 12, 2017, 02:54:06 pm »
Sorry.i got this result with wsndemo.c program. In that the stack already called nwk_sleepreq(),.but my requirement is like this peer2peer code.It should send data when some data hits in appdataind().and it shoud sleep and wake up each 8sec to check dataind().I also tried by addind following lines in APP_STATE_IDLE
Code: [Select]
NWK_SleepReq();
HAL_Sleep();
NWK_wakeupReq();
HAL_UartwriteByte(0x89);//To debug
_delay_ms(2000);//To wait for receivng any data
appstate=APP_STATE_IDLE;
here the uart prints always 00 Instead of 89.Thats why we confused whether the wakeup need any reinitialization.kindly point out my mistake
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: How To save power in LwMesh WSNDemo
« Reply #7 on: August 12, 2017, 04:40:33 pm »
You can't "wait" for data with a delay. You have to actively call SYS_TaskHandler() for nwkDataInd() to happen.

It is also possible that frequency of the main clock is not stable enough after exiting sleep mode, so UART  sends incorrect characters. Get a scope and check what is actually being sent.
Alex
 

Offline vishalTopic starter

  • Regular Contributor
  • *
  • Posts: 102
  • Country: in
Re: How To save power in LwMesh WSNDemo
« Reply #8 on: August 14, 2017, 08:39:40 am »
Thank you for your reply.I debug the program and could find that the sleep function  causes the uart to print error data.In HAL_sleep I wrote as
Code: [Select]
void HAL_Sleep(){
halSleepTimerEvent=false;
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
cli();
while(1){
 sleep_enable();   
 sei();
 sleep_cpu();
 sleep_disable();

 if(halSleepTimerEvent){
    return ;
   }
}
}

The above was my sleep function when  I called it I got error data in UART.So I just comment out the sleep function and called as follows
Code: [Select]
void HAL_Sleep(){
halSleepTimerEvenet=false;
while(1)

{
    if(halSleepTimerEvent){
       return;
    }
}

Is that sleep function correct.Do I want to reinitialize anything when it wakes up?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: How To save power in LwMesh WSNDemo
« Reply #9 on: August 14, 2017, 08:42:39 am »
But your second function does not actually sleep. I don't understand what you are doing.

Errors on UART are caused by frequency instability after oscillator is  restarted after the sleep. Give it some time to become stable before sending the data.
Alex
 
The following users thanked this post: vishal

Offline vishalTopic starter

  • Regular Contributor
  • *
  • Posts: 102
  • Country: in
Re: How To save power in LwMesh WSNDemo
« Reply #10 on: August 18, 2017, 05:11:58 am »
Hi, I got the functioning to work.  :).Thank you so much for your support.My aim was to save battery .Now during sleep am getting 1uA and when it wakes up and send data over RF it takes 22mA.Can we reduce this to something low by disabling any components that are not used?The following were used in the WDT_Init function.
Code: [Select]
DIDR0 = (1 << ADC5D) | (1 << ADC4D) | (1 << ADC3D)
    | (1 << ADC2D) | (1 << ADC1D) | (1 << ADC0D);
 DIDR1 |= (1 << AIN1D) | (1 << AIN0D);
ACSR &= ~(1 << ACIE);
ACSR |= (1 << ACD);
ADCSRA &= ~(1 << ADEN);
 power_adc_disable();
 power_spi_disable();
 power_twi_disable();
 power_usart0_disable();
 power_timer1_disable();
 power_timer0_disable();
 cli();
 wdt_reset();
 WDTCSR=(1<<WDCE)|(1<<WDE);
 WDTCSR=(1<<WDIF)|(1<<WDIE)|(1<<WDP3)|(1<<WDP0);
 sei();
Do we have any way reduce 22mA to some low value.The MCU using is  avr-atmega256rfr2 .

« Last Edit: August 18, 2017, 08:10:54 am by vishal »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: How To save power in LwMesh WSNDemo
« Reply #11 on: August 18, 2017, 08:05:33 am »
You can reduce TX power. That's basically the only way. Power consumption of the transmitter is around 14 mA. The rest is MCU. You can reduce MCU power consumption by reducing the operation frequency.

Whether any of those sacrifices are acceptable for your project is up to you.
Alex
 

Offline vishalTopic starter

  • Regular Contributor
  • *
  • Posts: 102
  • Country: in
Re: How To save power in LwMesh WSNDemo
« Reply #12 on: August 19, 2017, 09:11:07 am »
In WSNDemo application we have tried to send data multiple times to a coordinator when data hit in appDataInd() function.
For this in appDataInd() we wrote the following
Code: [Select]
static bool appDataInd(NWK_DataInd_t *ind)
{
  for(uint8_t i=0;i<2;i++){
   
    appSendData();
    SYS_TimerStop(&appTimer);
    SYS_TimerStart(&appTimer);
  }
}

The code works when we disable #define NWK_ENABLE_ROUTE_DISCOVERY.Whats wrong with this segment .please help us to  send  data mutilple times when data hit in appDataInd also need to  enable #define NWK_ENABLE_ROUTE_DISCOVERY
« Last Edit: August 19, 2017, 09:12:50 am by vishal »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: How To save power in LwMesh WSNDemo
« Reply #13 on: August 19, 2017, 11:13:02 am »
Read the stack documentation.

You can't call NWK_DataReq() twice on the same NWK_DataReq_t structure before confirmation is called.

You need to modify appSendData() to dynamically allocate a NWK_DataReq_t structure from a pool and keep track of the ones submitted to the stack.
Alex
 

Offline vishalTopic starter

  • Regular Contributor
  • *
  • Posts: 102
  • Country: in
Re: How To save power in LwMesh WSNDemo
« Reply #14 on: September 01, 2017, 06:19:13 am »
We worked on  WSNDemo application(for end device) to sleep in 4Sec delay.and while wake up it sends data.When coordinator is connected the wake up time is 5ms.But when there is no coordinator connected we have seen that 1 second wake up time.We have seen that the NWK_ROUTE_DISCOVERY_TIMER_INTERVAL is one of the factors for this delay.But  this 1 second delay is  affecting the battery consumption.Do we have any method to know whether there is any router or coordiantor connected.If they are not in network the device should go into sleep mode.
We need a 5ms wake up time in both cases of  whether there is coordinator connetected  or not.Can we achieve it?
« Last Edit: September 01, 2017, 06:29:52 am by vishal »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: How To save power in LwMesh WSNDemo
« Reply #15 on: September 01, 2017, 06:43:34 am »
If you only need direct link (no routing), then you can specify NWK_OPT_LINK_LOCAL option and there will be no routing attempt. If device is not there, you will get a PHY_NO_ACK error code.

There is no way to know if remote (routing needed) device is present or not.
Alex
 

Offline vishalTopic starter

  • Regular Contributor
  • *
  • Posts: 102
  • Country: in
Re: How To save power in LwMesh WSNDemo
« Reply #16 on: September 01, 2017, 06:51:53 am »
Our application need routing.The direct link is not useful.Do we have any way to reduce atleast that delay to some low value?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: How To save power in LwMesh WSNDemo
« Reply #17 on: September 01, 2017, 10:26:47 am »
In this case you can start reducing discovery time and related parameters, but that will affect normal operation as well, so you need to experiment what values work for you.

But generally you want to have sleeping devices only talk to local devices. and have those local devices pass messages to and from sleeping devices. This way your wake up time will be minimal, and non-sleeping devices will deal with the coordinator.
Alex
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf