Go Down

Topic: saving energy (Read 784 times) previous topic - next topic

largos

i try to make a code for saving energy in arduino by using IDLE MODE...
i used timer 2 for give an intteruption to my processeur every 6s...
but my problem is,how i can make a mesure to verify that my code is correct???
can someone help me please....
thanks...

Quote

#include <Timer.h>
#include <avr/sleep.h>

const int ledPin=13 ;    //declarer le port 13 comme output
int iEtat ;

TIMER TIM = TIMER();  //instancier la class de la TEMPS

void setup() {
  pinMode (ledPin,OUTPUT);
  iEtat = 0 ;    //initialise à 0
  digitalWrite (ledPin,iEtat);     //ecrire la valeur iEtat à broche 13
  TIM.Init() ;            //appelle la fonction donc la biblio
  TIM.Stop() ;            //appelle la fonction donc la biblio
  TIM.Set(6000) ;        //appelle la fonction donc la biblio
  TIM.Start() ; 
  set_sleep_mode(SLEEP_MODE_IDLE);   // sleep mode is set here
  sleep_enable();  //appelle la fonction donc la biblio
}

void loop(){
  enum TIMERSTATE EtatDuTimer ;    
    while(1) {   
     digitalWrite (ledPin,iEtat);
      EtatDuTimer = TIM.GetState() ;
      if(EtatDuTimer == FINI) {
        iEtat = ! iEtat ;
        digitalWrite (ledPin,iEtat);
        TIM.Start() ;
      }       
  }  
  sleep_mode(); 
}



johnwasser

You could measure the current draw with and without your sleep code.  If the current draw is lower during sleep then you have done it correctly.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

bubulindo

placing an ampmeter reading the current taken by the arduino will let you know if your code is doing something.

Regarding the code, I have no idea if it'll work since I haven't seen how the TIMER class is built. But I suspect that it won't work since it should need an interrupt function to be called every 6s (or when the timer expires). But again, I have no idea if this is the case.
This... is a hobby.

largos

which pin must i make a mesure to read a current taken by the arduino???


johnwasser

Usually you would be using energy saving features when your project has to run off batteries.  Put the current meter between the + side of the battery and here the battery connects to the Arduino, typically the Vin pin, +5 pin, or the power jack.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

gardner

There have been other recent threads regarding this topic, eg:
http://arduino.cc/forum/index.php/topic,54950.0.html
http://arduino.cc/forum/index.php/topic,60554.0.html

Search for "sleep_cpu" and you will find a good deal of material.

You will find that SLEEP_MODE_IDLE will be woken up by any interrupt, including the timer0 one, which will fire every 1,000 microseconds.  Even so, sleeping the CPU will make your main loop run at a thousand loops/sec rather than a million plus.  The energy savings might well be worth it.

Go Up