00001
00002
00003
00004
00005
00010 #ifndef _PIC24_TIMER_H_
00011 #define _PIC24_TIMER_H_
00012
00020 #define getTimerPrescale(TxCONbits) getTimerPrescaleBits(TxCONbits.TCKPS)
00021
00022 #define MS_TO_TICKS(ms, pre) ((FCY/1000L/(pre))*ms)
00023 uint16 msToU16Ticks(uint16 u16_ms, uint16 u16_pre);
00024 uint16 usToU16Ticks(uint16 u16_us, uint16 u16_pre);
00025 uint32 usToU32Ticks(uint32 u32_us, uint16 u16_pre);
00026 uint16 getTimerPrescaleBits(uint8 u8_TCKPS);
00027 uint32 ticksToMs (uint32 u32_ticks, uint16 u16_tmrPre);
00028 uint32 ticksToUs (uint32 u32_ticks, uint16 u16_tmrPre);
00029 uint32 ticksToNs (uint32 u32_ticks, uint16 u16_tmrPre);
00030 uint32 computeDeltaTicksLong(uint16 u16_start, uint16 u16_end, uint16 u16_tmrPR, uint16 u16_oflows);
00031 uint16 computeDeltaTicks(uint16 u16_start, uint16 u16_end, uint16 u16_tmrPR);
00032 int32 roundFloatToUint32(float f_x);
00033 int16 roundFloatToUint16(float f_x);
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #define T1_ON 0x8000
00048 #define T1_OFF 0x0000
00049 #define T1_OFF_ON_MASK (~T1_ON)
00050
00051 #define T1_IDLE_STOP 0x2000
00052 #define T1_IDLE_CON 0x0000
00053 #define T1_IDLE_MASK (~T1_IDLE_STOP)
00054
00055 #define T1_GATE_ON 0x0040
00056 #define T1_GATE_OFF 0x0000
00057 #define T1_GATE_MASK (~T1_GATE_ON)
00058
00059 #define T1_PS_1_1 0x0000
00060 #define T1_PS_1_8 0x0010
00061 #define T1_PS_1_64 0x0020
00062 #define T1_PS_1_256 0x0030
00063 #define T1_PS_MASK (~T1_PS_1_256)
00064
00065 #define T1_SYNC_EXT_ON 0x0004
00066 #define T1_SYNC_EXT_OFF 0x0000
00067 #define T1_SYNC_EXT_MASK (~T1_SYNC_EXT_ON)
00068
00069 #define T1_SOURCE_EXT 0x0002
00070 #define T1_SOURCE_INT 0x0000
00071 #define T1_SOURCE_MASK (~T1_SOURCE_EXT)
00072
00073 #ifdef _T2IF
00074
00075 #define T2_ON 0x8000
00076 #define T2_OFF 0x0000
00077 #define T2_OFF_ON_MASK (~T2_ON)
00078
00079 #define T2_IDLE_STOP 0x2000
00080 #define T2_IDLE_CON 0x0000
00081 #define T2_IDLE_MASK (~T2_IDLE_STOP)
00082
00083 #define T2_GATE_ON 0x0040
00084 #define T2_GATE_OFF 0x0000
00085 #define T2_GATE_MASK (~T2_GATE_ON)
00086
00087 #define T2_PS_1_1 0x0000
00088 #define T2_PS_1_8 0x0010
00089 #define T2_PS_1_64 0x0020
00090 #define T2_PS_1_256 0x0030
00091 #define T2_PS_MASK (~T2_PS_1_256)
00092
00093 #define T2_32BIT_MODE_ON 0x0008
00094 #define T2_32BIT_MODE_OFF 0x0000
00095 #define T2_32BIT_MODE_MASK (~T2_32BIT_MODE_ON)
00096
00097 #define T2_SOURCE_EXT 0x0002
00098 #define T2_SOURCE_INT 0x0000
00099 #define T2_SOURCE_MASK (~T2_SOURCE_EXT)
00100 #endif
00101
00102 #ifdef _T3IF
00103
00104 #define T3_ON 0x8000
00105 #define T3_OFF 0x0000
00106 #define T3_OFF_ON_MASK (~T3_ON)
00107
00108 #define T3_IDLE_STOP 0x2000
00109 #define T3_IDLE_CON 0x0000
00110 #define T3_IDLE_MASK (~T3_IDLE_STOP)
00111
00112 #define T3_GATE_ON 0x0040
00113 #define T3_GATE_OFF 0x0000
00114 #define T3_GATE_MASK (~T3_GATE_ON)
00115
00116 #define T3_PS_1_1 0x0000
00117 #define T3_PS_1_8 0x0010
00118 #define T3_PS_1_64 0x0020
00119 #define T3_PS_1_256 0x0030
00120 #define T3_PS_MASK (~T3_PS_1_256)
00121
00122 #define T3_SOURCE_EXT 0x0002
00123 #define T3_SOURCE_INT 0x0000
00124 #define T3_SOURCE_MASK (~T3_SOURCE_EXT)
00125 #endif
00126
00127 #ifdef _T4IF
00128
00129 #define T4_ON 0x8000
00130 #define T4_OFF 0x0000
00131 #define T4_OFF_ON_MASK (~T4_ON)
00132
00133 #define T4_IDLE_STOP 0x2000
00134 #define T4_IDLE_CON 0x0000
00135 #define T4_IDLE_MASK (~T4_IDLE_STOP)
00136
00137 #define T4_GATE_ON 0x0040
00138 #define T4_GATE_OFF 0x0000
00139 #define T4_GATE_MASK (~T4_GATE_ON)
00140
00141 #define T4_PS_1_1 0x0000
00142 #define T4_PS_1_8 0x0010
00143 #define T4_PS_1_64 0x0020
00144 #define T4_PS_1_256 0x0030
00145 #define T4_PS_MASK (~T4_PS_1_256)
00146
00147 #define T4_32BIT_MODE_ON 0x0008
00148 #define T4_32BIT_MODE_OFF 0x0000
00149 #define T4_32BIT_MODE_MASK (~T4_32BIT_MODE_ON)
00150
00151 #define T4_SOURCE_EXT 0x0002
00152 #define T4_SOURCE_INT 0x0000
00153 #define T4_SOURCE_MASK (~T4_SOURCE_EXT)
00154 #endif
00155
00156 #ifdef _T5IF
00157
00158 #define T5_ON 0x8000
00159 #define T5_OFF 0x0000
00160 #define T5_OFF_ON_MASK (~T5_ON)
00161
00162 #define T5_IDLE_STOP 0x2000
00163 #define T5_IDLE_CON 0x0000
00164 #define T5_IDLE_MASK (~T5_IDLE_STOP)
00165
00166 #define T5_GATE_ON 0x0040
00167 #define T5_GATE_OFF 0x0000
00168 #define T5_GATE_MASK (~T5_GATE_ON)
00169
00170 #define T5_PS_1_1 0x0000
00171 #define T5_PS_1_8 0x0010
00172 #define T5_PS_1_64 0x0020
00173 #define T5_PS_1_256 0x0030
00174 #define T5_PS_MASK (~T5_PS_1_256)
00175
00176 #define T5_SOURCE_EXT 0x0002
00177 #define T5_SOURCE_INT 0x0000
00178 #define T5_SOURCE_MASK (~T5_SOURCE_EXT)
00179 #endif
00180
00181 #ifdef _T6IF
00182
00183 #define T6_ON 0x8000
00184 #define T6_OFF 0x0000
00185 #define T6_OFF_ON_MASK (~T6_ON)
00186
00187 #define T6_IDLE_STOP 0x2000
00188 #define T6_IDLE_CON 0x0000
00189 #define T6_IDLE_MASK (~T6_IDLE_STOP)
00190
00191 #define T6_GATE_ON 0x0040
00192 #define T6_GATE_OFF 0x0000
00193 #define T6_GATE_MASK (~T6_GATE_ON)
00194
00195 #define T6_PS_1_1 0x0000
00196 #define T6_PS_1_8 0x0010
00197 #define T6_PS_1_64 0x0020
00198 #define T6_PS_1_256 0x0030
00199 #define T6_PS_MASK (~T6_PS_1_256)
00200
00201 #define T6_32BIT_MODE_ON 0x0008
00202 #define T6_32BIT_MODE_OFF 0x0000
00203 #define T6_32BIT_MODE_MASK (~T6_32BIT_MODE_ON)
00204
00205 #define T6_SOURCE_EXT 0x0002
00206 #define T6_SOURCE_INT 0x0000
00207 #define T6_SOURCE_MASK (~T6_SOURCE_EXT)
00208 #endif
00209
00210 #ifdef _T7IF
00211
00212 #define T7_ON 0x8000
00213 #define T7_OFF 0x0000
00214 #define T7_OFF_ON_MASK (~T7_ON)
00215
00216 #define T7_IDLE_STOP 0x2000
00217 #define T7_IDLE_CON 0x0000
00218 #define T7_IDLE_MASK (~T7_IDLE_STOP)
00219
00220 #define T7_GATE_ON 0x0040
00221 #define T7_GATE_OFF 0x0000
00222 #define T7_GATE_MASK (~T7_GATE_ON)
00223
00224 #define T7_PS_1_1 0x0000
00225 #define T7_PS_1_8 0x0010
00226 #define T7_PS_1_64 0x0020
00227 #define T7_PS_1_256 0x0030
00228 #define T7_PS_MASK (~T7_PS_1_256)
00229
00230 #define T7_SOURCE_EXT 0x0002
00231 #define T7_SOURCE_INT 0x0000
00232 #define T7_SOURCE_MASK (~T7_SOURCE_EXT)
00233 #endif
00234
00235 #ifdef _T8IF
00236
00237 #define T8_ON 0x8000
00238 #define T8_OFF 0x0000
00239 #define T8_OFF_ON_MASK (~T8_ON)
00240
00241 #define T8_IDLE_STOP 0x2000
00242 #define T8_IDLE_CON 0x0000
00243 #define T8_IDLE_MASK (~T8_IDLE_STOP)
00244
00245 #define T8_GATE_ON 0x0040
00246 #define T8_GATE_OFF 0x0000
00247 #define T8_GATE_MASK (~T8_GATE_ON)
00248
00249 #define T8_PS_1_1 0x0000
00250 #define T8_PS_1_8 0x0010
00251 #define T8_PS_1_64 0x0020
00252 #define T8_PS_1_256 0x0030
00253 #define T8_PS_MASK (~T8_PS_1_256)
00254
00255 #define T8_32BIT_MODE_ON 0x0008
00256 #define T8_32BIT_MODE_OFF 0x0000
00257 #define T8_32BIT_MODE_MASK (~T8_32BIT_MODE_ON)
00258
00259 #define T8_SOURCE_EXT 0x0002
00260 #define T8_SOURCE_INT 0x0000
00261 #define T8_SOURCE_MASK (~T8_SOURCE_EXT)
00262 #endif
00263
00264 #ifdef _T9IF
00265
00266 #define T9_ON 0x8000
00267 #define T9_OFF 0x0000
00268 #define T9_OFF_ON_MASK (~T9_ON)
00269
00270 #define T9_IDLE_STOP 0x2000
00271 #define T9_IDLE_CON 0x0000
00272 #define T9_IDLE_MASK (~T9_IDLE_STOP)
00273
00274 #define T9_GATE_ON 0x0040
00275 #define T9_GATE_OFF 0x0000
00276 #define T9_GATE_MASK (~T9_GATE_ON)
00277
00278 #define T9_PS_1_1 0x0000
00279 #define T9_PS_1_8 0x0010
00280 #define T9_PS_1_64 0x0020
00281 #define T9_PS_1_256 0x0030
00282 #define T9_PS_MASK (~T9_PS_1_256)
00283
00284 #define T9_SOURCE_EXT 0x0002
00285 #define T9_SOURCE_INT 0x0000
00286 #define T9_SOURCE_MASK (~T9_SOURCE_EXT)
00287 #endif
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 #define IC_IDLE_STOP 0x2000
00300 #define IC_IDLE_CON 0x0000
00301 #define IC_IDLE_MASK (~IC_IDLE_STOP)
00302
00303 #define IC_TIMER2_SRC 0x0080
00304 #define IC_TIMER3_SRC 0x0000
00305 #define IC_TIMER_SRC_MASK (~IC_TIMER2_SRC)
00306
00307 #define IC_INT_4CAPTURE 0x0060
00308 #define IC_INT_3CAPTURE 0x0040
00309 #define IC_INT_2CAPTURE 0x0020
00310 #define IC_INT_1CAPTURE 0x0000
00311 #define IC_INT_CAPTURE_MASK (~IC_INT_4CAPTURE)
00312
00313 #define IC_INTERRUPT 0x0007
00314 #define IC_EVERY_16_RISE_EDGE 0x0005
00315 #define IC_EVERY_4_RISE_EDGE 0x0004
00316 #define IC_EVERY_RISE_EDGE 0x0003
00317 #define IC_EVERY_FALL_EDGE 0x0002
00318 #define IC_EVERY_EDGE 0x0001
00319 #define IC_INPUTCAP_OFF 0x0000
00320 #define IC_CAPTURE_MODE_MASK (~IC_INTERRUPT)
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 #define OC_IDLE_CON 0x0000
00334 #define OC_IDLE_STOP 0x2000
00335 #define OC_IDLE_MASK (~OC_IDLE_STOP)
00336
00337
00338 #define OC_TIMER2_SRC 0x0000
00339 #define OC_TIMER3_SRC 0x0008
00340 #define OC_TIMER_SRC_MASK (~OC_TIMER3_SRC)
00341
00342 #define OC_PWM_FAULT_PIN_ENABLE 0x0007
00343 #define OC_PWM_FAULT_PIN_DISABLE 0x0006
00344 #define OC_CONTINUE_PULSE 0x0005
00345 #define OC_SINGLE_PULSE 0x0004
00346 #define OC_TOGGLE_PULSE 0x0003
00347 #define OC_HIGH_LOW 0x0002
00348 #define OC_LOW_HIGH 0x0001
00349 #define OC_OFF 0x0000
00350 #define OC_PWM_MODE_MASK (~OC_PWM_FAULT_PIN_ENABLE)
00351
00352
00353 #endif
00354