STC15W408AS library 0.9.0
|
Macros | |
#define | timer_uint16_ticks_to_freq100(ticks, timer_clock_divider, frequency_divider_scale) ((100 * get_master_clock_frequency() / (timer_clock_divider * (1 + (uint32_t)ticks))) >> frequency_divider_scale) |
Convert ticks to timer frequency multiplied by 100. More... | |
#define | timer_frequency_to_ticks_unsafe(frequency, timer_clock_divider, frequency_divider_scale) (((get_master_clock_frequency() >> 1) / (frequency * timer_clock_divider)) >> frequency_divider_scale) |
Convert timer frequency to ticks (unsafe operation) More... | |
#define | timer_ticks_to_ms_usafe(ticks, timer_divider, frequency_divider_scale) (((1UL + (uint32_t)ticks) / ((get_master_clock_frequency_high_part() / timer_divider) >> frequency_divider_scale))) |
Convert ticks count to ms. More... | |
#define | timer_ms_to_ticks_usafe(ms, timer_clock_divider) (ms * ((get_master_clock_frequency_high_part() + 26) >> get_frequency_divider_scale()) / timer_clock_divider) |
Convert milliseconds to timer ticks. More... | |
Functions and data structures for converting timer ticks to frequency and times for timers.
#define timer_frequency_to_ticks_unsafe | ( | frequency, | |
timer_clock_divider, | |||
frequency_divider_scale | |||
) | (((get_master_clock_frequency() >> 1) / (frequency * timer_clock_divider)) >> frequency_divider_scale) |
Convert timer frequency to ticks (unsafe operation)
Frequency to ticks is a reverse operation of ticks to frequency,
Not all frequency ranges can be correctly coverted to ticks. This method doesnt carefully analyze frequency to ticks covertion correctness.
For 1T mode and frequency divider scale 0 minimal frequency is near 100Hz (11059200 / 2 / 100) = 55296 ticks and maximum frequency is near 5MHz 1.1 ticks
For 12T mode and frequency divider scale 0 minimal frequency is near 8Hz (11059200 / 2 / 12 / 8) = 57600 ticks and maximum frequency is near 400kHz
frequency | uint32_t frequency |
timer_clock_divider | uint8_t or timer_clock_divider_t enum T12 or T1 timer clock divider |
frequency_divider_scale | uint8_t mcu clock frequency diviver scale in range of [0..7] |
#define timer_ms_to_ticks_usafe | ( | ms, | |
timer_clock_divider | |||
) | (ms * ((get_master_clock_frequency_high_part() + 26) >> get_frequency_divider_scale()) / timer_clock_divider) |
Convert milliseconds to timer ticks.
1 ms = ((get_master_clock_frequency_high_part() + 26) >> get_frequency_divider_scale()) / timer_clock_divider
This routine doesnt check overflows. Its unsafe.
ms | uint16_t ms to convert |
timer_clock_divider | timer clock divider |
#define timer_ticks_to_ms_usafe | ( | ticks, | |
timer_divider, | |||
frequency_divider_scale | |||
) | (((1UL + (uint32_t)ticks) / ((get_master_clock_frequency_high_part() / timer_divider) >> frequency_divider_scale))) |
Convert ticks count to ms.
This method doesnt analyze corner cases and overflow of result. Be careful.
ticks | uint16_t ticks count |
timer_divider | timer_clock_divider_t 1T or 12T timer clock divider |
frequency_divider_scale | uint8_t MCU frequency divider scale |
#define timer_uint16_ticks_to_freq100 | ( | ticks, | |
timer_clock_divider, | |||
frequency_divider_scale | |||
) | ((100 * get_master_clock_frequency() / (timer_clock_divider * (1 + (uint32_t)ticks))) >> frequency_divider_scale) |
Convert ticks to timer frequency multiplied by 100.
The output frequency = (SYSclk/timer_clock_divider)/((65536-ticks) * 2). Multiplication by 100 is used for get frequency value without using float numbers.
uint16 ticks used in mode 0, 1, 3. Low byte of ticks is used in mode 2.
ticks | uint16_t timer ticks count to covert |
timer_clock_divider | uint8_t timer clock divider T12 or T1 |
frequency_divider_scale | uint8_t mcu frequency divider scale 0..7 |