45

Dependencies:   mbed BufferedSerial LS7366LIB FastPWM

timer.h

Committer:
lsh2205
Date:
2020-03-23
Revision:
0:c21936a3520a

File content as of revision 0:c21936a3520a:


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);
}