An Example Using A Master Roll Over Timer To Get Time Since Last Event


//----- DO IN 1mS HEARTBEAT TIMER -----
main_1ms_clock_timer_irq++;


//----- USING THE TIMER -----
unsigned long main_1ms_clock_timer_irq;
unsigned long main_1ms_clock_timer;
unsigned long process_last_time;
unsigned long process_1ms_time_since_last;


  //Create a local copy of the timer (which won't change in the interrupt when being used - if no interrupt then no need to use)
  main_1ms_clock_timer = main_1ms_clock_timer_irq;
  while (main_1ms_clock_timer != main_1ms_clock_timer_irq)    //Use sizeof(main_1ms_clock_timer) != the processor native bit length
    main_1ms_clock_timer = main_1ms_clock_timer_irq;
  

  //Start timing
  process_last_time = main_1ms_clock_timer;


  //Time since start
  process_1ms_time_since_last = (main_1ms_clock_timer - process_last_time);    //Time in mS since last time point with roll over of the timer inherantly compensated for

 

 

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *