help with code and sleep routine..

Thread Starter

toffee_pie

Joined Oct 31, 2009
235
Hi guys,

I have code here which basically does some operands, checks the validity of results and lights up a led sequence and moves onto the next operand in between a delay.

each operand is run x amount of times for integrity.

I am wondering is it feasible to have a sleep routine which puts the atmega328 to sleep after each operand is done, and to wake up and do the next operand etc.. ie: replace the delays with a sleep routine.?

I can use a wdt/interrupt etc to wake it up i assume?

I am interested in doing a power consumption comparison between case a/ and case b/.


thanks for listening.


Rich (BB code):
int main (void)

{
int repeat = 0;

 //SetSystemClockPrescaler(2);

 while(1) // repeat all functions 3 x times
 
 { 
         for(repeat = 0; repeat < 4; repeat++){
         array(); // run array function
        _delay_ms(3000);
        reset_d();
        }

           for(repeat = 0; repeat < 3; repeat++){
        pwm_led();  // run PWM Led function
        _delay_ms(3000);
        reset_d();
        }
        
        for(repeat = 0; repeat < 3; repeat++){
        maths(); //  run Math function
       _delay_ms(3000);
        reset_d();
        }

        for(repeat = 0; repeat < 3; repeat++){
        simpsons(); // run simpson algorithm
        _delay_ms(3000);
        reset_d();
        }

        for(repeat = 0; repeat < 3; repeat++){

        newton_sqrt(20); // run newton rhapson for square root of 20
        _delay_ms(3000);
        reset_d();
        }
        
        

//   sleep_mode();



     

 }
return (1);


}
 

retched

Joined Dec 5, 2009
5,207
I would check with the datasheet to see the amount of power it takes to wake up.

AND if the sleep/wake period is longer than your desired delay.

If you actually do save power by sleeping through the 3 second delays, that cant be bad.

I do not know off hand, but I bet you could find sleep functions prewritten.

There may even be a low power mode for the 328, but I cannot recall.

The newer ATMEL and PIC micropower uCs have the ability to hibernate for a set time.

For instance, If you want a data logger to take the temperature at 8am every morning for a year, the uC need only be awake for a few mS every day.

Thing is, you still have to be counting the time passing, so I dont really see how you could save power. The going to sleep and waking up may eat any gains.
 

Thread Starter

toffee_pie

Joined Oct 31, 2009
235
That is true, seems the gains to be had would be minimal, if anything.

I could add up all the delays (15 sceonds) and replace if with 1 sleep/wake up instead for part two.?

makes more sense.

scenario 1 / 5 routines with 15 seconds delay

scenario 2 / 5 routines with a sleep/wake up over 15 seconds.


what do you think?
 
Top