help with code and sleep routine..

Discussion in 'Programmer's Corner' started by toffee_pie, Aug 28, 2010.

  1. toffee_pie

    Thread Starter Active Member

    Oct 31, 2009
    162
    7
    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.


    Code ( (Unknown Language)):
    1. int main (void)
    2.  
    3. {
    4. int repeat = 0;
    5.  
    6.  //SetSystemClockPrescaler(2);
    7.  
    8.  while(1) // repeat all functions 3 x times
    9.  
    10.  {
    11.          for(repeat = 0; repeat < 4; repeat++){
    12.          array(); // run array function
    13.         _delay_ms(3000);
    14.         reset_d();
    15.         }
    16.  
    17.            for(repeat = 0; repeat < 3; repeat++){
    18.         pwm_led();  // run PWM Led function
    19.         _delay_ms(3000);
    20.         reset_d();
    21.         }
    22.        
    23.         for(repeat = 0; repeat < 3; repeat++){
    24.         maths(); //  run Math function
    25.        _delay_ms(3000);
    26.         reset_d();
    27.         }
    28.  
    29.         for(repeat = 0; repeat < 3; repeat++){
    30.         simpsons(); // run simpson algorithm
    31.         _delay_ms(3000);
    32.         reset_d();
    33.         }
    34.  
    35.         for(repeat = 0; repeat < 3; repeat++){
    36.  
    37.         newton_sqrt(20); // run newton rhapson for square root of 20
    38.         _delay_ms(3000);
    39.         reset_d();
    40.         }
    41.        
    42.        
    43.  
    44. //   sleep_mode();
    45.  
    46.  
    47.  
    48.      
    49.  
    50.  }
    51. return (1);
    52.  
    53.  
    54. }
    55.  
     
  2. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    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.
     
  3. toffee_pie

    Thread Starter Active Member

    Oct 31, 2009
    162
    7
    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?
     
Loading...