Go Down

Topic: saving energy (Read 674 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.
Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

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