00001
00022
00023
00024 #ifndef _TIMER16_DRV_H_
00025 #define _TIMER16_DRV_H_
00026
00027
00028
00029 #include "config.h"
00030
00031
00032
00033
00034
00035
00036
00037 #define Timer16_get_counter() ( timer16_get_counter() ) // c.f. "timer16_drv.c" file
00038 #define Timer16_get_capture() ( timer16_get_capture() ) // c.f. "timer16_drv.c" file
00039
00040 #define Timer16_set_pwm_a(value) ( Timer16_set_compare_a(value) ) // c.f. above !
00041 #define Timer16_set_pwm_b(value) ( Timer16_set_compare_b(value) ) // c.f. above !
00042 #define Timer16_set_pwm_c(value) ( Timer16_set_compare_c(value) ) // c.f. above !
00043 #define Timer16_get_pwm_a() ( Timer16_get_compare_a() ) // c.f. above !
00044 #define Timer16_get_pwm_b() ( Timer16_get_compare_b() ) // c.f. above !
00045 #define Timer16_get_pwm_c() ( Timer16_get_compare_c() ) // c.f. above !
00046
00047 #define Timer16_off() Timer16_set_clock(TIMER16_NO_CLOCK)
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 # define Timer16_select(timer16_num) __no_operation() // for compatibility with MCU with 2 timers
00069
00070 # define Timer16_clear() ( TCCR1B=0, TCCR1A=0, TCCR1C=0, TCNT1H=0, TCNT1L= 0, OCR1AH=0, OCR1AL=0, \
00071 OCR1BH=0, OCR1BL=0, OCR1CH=0, OCR1CL=0, ICR1H=0, ICR1L=0 )
00072
00073 # define Timer16_set_counter(value) ( TCNT1H = ((U8)(value>>8)), TCNT1L = ((U8)(value)))
00074 # define Timer16_get_counter_low() ((U16)(TCNT1L))
00075 # define Timer16_get_counter_high() ((U16)(TCNT1H))
00076
00077 # define Timer16_set_compare_a(value) ( OCR1AH = ((U8)(value>>8)), OCR1AL = ((U8)(value)))
00078 # define Timer16_set_compare_b(value) ( OCR1BH = ((U8)(value>>8)), OCR1BL = ((U8)(value)))
00079 # define Timer16_set_compare_c(value) ( OCR1CH = ((U8)(value>>8)), OCR1CL = ((U8)(value)))
00080 # define Timer16_get_compare_a() ( OCR1A ) // The temporary register is not used
00081 # define Timer16_get_compare_b() ( OCR1B ) // The temporary register is not used
00082 # define Timer16_get_compare_c() ( OCR1C ) // The temporary register is not used
00083
00084 # define Timer16_set_capture(value) ( ICR1H = ((U8)(value>>8)), ICR1L = ((U8)(value)) )
00085 # define Timer16_get_capture_low() ((U16)(ICR1L))
00086 # define Timer16_get_capture_high() ((U16)(ICR1H))
00087
00088 # define Timer16_set_mode_output_a(conf) ( TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_A)) | (conf << COM1A0) )
00089 # define Timer16_set_mode_output_b(conf) ( TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_B)) | (conf << COM1B0) )
00090 # define Timer16_set_mode_output_c(conf) ( TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_C)) | (conf << COM1C0) )
00091 # define Timer16_get_mode_output_a() ((TCCR1A & TIMER16_COMP_MODE_MASK_A) >> COM1A0 )
00092 # define Timer16_get_mode_output_b() ((TCCR1A & TIMER16_COMP_MODE_MASK_B) >> COM1B0 )
00093 # define Timer16_get_mode_output_c() ((TCCR1A & TIMER16_COMP_MODE_MASK_C) >> COM1C0 )
00094
00095 # define Timer16_set_waveform_mode(conf) ( TCCR1A = (TCCR1A & (~TIMER16_WGM_RA_MASK)) | ((conf & 0x3) << WGM10), \
00096 TCCR1B = (TCCR1B & (~TIMER16_WGM_RB_MASK)) | ((conf >> 0x2) << WGM12) )
00097 # define Timer16_get_waveform_mode() (((TCCR1A & TIMER16_WGM_RA_MASK) >> WGM10) | \
00098 (((TCCR1B & TIMER16_WGM_RB_MASK) >> WGM12) << 0x2) )
00099
00100 # define Timer16_set_clock(value) ( TCCR1B = (TCCR1B & (~TIMER16_CLK_MASK)) | (value << CS10) )
00101 # define Timer16_get_clock() (((TCCR1B & TIMER16_CLK_MASK) >> CS10) )
00102
00103 # define Timer16_set_input_filter() ( TCCR1B |= (1<<ICNC1) )
00104 # define Timer16_clear_input_filter() ( TCCR1B &= ~(1<<ICNC1) )
00105 # define Timer16_get_input_filter() ((TCCR1B & (1<<ICNC1)) >> ICNC1 )
00106
00107 # define Timer16_set_input_rising_edge() ( TCCR1B |= (1<<ICES1) )
00108 # define Timer16_set_input_falling_edge()( TCCR1B &= ~(1<<ICES1) )
00109 # define Timer16_get_input_capture_edge()((TCCR1B & (1<<ICES1)) >> ICES1 )
00110
00111 # define Timer16_set_compare_force_a() ( TCCR1C |= (1<<FOC1A) )
00112 # define Timer16_set_compare_force_b() ( TCCR1C |= (1<<FOC1B) )
00113 # define Timer16_set_compare_force_c() ( TCCR1C |= (1<<FOC1C) )
00114 # define Timer16_clear_compare_force_a() ( TCCR1C &= ~(1<<FOC1A) )
00115 # define Timer16_clear_compare_force_b() ( TCCR1C &= ~(1<<FOC1B) )
00116 # define Timer16_clear_compare_force_c() ( TCCR1C &= ~(1<<FOC1C) )
00117 # define Timer16_get_compare_force_a() ((TCCR1C & (1<<FOC1A)) >> FOC1A )
00118 # define Timer16_get_compare_force_b() ((TCCR1C & (1<<FOC1B)) >> FOC1B )
00119 # define Timer16_get_compare_force_c() ((TCCR1C & (1<<FOC1C)) >> FOC1C )
00120
00121 # define Timer16_overflow_it_enable() ( TIMSK1 |= (1<<TOIE1) )
00122 # define Timer16_overflow_it_disable() ( TIMSK1 &= ~(1<<TOIE1) )
00123 # define Timer16_compare_a_it_enable() ( TIMSK1 |= (1<<OCIE1A) )
00124 # define Timer16_compare_a_it_disable() ( TIMSK1 &= ~(1<<OCIE1A) )
00125 # define Timer16_compare_b_it_enable() ( TIMSK1 |= (1<<OCIE1B) )
00126 # define Timer16_compare_b_it_disable() ( TIMSK1 &= ~(1<<OCIE1B) )
00127 # define Timer16_compare_c_it_enable() ( TIMSK1 |= (1<<OCIE1C) )
00128 # define Timer16_compare_c_it_disable() ( TIMSK1 &= ~(1<<OCIE1C) )
00129 # define Timer16_capture_it_enable() ( TIMSK1 |= (1<<ICIE1) )
00130 # define Timer16_capture_it_disable() ( TIMSK1 &= ~(1<<ICIE1) )
00131 # define Timer16_get_overflow_it_mask() ((TIMSK1 & (1<<TOIE1) ) >> TOIE1 )
00132 # define Timer16_get_compare_a_it_mask() ((TIMSK1 & (1<<OCIE1A)) >> OCIE1A )
00133 # define Timer16_get_compare_b_it_mask() ((TIMSK1 & (1<<OCIE1B)) >> OCIE1B )
00134 # define Timer16_get_compare_c_it_mask() ((TIMSK1 & (1<<OCIE1C)) >> OCIE1C )
00135 # define Timer16_get_capture_it_mask() ((TIMSK1 & (1<<ICIE1) ) >> ICIE1 )
00136
00137 # define Timer16_clear_overflow_it() ( TIFR1 |= (1<<TOV1) )
00138 # define Timer16_clear_compare_a_it() ( TIFR1 |= (1<<OCF1A) )
00139 # define Timer16_clear_compare_b_it() ( TIFR1 |= (1<<OCF1B) )
00140 # define Timer16_clear_compare_c_it() ( TIFR1 |= (1<<OCF1C) )
00141 # define Timer16_clear_capture_it() ( TIFR1 |= (1<<ICF1) )
00142 # define Timer16_get_overflow_it() ((TIFR1 & (1<<TOV1) ) >> TOV1 )
00143 # define Timer16_get_compare_a_it() ((TIFR1 & (1<<OCF1A)) >> OCF1A )
00144 # define Timer16_get_compare_b_it() ((TIFR1 & (1<<OCF1B)) >> OCF1B )
00145 # define Timer16_get_compare_c_it() ((TIFR1 & (1<<OCF1C)) >> OCF1C )
00146 # define Timer16_get_capture_it() ((TIFR1 & (1<<ICF1) ) >> ICF1 )
00147
00148
00149
00150
00151
00152 #define TIMER16_COMP_MODE_NORMAL (0)
00153 #define TIMER16_COMP_MODE_TOGGLE (1)
00154 #define TIMER16_COMP_MODE_CLEAR_OC (2)
00155 #define TIMER16_COMP_MODE_SET_OC (3)
00156 #define TIMER16_COMP_MODE_MASK_A (3<<COM1A0)
00157 #define TIMER16_COMP_MODE_MASK_B (3<<COM1B0)
00158 #define TIMER16_COMP_MODE_MASK_C (3<<COM1C0)
00159
00160 #define TIMER16_WGM_NORMAL (0)
00161 #define TIMER16_WGM_CTC_OCR (4)
00162 #define TIMER16_WGM_CTC_ICR (12)
00163 #define TIMER16_WGM_PWM_PC8 (1)
00164 #define TIMER16_WGM_PWM_PC9 (2)
00165 #define TIMER16_WGM_PWM_PC10 (3)
00166 #define TIMER16_WGM_PWM_PC_ICR (10)
00167 #define TIMER16_WGM_PWM_PC_OCR (11)
00168 #define TIMER16_WGM_PWM_PFC_ICR (8)
00169 #define TIMER16_WGM_PWM_PFC_OCR (9)
00170 #define TIMER16_WGM_FAST_PWM8 (5)
00171 #define TIMER16_WGM_FAST_PWM9 (6)
00172 #define TIMER16_WGM_FAST_PWM10 (7)
00173 #define TIMER16_WGM_FAST_PWM_ICR (14)
00174 #define TIMER16_WGM_FAST_PWM_OCR (15)
00175 #define TIMER16_WGM_RA_MASK (3<<WGM10)
00176 #define TIMER16_WGM_RB_MASK (3<<WGM12)
00177
00178 #define TIMER16_NO_CLOCK (0)
00179 #define TIMER16_CLKIO_BY_1 (1)
00180 #define TIMER16_CLKIO_BY_8 (2)
00181 #define TIMER16_CLKIO_BY_64 (3)
00182 #define TIMER16_CLKIO_BY_256 (4)
00183 #define TIMER16_CLKIO_BY_1024 (5)
00184 #define TIMER16_EXT_CLOCK_FALLING_EDGE (6)
00185 #define TIMER16_EXT_CLOCK_RISING_EDGE (7)
00186 #define TIMER16_CLK_MASK (7<<CS10)
00187
00188
00189
00190
00191
00192
00202 extern U16 timer16_get_counter(void);
00203
00204
00205
00215 extern U16 timer16_get_capture(void);
00216
00217
00218
00219 #endif // _TIMER16_DRV_H_
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249