STC15W408AS library 0.9.0
Timer0 Aux

frequency and ticks

Timer ticks to frequency and vice versa convertions

#define timer0_uint16_ticks_to_freq100(ticks)   (timer_uint16_ticks_to_freq100(ticks, get_timer0_clock_divider(), get_frequency_divider_scale()))
 Convert ticks to timer frequency for timer0 multiplied by 100. More...
 
#define timer0_frequency_to_ticks_unsafe(frequency)   (timer_frequency_to_ticks_unsafe(frequency, get_timer0_clock_divider(), get_frequency_divider_scale()))
 Unsafe approximation timer0 frequency corresponding to ticks. More...
 
#define timer0_ticks_to_ms_usafe(ticks)   (timer_ticks_to_ms_usafe(ticks, get_timer0_clock_divider(), get_frequency_divider_scale()))
 Convert ticks count to ms. More...
 
#define timer0_ms_to_ticks_usafe(ms)   (timer_ms_to_ticks_usafe(ms, get_timer0_clock_divider()))
 Convert milliseconds to timer0 ticks. More...
 

tick to frequency conversions

Timer ticks to overlow frequency and vice versa convertions

#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_ms_to_ticks_usafe(ms)   (timer_ms_to_ticks_usafe(ms, get_timer2_clock_divider()))
 Convert milliseconds to timer2 ticks. More...
 

Detailed Description

Functions and data structures for converting timer ticks to frequency and times for timer0.

Author
Michael Golovanov

Macro Definition Documentation

◆ timer0_frequency_to_ticks_unsafe

#define timer0_frequency_to_ticks_unsafe (   frequency)    (timer_frequency_to_ticks_unsafe(frequency, get_timer0_clock_divider(), get_frequency_divider_scale()))

Unsafe approximation timer0 frequency corresponding to ticks.

ticks = get_master_clock_frequency() / (2 * get_timer0_clock_divider() * frequency))

Call this method after timer0 is initialized and MCU clock frequency divider scale is set.

This method doesnt analyze corner cases and overflow of result. Be careful.

Parameters
frequencyuint32_t frequency value in Hz. Should not be 0;
Returns
uint16_t timer0 ticks corresponding to frequency value

◆ timer0_ms_to_ticks_usafe

#define timer0_ms_to_ticks_usafe (   ms)    (timer_ms_to_ticks_usafe(ms, get_timer0_clock_divider()))

Convert milliseconds to timer0 ticks.

1 ms = ((get_master_clock_frequency_high_part() + 26) >> get_frequency_divider_scale()) / timer_clock_divider

This routine doesnt check overflows. Its unsafe.

Parameters
msuint16_t ms to convert
Returns
uint16_t ticks count for milliseconds

◆ timer0_ticks_to_ms_usafe

#define timer0_ticks_to_ms_usafe (   ticks)    (timer_ticks_to_ms_usafe(ticks, get_timer0_clock_divider(), get_frequency_divider_scale()))

Convert ticks count to ms.

This method doesnt analyze corner cases and overflow of result. Be careful.

Parameters
ticksuint16_t ticks count
Returns
milliseconds time corresponing to timer ticks

◆ timer0_uint16_ticks_to_freq100

#define timer0_uint16_ticks_to_freq100 (   ticks)    (timer_uint16_ticks_to_freq100(ticks, get_timer0_clock_divider(), get_frequency_divider_scale()))

Convert ticks to timer frequency for timer0 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 timer0 is initialized and MCU clock frequency divider scale is set.

uint16 ticks used in mode 0, 1, 3. Low byte of ticks is used in mode 2.

Parameters
ticksuint16_t timer ticks count to covert
Returns
uint32_t frequency multiplied by 100 corresponding to ticks count

◆ timer2_ms_to_ticks_usafe

#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.

Parameters
msuint16_t ms to convert
Returns
uint16_t ticks count for milliseconds

◆ timer2_ticks_to_ms_usafe

#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.

Parameters
ticksuint16_t ticks count
Returns
milliseconds time corresponing to timer ticks