NNP STM Generic Remote Module git-main
Loading...
Searching...
No Matches
timerscfg.h
1/*
2 * timerscfg.h
3 *
4 * Created on: Oct 9, 2024
5 * Author: jenej
6 */
7
8#ifndef INC_ST32_TIMERSCFG_H_
9#define INC_ST32_TIMERSCFG_H_
10
11// Whatever your microcontroller, the timer wont work if
12// TIMEVAL is not at least on 32 bits
13#define TIMEVAL UNS32
14
15// The timer of the STM32 counts from 0 to 0xFFFF (it can be
16// shortened setting counter ARR register eg. to get 2ms instead of 2.048ms)
17#define TIMEVAL_MAX 0xFFFF
18
19#if (FOSC == 8000)
20// The timer is incrementing every 8 us at 8 Mhz/64 clock.
21#define MS_TO_TIMEVAL(ms) ((ms) * 125UL) //JML added UL otherwise may overflow
22#define US_TO_TIMEVAL(us) ((us)>>3)
23#endif
24#if (FOSC == 4000)
25// The timer is incrementing every 16 us at 4 Mhz/64 clock.
26// clock will be slightly slow (63/62.5=1.008)*ms
27#define MS_TO_TIMEVAL(ms) ((ms) * 63UL) //JML added UL otherwise may overflow
28#define US_TO_TIMEVAL(us) ((us)>>4)
29#endif
30#if (FOSC == 2000)
31// The timer is incrementing every 32 us at 2 Mhz/64 clock
32// clock will be slightly fast (31/31.25=0.996)*ms
33#define MS_TO_TIMEVAL(ms) ((ms) * 31UL) //JML added UL otherwise may overflow
34#define US_TO_TIMEVAL(us) ((us)>>5)
35#endif
36#if (FOSC == 1000)
37
38#define MS_TO_TIMEVAL(ms) ((ms) * 100UL) //JML added UL otherwise may overflow
39#define US_TO_TIMEVAL(us) ((us)>>3)
40#endif
41
42#endif /* INC_ST32_TIMERSCFG_H_ */