Add Method to get some kind of ticks #1

Closed
opened 6 years ago by Ruakij · 2 comments
Ruakij commented 6 years ago (Migrated from gitea.railduction.eu)

Implement how to get the current tick (of the cpu) or create own tick with a defined time interval.

One possibility would be to use a timer interrupt.

Implement how to get the current tick (of the cpu) or create own tick with a defined time interval. One possibility would be to use a timer interrupt.
JohnD commented 6 years ago (Migrated from gitea.railduction.eu)

solution proposal:


#include <time.h>

int main(){

   clock_t start, end;
   int32_t cpu_tick = 0;

   if(cpu_tick== 0){
      start = clock();
      for(int i=0; i<100000; i++){
         int a = i*2 + i %2323;
      }
      end = clock();
      cpu_tick = ((int32_t) (end-start)) / F_CPU;


   }

   //Our code

}

solution proposal: ``` #include <time.h> int main(){ clock_t start, end; int32_t cpu_tick = 0; if(cpu_tick== 0){ start = clock(); for(int i=0; i<100000; i++){ int a = i*2 + i %2323; } end = clock(); cpu_tick = ((int32_t) (end-start)) / F_CPU; } //Our code } ```
Ruakij commented 6 years ago (Migrated from gitea.railduction.eu)

Example calculation for nextTick:



clock() + F_CPU * 0.2





The nextTick should then be in 0.2s

Example calculation for nextTick: <br> <code> clock() + F_CPU * 0.2 </code> <br> <br> The nextTick should then be in 0.2s
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Ruakij/Geigercounter#1
Loading…
There is no content yet.