This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:software:homelab:library:timer [2010/02/08 12:52] – mikk.leini | en:software:homelab:library:timer [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Timers ====== | ====== Timers ====== | ||
- | Käesolev taimerite teek katab suure osa ATmega128 | + | This library covers a large part of the functionality of ATmega128 |
- | ===== Andmetüübid | + | ===== Data types ===== |
- | * **// | + | * **// |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * **// | + | * **// |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
* **// | * **// | ||
- | * **// | + | * **// |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
* **// | * **// | ||
- | * **// | + | * **// |
- | * // | + | * // |
- | * // | + | * // |
* **// | * **// | ||
- | * **// | + | * **// |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
* **// | * **// | ||
- | * **// | + | * **// |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | * // | + | * // |
- | ===== Funktsioonid | + | ===== Functions |
- | * **//void timer0_init_normal(timer0_prescale prescale)// | + | * **//void timer0_init_normal(timer0_prescale prescale)// |
- | * // | + | Initializes timer 0 in normal mode. In this mode the timer counts from 0 to 255 (including). Overflow interrupt can be used. Parameters: |
+ | * // | ||
- | * **//void timer2_init_normal(timer2_prescale prescale)// | + | * **//void timer2_init_normal(timer2_prescale prescale)// |
- | * // | + | Initializes timer 2 in normal mode. In this mode timer counts from 0 to 255 (including). Overflow interrupt can be used. Parameters: |
+ | * // | ||
* **//void timer0_stop()// | * **//void timer0_stop()// | ||
- | * **//void timer2_stop()// | + | * **//void timer2_stop()// |
+ | Stops timer 0/2. | ||
* **// | * **// | ||
- | * **// | + | * **// |
- | * Tagastab | + | Returns timer 0/2 current value. Parameters: |
+ | * Return | ||
* **//void timer0_set_value(unsigned char value)//** | * **//void timer0_set_value(unsigned char value)//** | ||
- | * **//void timer2_set_value(unsigned char value)//** \\ Taimer | + | * **//void timer2_set_value(unsigned char value)//** \\ |
- | * //value// - Uus 8-bitine loenduri väärtus. | + | Sets timer 0/2 value. Parameters: |
+ | * //value// - New 8-bit timer value. | ||
* **//void timer0_overflow_interrupt_enable(bool enable)//** | * **//void timer0_overflow_interrupt_enable(bool enable)//** | ||
- | * **//void timer2_overflow_interrupt_enable(bool enable)//** \\ Taimer | + | * **//void timer2_overflow_interrupt_enable(bool enable)//** \\ |
- | * //enable// - Tõeväärtus katkestuse lubamiseks või keelamiseks. | + | Enables or disables timer 0/2 overflow interrupt. The name of the interrupt vector is "TIMERn_OVF_vect" where " |
+ | * //enable// - // | ||
* **//bool timer0_overflow_flag_is_set(void)// | * **//bool timer0_overflow_flag_is_set(void)// | ||
- | * **//bool timer2_overflow_flag_is_set(void)// | + | * **//bool timer2_overflow_flag_is_set(void)// |
- | * Tagastab tõeväärtuse | + | Checks timer 0/2 overflow flag. Parameters: |
+ | * Returns | ||
* **//void timer0_overflow_flag_clear(void)// | * **//void timer0_overflow_flag_clear(void)// | ||
- | * **//void timer2_overflow_flag_clear(void)// | + | * **//void timer2_overflow_flag_clear(void)// |
+ | Resets timer 0/2 overflow flag. | ||
* **//void timer1_init_normal(timer1_prescale prescale)// | * **//void timer1_init_normal(timer1_prescale prescale)// | ||
- | * **//void timer3_init_normal(timer3_prescale prescale)// | + | * **//void timer3_init_normal(timer3_prescale prescale)// |
- | * // | + | Initializes timer 1/3 in normal mode. In this mode timer counts from 0 to 65535 (including). Overflow interrupt can be used. Parameters: |
+ | * // | ||
* **//void timer1_init_ctc(timer1_prescale prescale, timer1_ctc_top top)//** | * **//void timer1_init_ctc(timer1_prescale prescale, timer1_ctc_top top)//** | ||
- | * **//void timer3_init_ctc(timer3_prescale prescale, timer3_ctc_top top)//** \\ Taimer | + | * **//void timer3_init_ctc(timer3_prescale prescale, timer3_ctc_top top)//** \\ |
- | * // | + | Initializes timer 1/3 in CTC (//Clear Timer on Compare Match// |
- | * //top// - Taimeri maksimaalse väärtuse registri valik. Valida saab kahe registri vahel, mille mõlema muutmiseks on omaette funktsioonid. Mõlemad registrid võib loenduri tippu jõudes katkestust tekitama seadistada. | + | * // |
+ | * //top// - Timer top value selection. Actual value must be specified with register selected as a top value holder. | ||
* **//void timer1_init_fast_pwm(timer1_prescale prescale, timer1_fast_pwm_top top, timer1_fast_pwm_output_mode output_a, timer1_fast_pwm_output_mode output_b, timer1_fast_pwm_output_mode output_c)// | * **//void timer1_init_fast_pwm(timer1_prescale prescale, timer1_fast_pwm_top top, timer1_fast_pwm_output_mode output_a, timer1_fast_pwm_output_mode output_b, timer1_fast_pwm_output_mode output_c)// | ||
- | * **//void timer3_init_fast_pwm(timer3_prescale prescale, timer3_fast_pwm_top top, timer3_fast_pwm_output_mode output_a, timer3_fast_pwm_output_mode output_b, timer3_fast_pwm_output_mode output_c)// | + | * **//void timer3_init_fast_pwm(timer3_prescale prescale, timer3_fast_pwm_top top, timer3_fast_pwm_output_mode output_a, timer3_fast_pwm_output_mode output_b, timer3_fast_pwm_output_mode output_c)// |
- | * // | + | Initializises timer 1/3 in fast PWM mode. In this mode timer counts to a specified value, which also determines the period of the PWM signal. Timer 1/3 has three 3 output compare units (A, B and C) to generate PWM signals. Overflow and compare match interrupts can be used. Parameters: |
- | * //top// - Taimeri maksimaalse väärtuse valik. Valida saab konstantide ja kahe registri vahel. Mõlemad registrid võib loenduri tippu jõudes katkestust tekitama seadistada. | + | * // |
- | * // | + | * //top// - Timer top value selection. Actual value must be specified with register selected as a top value holder. |
- | * // | + | * // |
- | * // | + | * // |
+ | * // | ||
* **//void timer1_stop()// | * **//void timer1_stop()// | ||
- | * **//void timer3_stop()// | + | * **//void timer3_stop()// |
+ | Stops timer 1/3. | ||
* **// | * **// | ||
- | * **// | + | * **// |
- | * Tagastab | + | Returns timer 1/3 current value. Parameters: |
+ | * Returns | ||
* **//void timer1_set_value(unsigned char value)//** | * **//void timer1_set_value(unsigned char value)//** | ||
- | * **//void timer3_set_value(unsigned char value)//** \\ Taimeri 1/3 loenduri uue väärtuse määramine. Parameetrid: | + | * **//void timer3_set_value(unsigned char value)//** \\ |
- | * //value// - Uus 16-bitine loenduri väärtus. | + | Sets timer 0/2 value. Parameters: |
+ | * //value// - New 16-bit timer value. | ||
* **// | * **// | ||
Line 116: | Line 130: | ||
* **// | * **// | ||
* **// | * **// | ||
- | * **// | + | * **// |
- | * Tagastab | + | |
+ | * Returns | ||
* **//void timer1_set_compare_match_unitA_value(unsigned short value)//** | * **//void timer1_set_compare_match_unitA_value(unsigned short value)//** | ||
Line 124: | Line 139: | ||
* **//void timer3_set_compare_match_unitA_value(unsigned short value)//** | * **//void timer3_set_compare_match_unitA_value(unsigned short value)//** | ||
* **//void timer3_set_compare_match_unitB_value(unsigned short value)//** | * **//void timer3_set_compare_match_unitB_value(unsigned short value)//** | ||
- | * **//void timer3_set_compare_match_unitC_value(unsigned short value)//** \\ Taimeri | + | * **//void timer3_set_compare_match_unitC_value(unsigned short value)//** \\ |
- | * //value// - Uus 16-bitine võrdlusväärtus. | + | Sets timer 1/3 output compare unit A/B/C compare match register value. Parameters: |
+ | * //value// - New 16-bit compare match register value. | ||
* **// | * **// | ||
- | * **// | + | * **// |
- | * Tagastab | + | Returns timer 1/3 input capture register value. Parameters: |
+ | * Returns | ||
* **//void timer1_set_input_capture_value(unsigned short value)//** | * **//void timer1_set_input_capture_value(unsigned short value)//** | ||
- | * **//void timer3_set_input_capture_value(unsigned short value)//** \\ Taimer | + | * **//void timer3_set_input_capture_value(unsigned short value)//** \\ |
- | * //value// - Uus 16-bitine sündmuste loenduri väärtus. | + | Sets timer 1/3 input capture register value. Parameters: |
+ | * //value// - New 16-bit input capture register value. | ||
* **//void timer1_overflow_interrupt_enable(bool enable)//** | * **//void timer1_overflow_interrupt_enable(bool enable)//** | ||
- | * **//void timer3_overflow_interrupt_enable(bool enable)//** \\ Taimer | + | * **//void timer3_overflow_interrupt_enable(bool enable)//** \\ |
- | * //enable// - Tõeväärtus katkestuse lubamiseks või keelamiseks. | + | Enables or disables timer 1/3 overflow interrupt. The name of the interrupt vector is "TIMERn_OVF_vect" where " |
+ | * //enable// - // | ||
* **//void timer1_compare_match_unitA_interrupt_enable(bool enable)//** | * **//void timer1_compare_match_unitA_interrupt_enable(bool enable)//** | ||
Line 144: | Line 163: | ||
* **//void timer3_compare_match_unitA_interrupt_enable(bool enable)//** | * **//void timer3_compare_match_unitA_interrupt_enable(bool enable)//** | ||
* **//void timer3_compare_match_unitB_interrupt_enable(bool enable)//** | * **//void timer3_compare_match_unitB_interrupt_enable(bool enable)//** | ||
- | * **//void timer3_compare_match_unitC_interrupt_enable(bool enable)//** \\ Taimer | + | * **//void timer3_compare_match_unitC_interrupt_enable(bool enable)//** \\ |
- | * //enable// - Tõeväärtus katkestuse lubamiseks või keelamiseks. | + | |
+ | * //enable// - // | ||
* **//void timer1_input_capture_interrupt_enable(bool enable)//** | * **//void timer1_input_capture_interrupt_enable(bool enable)//** | ||
- | * **//void timer3_input_capture_interrupt_enable(bool enable)//** \\ Taimer | + | * **//void timer3_input_capture_interrupt_enable(bool enable)//** \\ |
- | * //enable// - Tõeväärtus katkestuse lubamiseks või keelamiseks. | + | Enables or disables timer 1/3 input capture interrupt. The name of the interrupt vector is "TIMERn_CAPT_vect", where " |
+ | * //enable// - // | ||
* **//bool timer1_overflow_flag_is_set(void)// | * **//bool timer1_overflow_flag_is_set(void)// | ||
- | * **//bool timer3_overflow_flag_is_set(void)// | + | * **//bool timer3_overflow_flag_is_set(void)// |
- | * Tagastab tõeväärtuse | + | Checks timer 1/3 overflow flag. Parameters: |
+ | * Returns | ||
* **//bool timer1_input_capture_flag_is_set(void)// | * **//bool timer1_input_capture_flag_is_set(void)// | ||
- | * **//bool timer3_input_capture_flag_is_set(void)// | + | * **//bool timer3_input_capture_flag_is_set(void)// |
- | * Tagastab tõeväärtuse | + | Checks timer 1/3 input capture flag. Parameters: |
+ | * Returns | ||
* **//void timer1_overflow_flag_clear(void)// | * **//void timer1_overflow_flag_clear(void)// | ||
- | * **//void timer3_overflow_flag_clear(void)// | + | * **//void timer3_overflow_flag_clear(void)// |
+ | Resets timer 1/3 overflow flag. | ||
* **//void timer1_input_capture_flag_clear(void)// | * **//void timer1_input_capture_flag_clear(void)// | ||
- | * **//void timer3_input_capture_flag_clear(void)// | + | * **//void timer3_input_capture_flag_clear(void)// |
+ | Resets timer 1/3 input capture flag. | ||
- | ===== Näide | + | ===== Example |
- | Näites seadistatakse taimer | + | In the following program timer 0 is started in normal mode with overflow interrupt. |
<code c> | <code c> | ||
Line 173: | Line 198: | ||
#include < | #include < | ||
- | // Katkestuse programmilõik | + | // Overflow interrupt program. |
ISR(TIMER0_OVF_vect) | ISR(TIMER0_OVF_vect) | ||
{ | { | ||
Line 180: | Line 205: | ||
int main(void) | int main(void) | ||
{ | { | ||
- | // Taimer | + | // Initializing of timer 0 in normal mode. |
timer0_init_normal(TIMER0_PRESCALE_32); | timer0_init_normal(TIMER0_PRESCALE_32); | ||
- | // Taimer | + | // Enabling timer 0 overflow interrupt. |
timer0_overflow_interrupt_enable(true); | timer0_overflow_interrupt_enable(true); | ||
- | // Globaalne katkestuse lubamine | + | // Global interrupts enabling. |
sei(); | sei(); | ||
} | } | ||
</ | </ |