STC15W408AS library 0.9.0
|
tick to frequency conversions | |
Timer ticks to overlow frequency and vice versa convertions | |
#define | timer2_uint16_ticks_to_freq100(ticks) (timer_uint16_ticks_to_freq100(ticks, get_timer2_clock_divider(), get_frequency_divider_scale())) |
Convert ticks to timer frequency for timer2 multiplied by 100. More... | |
#define | timer2_frequency_to_ticks_unsafe(frequency) (timer_frequency_to_ticks_unsafe(frequency, get_timer2_clock_divider(), get_frequency_divider_scale())) |
Unsafe approximation timer2 frequency corresponding to ticks. More... | |
#define | timer2_ticks_to_ms_usafe(ticks) (timer_ticks_to_ms_usafe(ticks, get_timer2_clock_divider(), get_frequency_divider_scale())) |
Convert ticks count to ms. More... | |
UART baud rate to ticks | |
UART baud rate to timer ticks to overlow frequency and vice versa convertions | |
#define | timer2_mode0_baudrate_to_ticks(uart_baudrate) ((get_master_clock_frequency() >> get_frequency_divider_scale())/4/uart_baudrate) |
Calculate timer2 ticks for UART baudrate. More... | |
#define | timer2_ms_to_ticks_usafe(ms) (timer_ms_to_ticks_usafe(ms, get_timer2_clock_divider())) |
Convert milliseconds to timer2 ticks. More... | |
Functions and data structures for converting timer ticks to frequency and times for timer2.
#define timer2_frequency_to_ticks_unsafe | ( | frequency | ) | (timer_frequency_to_ticks_unsafe(frequency, get_timer2_clock_divider(), get_frequency_divider_scale())) |
Unsafe approximation timer2 frequency corresponding to ticks.
ticks = get_master_clock_frequency() / (2 * get_timer2_clock_divider() * frequency))
Call this method after timer2 is initialized and MCU clock frequency divider scale is set.
This method doesnt analyze corner cases and overflow of result. Be careful.
frequency | uint32_t frequency value in Hz. Should not be 0; |
#define timer2_mode0_baudrate_to_ticks | ( | uart_baudrate | ) | ((get_master_clock_frequency() >> get_frequency_divider_scale())/4/uart_baudrate) |
Calculate timer2 ticks for UART baudrate.
Adapted for use mcu frequency divider. On some baudrates get not exact values. The reasons are
freq/4 = 2764800
Freq div | Baudrate | Ticks hex |
---|---|---|
1 | 9600 | 0x120 |
1 | 19200 | 0x90 |
1 | 38400 | 0x48 |
1 | 57600 | 0x30 |
1 | 74880 | 0x24 |
1 | 115200 | 0x18 |
1 | 230400 | 0x0C |
1 | 250000 | 0x0B |
freq / 8 = 1382400
Freq div | Baudrate | Ticks hex |
---|---|---|
2 | 9600 | 0x90 |
2 | 19200 | 0x48 |
2 | 38400 | 0x24 |
2 | 57600 | 0x18 |
2 | 74880 | 0x12 |
2 | 115200 | 0x0C |
2 | 230400 | 0x06 |
2 | 250000 | 0x05 0x06? |
freq/16 = 691200
Freq div | Baudrate | Ticks hex |
---|---|---|
4 | 9600 | 0x48 |
4 | 19200 | 0x24 |
4 | 38400 | 0x12 |
4 | 57600 | 0x0C |
4 | 74880 | 0x09 |
4 | 115200 | 0x06 |
4 | 230400 | 0x03 |
4 | 250000 | 0x02-0x03? |
uart_baudrate | uint16_t UART baudrate |
#define timer2_ms_to_ticks_usafe | ( | ms | ) | (timer_ms_to_ticks_usafe(ms, get_timer2_clock_divider())) |
Convert milliseconds to timer2 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 |
#define timer2_ticks_to_ms_usafe | ( | ticks | ) | (timer_ticks_to_ms_usafe(ticks, get_timer2_clock_divider(), get_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 |
#define timer2_uint16_ticks_to_freq100 | ( | ticks | ) | (timer_uint16_ticks_to_freq100(ticks, get_timer2_clock_divider(), get_frequency_divider_scale())) |
Convert ticks to timer frequency for timer2 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.
Call this method after timer2 is initialized and MCU clock frequency divider scale is set.
ticks | uint16_t timer ticks count to covert |