How To save power in LwMesh WSNDemo - Page 1
Forum section: electronics / beginners

author: vishal
author_rank: Regular Contributor
timestamp: August 07, 2017, 10:57:38 am
content: 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: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

author: ataradov
author_rank: Super Contributor
timestamp: August 07, 2017, 08:29:13 pm
content: 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.

author: vishal
author_rank: Regular Contributor
timestamp: August 08, 2017, 04:52:23 am
content: I have changed HAL_sleep code as follows:Code: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?

author: ataradov
author_rank: Super Contributor
timestamp: August 08, 2017, 05:00:22 am
content: 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.

author: vishal
author_rank: Regular Contributor
timestamp: August 11, 2017, 09:39:45 am
content: 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 codeCode: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

author: ataradov
author_rank: Super Contributor
timestamp: August 11, 2017, 04:58:23 pm
content: 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.

author: vishal
author_rank: Regular Contributor
timestamp: August 12, 2017, 02:54:06 pm
content: 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_IDLECode:NWK_SleepReq();HAL_Sleep();NWK_wakeupReq();HAL_UartwriteByte(0x89);//To debug_delay_ms(2000);//To wait for receivng any dataappstate=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

author: ataradov
author_rank: Super Contributor
timestamp: August 12, 2017, 04:40:33 pm
content: 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.

author: vishal
author_rank: Regular Contributor
timestamp: August 14, 2017, 08:39:40 am
content: 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 asCode: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 followsCode: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?

author: ataradov
author_rank: Super Contributor
timestamp: August 14, 2017, 08:42:39 am
content: 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.

author: vishal
author_rank: Regular Contributor
timestamp: August 18, 2017, 05:11:58 am
content: 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: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 .

author: ataradov
author_rank: Super Contributor
timestamp: August 18, 2017, 08:05:33 am
content: 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.

author: vishal
author_rank: Regular Contributor
timestamp: August 19, 2017, 09:11:07 am
content: 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 followingCode: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 whenwe 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 toenable #define NWK_ENABLE_ROUTE_DISCOVERY

author: ataradov
author_rank: Super Contributor
timestamp: August 19, 2017, 11:13:02 am
content: 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.

author: vishal
author_rank: Regular Contributor
timestamp: September 01, 2017, 06:19:13 am
content: 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?

author: ataradov
author_rank: Super Contributor
timestamp: September 01, 2017, 06:43:34 am
content: 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.

author: vishal
author_rank: Regular Contributor
timestamp: September 01, 2017, 06:51:53 am
content: Our application need routing.The direct link is not useful.Do we have any way to reduce atleast that delay to some low value?

author: ataradov
author_rank: Super Contributor
timestamp: September 01, 2017, 10:26:47 am
content: 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.