Programming problem in sleep mode.


hi  guys have following code running on modified pro mini.
code: [select]
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <virtualwire.h>

const byte led = 13;

int atimer;


typedef struct roverremotedata
{
  int    tx_id;
  int    sensor1data;// variable data each sensor
};

void awaketimer()
{
  atimer++;
}
//void datatx()
//{
//
//}

void flash ()
{
  pinmode (led, output);
  digitalwrite (led, high);
  delay (1000);
  digitalwrite (led, low);
  delay (50);
  atimer = 0;
}

// watchdog interrupt
isr (wdt_vect)
{
  wdt_disable();  // disable watchdog
}  // end of wdt_vect

void setup ()
{
  // virtualwire setup
  vw_setup(2000); // bits per sec
  vw_set_tx_pin(11);
  pinmode(9,output);

}

void loop ()
{
  int battvalue = 0;
  //delay(5000);
    int battcheckpin = a3;
    pinmode(battcheckpin,input);
    delay(100);
    battvalue= analogread(battcheckpin);
    delay(100);
   
  awaketimer();
  if ( atimer == 2) // 45 = 6 min// 75 = 8 min // 450 = 1 hour
  {
    flash ();
   // datatx();
     digitalwrite(9,high);
  struct roverremotedata payload;

  payload.tx_id = 3;
  payload.sensor1data = battvalue;

  vw_send((uint8_t *)&payload, sizeof(payload));
  vw_wait_tx();
  digitalwrite(9,low);
  }

  digitalwrite(9,low);

  // disable adc
  adcsra = 0; 

  // clear various "reset" flags
  mcusr = 0;     
  // allow changes, disable reset
  wdtcsr = bit (wdce) | bit (wde);
  // set interrupt mode , interval
  wdtcsr = bit (wdie) | bit (wdp3) | bit (wdp0);    // set wdie, , 8 seconds delay
  wdt_reset();  // pat dog

  set_sleep_mode (sleep_mode_pwr_down); 
  sleep_enable();

  // turn off brown-out enable in software
  mcucr = bit (bods) | bit (bodse);
  mcucr = bit (bods);
  sleep_cpu (); 

  // cancel sleep precaution
  sleep_disable();
} // end of loop


it works great power saving , test have wake once minute , read voltage input on pin a3 . problem strange reason pin reading not update once reading taken.

example
when starting proram analog read of pin a3 reads 1023 ie 3.3v 3.3v mini. if remove pin , apply 1.5v voltage on a3 pin still reports 3.3v.

i have tried place line code
code: [select]
battvalue= 0;

after transmission complete , still not work.

does sleep library have impact ont eh analog read function or going on. pin not update reading after first bootup.


any great

code: [select]
   pinmode(battcheckpin,input);
why?


Arduino Forum > Using Arduino > Programming Questions > Programming problem in sleep mode.


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support