45
Dependencies: mbed BufferedSerial LS7366LIB FastPWM
Diff: timer.h
- Revision:
- 0:c21936a3520a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/timer.h Mon Mar 23 08:38:40 2020 +0000 @@ -0,0 +1,40 @@ + +Timer t; + + +int delay_time=0; + +bool find_delay=false; + +uint32_t loop_time = 0; +uint32_t ex_loop_time = 0; +uint32_t dif_loop_time = 0; +double loop_time_f = 0; + +void timer_init() +{ + //t.start(); +} + + +void loop_time_run() +{ + loop_time = t.read_us(); + dif_loop_time=loop_time-ex_loop_time; + ex_loop_time = loop_time; + + loop_time_f=(double)dif_loop_time; + + if(dif_loop_time==2000) + find_delay=true; + + if(find_delay==false) + { + if(dif_loop_time>2000) + delay_time--; + if(dif_loop_time<2000) + delay_time++; + } + + wait_us(delay_time); +} \ No newline at end of file