Every time this function is called, a timestamp will be stored and compared with the last timestamp. The difference between now and the last timestamp is used to calculate the wheel revolutions per minute. Also the trip distance will be incremented by calling this ISR.
Definition at line 112 of file speed.c. References LOCAL_STATIC, MAX_RELIABLE_SPEED, mg_u16WheelSize, mg_u32Distance, mg_u32Rpm, mg_u32TickTime, mg_u8NumMagnetsTacho, ONE_MINUTE_MS, SPEED_INT_DISABLE, SPEED_INT_ENABLE, and timer_GetSystemTime(). { LOCAL_STATIC UINT32 u32CurrentTime; UINT32 u32DiffTime; SPEED_INT_DISABLE(); u32CurrentTime = timer_GetSystemTime(); u32DiffTime = u32CurrentTime - mg_u32TickTime; /* Maybe there will be false sensor signals from keybouncing. To filter these out we use a maximum speed definition that gives a minimum diff time between two sensor signals: wheel_size[mm] * 3.6 -------------------------------------------- max_reliable_speed[km/h] * number_of_magnets And to avoid floating point numbers we sustitute 3.6 with 36/10. */ if(u32DiffTime >= ( (mg_u16WheelSize * 36U) / (MAX_RELIABLE_SPEED * 10U * mg_u8NumMagnetsTacho) ) ) { mg_u32TickTime = u32CurrentTime; mg_u32Rpm = ONE_MINUTE_MS / u32DiffTime / mg_u8NumMagnetsTacho; mg_u32Distance += mg_u16WheelSize; } SPEED_INT_ENABLE(); }
Here is the call graph for this function:
![]() |