Watch and log free sram during runtime..


  • Code Contributor

    (I copied interrupt setup from another script, dont know if its 100% correct, but it works :P) i think ir runs the timer1 each 1ms.

     int min_mem=32000;
     int free_mem=0;
     ISR(TIMER1_COMPA_vect) {
     cli();
       extern int __heap_start, *__brkval;
       int m = (int) &m - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
       if (m < min_mem) min_mem=m;
       free_mem=m;
     sei();
     } 
     
     int main(void) {
     	init();
     	cli();
     	TCCR1A = 0;
     	TCCR1B = 0;
     	TCNT1  = 0;
     	OCR1A = 1000;
     	TCCR1B |= (1 << WGM12);
     	TCCR1B |= (1 << CS11);
     	TIMSK1 |= (1 << OCIE1A); 
     	sei();
     	
     	while (1) {
     		do_stuff();
     		delay(100);
     		Serial.print("mem: ");
     		Serial.print(free_mem,DEC);
     		Serial.print(" - lowest: ");
     		Serial.println(min_mem,DEC);
     	}
     }

Log in to reply
 

Suggested Topics

  • 3
  • 2
  • 24
  • 2
  • 2
  • 3

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts