PIC24 Support Libraries
pic24_timer.h
Go to the documentation of this file.
1 /* Standard copyright does not go in this file because
2 * of the use of Microchip provided macros, see comments below.
3 */
4 // Documentation for this file. If the \file tag isn't present,
5 // this file won't be documented.
6 /** \file
7  * To do.
8  */
9 
10 #pragma once
11 
12 #include <stdint.h>
13 #include "pic24_chip.h"
14 #include "pic24_clockfreq.h"
15 
16 /** Given the TxCON register as a bitfield, determines the prescale
17  * based on the TCKPS bitfield. Works for PIC24H, PIC24F timers.
18  * Simply accesses the TCKPS bitfield then calls
19  * \ref getTimerPrescaleBits with the bitfield.
20  * \param TxCONbits The TxCONbits for the timer in question
21  * \return Prescale value.
22  */
23 #define getTimerPrescale(TxCONbits) getTimerPrescaleBits(TxCONbits.TCKPS)
24 
25 #define MS_TO_TICKS(ms, pre) ((FCY/1000L/(pre))*(ms))
26 
27 #ifndef _NOFLOAT
28 uint16_t msToU16Ticks(uint16_t u16_ms, uint16_t u16_pre);
29 uint16_t usToU16Ticks(uint16_t u16_us, uint16_t u16_pre);
30 uint32_t usToU32Ticks(uint32_t u32_us, uint16_t u16_pre);
31 uint32_t ticksToMs (uint32_t u32_ticks, uint16_t u16_tmrPre);
32 uint32_t ticksToUs (uint32_t u32_ticks, uint16_t u16_tmrPre);
33 uint32_t ticksToNs (uint32_t u32_ticks, uint16_t u16_tmrPre);
34 #endif
35 uint16_t getTimerPrescaleBits(uint8_t u8_TCKPS);
36 uint32_t computeDeltaTicksLong(uint16_t u16_start, uint16_t u16_end, uint16_t u16_tmrPR, uint16_t u16_oflows);
37 uint16_t computeDeltaTicks(uint16_t u16_start, uint16_t u16_end, uint16_t u16_tmrPR);
38 
39 /*
40 The following macros are a subset of the AND/OR macros found in the
41 the MPLAB C30/src/peripheral_24F/timer.h file and placed
42 in this header for use solely and exclusively on Microchip
43 PICmicro Microcontroller products as
44 specified in the MPLAB C30/src/peripheral_24F/timer.h header.
45 
46 Edits have been made in the comments to correct some
47 minor typos.
48 */
49 
50 /* T1CON: TIMER1 CONTROL REGISTER */
51 #define T1_ON 0x8000 /* Timer1 ON */
52 #define T1_OFF 0x0000 /* Timer1 OFF */
53 #define T1_OFF_ON_MASK (~T1_ON)
54 
55 #define T1_IDLE_STOP 0x2000 /* stop operation during sleep */
56 #define T1_IDLE_CON 0x0000 /* operate during sleep */
57 #define T1_IDLE_MASK (~T1_IDLE_STOP)
58 
59 #define T1_GATE_ON 0x0040 /* Timer Gate time accumulation enabled */
60 #define T1_GATE_OFF 0x0000 /* Timer Gate time accumulation disabled */
61 #define T1_GATE_MASK (~T1_GATE_ON)
62 
63 #define T1_PS_1_1 0x0000 /* Prescaler 1:1 */
64 #define T1_PS_1_8 0x0010 /* 1:8 */
65 #define T1_PS_1_64 0x0020 /* 1:64 */
66 #define T1_PS_1_256 0x0030 /* 1:256 */
67 #define T1_PS_MASK (~T1_PS_1_256)
68 
69 #define T1_SYNC_EXT_ON 0x0004 /* Synch external clk input */
70 #define T1_SYNC_EXT_OFF 0x0000 /* Do not synch external clk input */
71 #define T1_SYNC_EXT_MASK (~T1_SYNC_EXT_ON)
72 
73 #define T1_SOURCE_EXT 0x0002 /* External clock source */
74 #define T1_SOURCE_INT 0x0000 /* Internal clock source */
75 #define T1_SOURCE_MASK (~T1_SOURCE_EXT)
76 
77 #ifdef _T2IF
78 /* T2CON: TIMER2 CONTROL REGISTER */
79 #define T2_ON 0x8000 /* Timer2 ON */
80 #define T2_OFF 0x0000 /* Timer2 OFF */
81 #define T2_OFF_ON_MASK (~T2_ON)
82 
83 #define T2_IDLE_STOP 0x2000 /* stop operation during sleep */
84 #define T2_IDLE_CON 0x0000 /* operate during sleep */
85 #define T2_IDLE_MASK (~T2_IDLE_STOP)
86 
87 #define T2_GATE_ON 0x0040 /* Timer Gate time accumulation enabled */
88 #define T2_GATE_OFF 0x0000 /* Timer Gate time accumulation disabled */
89 #define T2_GATE_MASK (~T2_GATE_ON)
90 
91 #define T2_PS_1_1 0x0000 /* Prescaler 1:1 */
92 #define T2_PS_1_8 0x0010 /* 1:8 */
93 #define T2_PS_1_64 0x0020 /* 1:64 */
94 #define T2_PS_1_256 0x0030 /* 1:256 */
95 #define T2_PS_MASK (~T2_PS_1_256)
96 
97 #define T2_32BIT_MODE_ON 0x0008 /* Timer 2 and Timer 3 form a 32 bit Timer */
98 #define T2_32BIT_MODE_OFF 0x0000
99 #define T2_32BIT_MODE_MASK (~T2_32BIT_MODE_ON)
100 
101 #define T2_SOURCE_EXT 0x0002 /* External clock source */
102 #define T2_SOURCE_INT 0x0000 /* Internal clock source */
103 #define T2_SOURCE_MASK (~T2_SOURCE_EXT)
104 #endif
105 
106 #ifdef _T3IF
107 /* T3CON: TIMER3 CONTROL REGISTER */
108 #define T3_ON 0x8000 /* Timer3 ON */
109 #define T3_OFF 0x0000 /* Timer3 OFF */
110 #define T3_OFF_ON_MASK (~T3_ON)
111 
112 #define T3_IDLE_STOP 0x2000 /* operate during sleep */
113 #define T3_IDLE_CON 0x0000 /* stop operation during sleep */
114 #define T3_IDLE_MASK (~T3_IDLE_STOP)
115 
116 #define T3_GATE_ON 0x0040 /* Timer Gate time accumulation enabled */
117 #define T3_GATE_OFF 0x0000 /* Timer Gate time accumulation disabled */
118 #define T3_GATE_MASK (~T3_GATE_ON)
119 
120 #define T3_PS_1_1 0x0000 /* Prescaler 1:1 */
121 #define T3_PS_1_8 0x0010 /* 1:8 */
122 #define T3_PS_1_64 0x0020 /* 1:64 */
123 #define T3_PS_1_256 0x0030 /* 1:256 */
124 #define T3_PS_MASK (~T3_PS_1_256)
125 
126 #define T3_SOURCE_EXT 0x0002 /* External clock source */
127 #define T3_SOURCE_INT 0x0000 /* Internal clock source */
128 #define T3_SOURCE_MASK (~T3_SOURCE_EXT)
129 #endif
130 
131 #ifdef _T4IF
132 /* T4CON: TIMER4 CONTROL REGISTER */
133 #define T4_ON 0x8000 /* Timer4 ON */
134 #define T4_OFF 0x0000 /* Timer4 OFF */
135 #define T4_OFF_ON_MASK (~T4_ON)
136 
137 #define T4_IDLE_STOP 0x2000 /* operate during sleep */
138 #define T4_IDLE_CON 0x0000 /* stop operation during sleep */
139 #define T4_IDLE_MASK (~T4_IDLE_STOP)
140 
141 #define T4_GATE_ON 0x0040 /* Timer Gate time accumulation enabled */
142 #define T4_GATE_OFF 0x0000 /* Timer Gate time accumulation disabled */
143 #define T4_GATE_MASK (~T4_GATE_ON)
144 
145 #define T4_PS_1_1 0x0000 /* Prescaler 1:1 */
146 #define T4_PS_1_8 0x0010 /* 1:8 */
147 #define T4_PS_1_64 0x0020 /* 1:64 */
148 #define T4_PS_1_256 0x0030 /* 1:256 */
149 #define T4_PS_MASK (~T4_PS_1_256)
150 
151 #define T4_32BIT_MODE_ON 0x0008 /* Timer 4 and Timer 5 form a 32 bit Timer */
152 #define T4_32BIT_MODE_OFF 0x0000
153 #define T4_32BIT_MODE_MASK (~T4_32BIT_MODE_ON)
154 
155 #define T4_SOURCE_EXT 0x0002 /* External clock source */
156 #define T4_SOURCE_INT 0x0000 /* Internal clock source */
157 #define T4_SOURCE_MASK (~T4_SOURCE_EXT)
158 #endif
159 
160 #ifdef _T5IF
161 /* T5CON: TIMER5 CONTROL REGISTER */
162 #define T5_ON 0x8000 /* Timer5 ON */
163 #define T5_OFF 0x0000 /* Timer5 OFF */
164 #define T5_OFF_ON_MASK (~T5_ON)
165 
166 #define T5_IDLE_STOP 0x2000 /* operate during sleep */
167 #define T5_IDLE_CON 0x0000 /* stop operation during sleep */
168 #define T5_IDLE_MASK (~T5_IDLE_STOP)
169 
170 #define T5_GATE_ON 0x0040 /* Timer Gate time accumulation enabled */
171 #define T5_GATE_OFF 0x0000 /* Timer Gate time accumulation disabled */
172 #define T5_GATE_MASK (~T5_GATE_ON)
173 
174 #define T5_PS_1_1 0x0000 /* Prescaler 1:1 */
175 #define T5_PS_1_8 0x0010 /* 1:8 */
176 #define T5_PS_1_64 0x0020 /* 1:64 */
177 #define T5_PS_1_256 0x0030 /* 1:256 */
178 #define T5_PS_MASK (~T5_PS_1_256)
179 
180 #define T5_SOURCE_EXT 0x0002 /* External clock source */
181 #define T5_SOURCE_INT 0x0000 /* Internal clock source */
182 #define T5_SOURCE_MASK (~T5_SOURCE_EXT)
183 #endif
184 
185 #ifdef _T6IF
186 /* T6CON: TIMER6 CONTROL REGISTER */
187 #define T6_ON 0x8000 /* Timer6 ON */
188 #define T6_OFF 0x0000 /* Timer6 OFF */
189 #define T6_OFF_ON_MASK (~T6_ON)
190 
191 #define T6_IDLE_STOP 0x2000 /* operate during sleep */
192 #define T6_IDLE_CON 0x0000 /* stop operation during sleep */
193 #define T6_IDLE_MASK (~T6_IDLE_STOP)
194 
195 #define T6_GATE_ON 0x0040 /* Timer Gate time accumulation enabled */
196 #define T6_GATE_OFF 0x0000 /* Timer Gate time accumulation disabled */
197 #define T6_GATE_MASK (~T6_GATE_ON)
198 
199 #define T6_PS_1_1 0x0000 /* Prescaler 1:1 */
200 #define T6_PS_1_8 0x0010 /* 1:8 */
201 #define T6_PS_1_64 0x0020 /* 1:64 */
202 #define T6_PS_1_256 0x0030 /* 1:256 */
203 #define T6_PS_MASK (~T6_PS_1_256)
204 
205 #define T6_32BIT_MODE_ON 0x0008 /* Timer 6 and Timer 7 form a 32 bit Timer */
206 #define T6_32BIT_MODE_OFF 0x0000
207 #define T6_32BIT_MODE_MASK (~T6_32BIT_MODE_ON)
208 
209 #define T6_SOURCE_EXT 0x0002 /* External clock source */
210 #define T6_SOURCE_INT 0x0000 /* Internal clock source */
211 #define T6_SOURCE_MASK (~T6_SOURCE_EXT)
212 #endif
213 
214 #ifdef _T7IF
215 /* T7CON: TIMER7 CONTROL REGISTER */
216 #define T7_ON 0x8000 /* Timer7 ON */
217 #define T7_OFF 0x0000 /* Timer7 OFF */
218 #define T7_OFF_ON_MASK (~T7_ON)
219 
220 #define T7_IDLE_STOP 0x2000 /* operate during sleep */
221 #define T7_IDLE_CON 0x0000 /* stop operation during sleep */
222 #define T7_IDLE_MASK (~T7_IDLE_STOP)
223 
224 #define T7_GATE_ON 0x0040 /* Timer Gate time accumulation enabled */
225 #define T7_GATE_OFF 0x0000 /* Timer Gate time accumulation disabled */
226 #define T7_GATE_MASK (~T7_GATE_ON)
227 
228 #define T7_PS_1_1 0x0000 /* Prescaler 1:1 */
229 #define T7_PS_1_8 0x0010 /* 1:8 */
230 #define T7_PS_1_64 0x0020 /* 1:64 */
231 #define T7_PS_1_256 0x0030 /* 1:256 */
232 #define T7_PS_MASK (~T7_PS_1_256)
233 
234 #define T7_SOURCE_EXT 0x0002 /* External clock source */
235 #define T7_SOURCE_INT 0x0000 /* Internal clock source */
236 #define T7_SOURCE_MASK (~T7_SOURCE_EXT)
237 #endif
238 
239 #ifdef _T8IF
240 /* T8CON: TIMER8 CONTROL REGISTER */
241 #define T8_ON 0x8000 /* Timer8 ON */
242 #define T8_OFF 0x0000 /* Timer8 OFF */
243 #define T8_OFF_ON_MASK (~T8_ON)
244 
245 #define T8_IDLE_STOP 0x2000 /* operate during sleep */
246 #define T8_IDLE_CON 0x0000 /* stop operation during sleep */
247 #define T8_IDLE_MASK (~T8_IDLE_STOP)
248 
249 #define T8_GATE_ON 0x0040 /* Timer Gate time accumulation enabled */
250 #define T8_GATE_OFF 0x0000 /* Timer Gate time accumulation disabled */
251 #define T8_GATE_MASK (~T8_GATE_ON)
252 
253 #define T8_PS_1_1 0x0000 /* Prescaler 1:1 */
254 #define T8_PS_1_8 0x0010 /* 1:8 */
255 #define T8_PS_1_64 0x0020 /* 1:64 */
256 #define T8_PS_1_256 0x0030 /* 1:256 */
257 #define T8_PS_MASK (~T8_PS_1_256)
258 
259 #define T8_32BIT_MODE_ON 0x0008 /* Timer 8 and Timer 9 form a 32 bit Timer */
260 #define T8_32BIT_MODE_OFF 0x0000
261 #define T8_32BIT_MODE_MASK (~T8_32BIT_MODE_ON)
262 
263 #define T8_SOURCE_EXT 0x0002 /* External clock source */
264 #define T8_SOURCE_INT 0x0000 /* Internal clock source */
265 #define T8_SOURCE_MASK (~T8_SOURCE_EXT)
266 #endif
267 
268 #ifdef _T9IF
269 /* T9CON: TIMER9 CONTROL REGISTER */
270 #define T9_ON 0x8000 /* Timer9 ON */
271 #define T9_OFF 0x0000 /* Timer9 OFF */
272 #define T9_OFF_ON_MASK (~T9_ON)
273 
274 #define T9_IDLE_STOP 0x2000 /* operate during sleep */
275 #define T9_IDLE_CON 0x0000 /* stop operation during sleep */
276 #define T9_IDLE_MASK (~T9_IDLE_STOP)
277 
278 #define T9_GATE_ON 0x0040 /* Timer Gate time accumulation enabled */
279 #define T9_GATE_OFF 0x0000 /* Timer Gate time accumulation disabled */
280 #define T9_GATE_MASK (~T9_GATE_ON)
281 
282 #define T9_PS_1_1 0x0000 /* Prescaler 1:1 */
283 #define T9_PS_1_8 0x0010 /* 1:8 */
284 #define T9_PS_1_64 0x0020 /* 1:64 */
285 #define T9_PS_1_256 0x0030 /* 1:256 */
286 #define T9_PS_MASK (~T9_PS_1_256)
287 
288 #define T9_SOURCE_EXT 0x0002 /* External clock source */
289 #define T9_SOURCE_INT 0x0000 /* Internal clock source */
290 #define T9_SOURCE_MASK (~T9_SOURCE_EXT)
291 #endif
292 
293 //Input Capture macros
294 
295 /*
296 The following macros are a subset of the AND/OR macros found in the
297 the MPLAB C30/src/peripheral_24F/incap.h file and placed
298 in this header for use solely and exclusively on Microchip
299 PICmicro Microcontroller products as
300 specified in the MPLAB C30/src/peripheral_24F/incap.h header.
301 */
302 #if (defined(__dsPIC33E__) || defined(__PIC24E__))
303 #define IC_IDLE_STOP 0x2000 /* IC stop in sleep mode */
304 #define IC_IDLE_CON 0x0000 /* IC operate in sleep mode */
305 #define IC_IDLE_MASK (~IC_IDLE_STOP)
306 
307 #define IC_FP_SRC (7 << 10) /* Peripheral Clock is the clock source for Capture */
308 #define IC_TIMER1_SRC (4 << 10) /* Timer1 is the clock source for Capture */
309 #define IC_TIMER5_SRC (3 << 10) /* Timer5 is the clock source for Capture */
310 #define IC_TIMER4_SRC (2 << 10) /* Timer4 is the clock source for Capture */
311 #define IC_TIMER2_SRC (1 << 10) /* Timer2 is the clock source for Capture */
312 #define IC_TIMER3_SRC 0x0000 /* Timer3 is the clock source for Capture */
313 #define IC_TIMER_SRC_MASK (~ (7 << 10) )
314 
315 #define IC_INT_4CAPTURE 0x0060 /* Interrupt on fourth Capture*/
316 #define IC_INT_3CAPTURE 0x0040 /* Interrupt on third Capture */
317 #define IC_INT_2CAPTURE 0x0020 /* Interrupt on second Capture*/
318 #define IC_INT_1CAPTURE 0x0000 /* Interrupt on first Capture */
319 #define IC_INT_CAPTURE_MASK (~IC_INT_4CAPTURE)
320 
321 #define IC_INTERRUPT 0x0007 /* Interrupt pin only in CPU sleep and idle mode */
322 #define IC_EVERY_16_RISE_EDGE 0x0005 /* Every 16th rising edge */
323 #define IC_EVERY_4_RISE_EDGE 0x0004 /* Every 4th rising edge */
324 #define IC_EVERY_RISE_EDGE 0x0003 /* Every rising edge */
325 #define IC_EVERY_FALL_EDGE 0x0002 /* Every falling edge */
326 #define IC_EVERY_EDGE 0x0001 /* Every rising/falling edge */
327 #define IC_INPUTCAP_OFF 0x0000 /* Input Capture Off */
328 #define IC_CAPTURE_MODE_MASK (~IC_INTERRUPT)
329 
330 //ICxCON2 register bits (dsPIC33E/PIC24E)
331 #define IC_IC32_ON (0x01 << 8)
332 #define IC_IC32_OFF (0x00 << 8)
333 #define IC_TRIG_MODE (0x01 << 7)
334 #define IC_SYNC_MODE (0x00 << 7)
335 
336 //Sync/Trigger Bits for Input Capture
337 //these are device dependent, but this works for many devices
338 #define IC_SYNCSEL_NOSYNC 0x00
339 #define IC_SYNCSEL_OC1 0x01
340 #define IC_SYNCSEL_OC2 0x02
341 #define IC_SYNCSEL_OC3 0x03
342 #define IC_SYNCSEL_OC4 0x04
343 #define IC_SYNCSEL_PTGO 0x0A
344 #define IC_SYNCSEL_TIMER1 0x0B
345 #define IC_SYNCSEL_TIMER2 0x0C
346 #define IC_SYNCSEL_TIMER3 0x0D
347 #define IC_SYNCSEL_TIMER4 0x0E
348 #define IC_SYNCSEL_TIMER5 0x0F
349 #define IC_SYNCSEL_IC1 0x10
350 #define IC_SYNCSEL_IC2 0x11
351 #define IC_SYNCSEL_IC3 0x12
352 #define IC_SYNCSEL_IC4 0x13
353 #define IC_SYNCSEL_CMP1 0x18
354 #define IC_SYNCSEL_CMP2 0x19
355 #define IC_SYNCSEL_CMP3 0x1A
356 #define IC_SYNCSEL_ADC1 0x1B
357 #define IC_SYNCSEL_CTMU 0x1C
358 
359 
360 
361 #else
362 #define IC_IDLE_STOP 0x2000 /* IC stop in sleep mode */
363 #define IC_IDLE_CON 0x0000 /* IC operate in sleep mode */
364 #define IC_IDLE_MASK (~IC_IDLE_STOP)
365 
366 #define IC_TIMER2_SRC 0x0080 /* Timer2 is the clock source for Capture */
367 #define IC_TIMER3_SRC 0x0000 /* Timer3 is the clock source for Capture */
368 #define IC_TIMER_SRC_MASK (~IC_TIMER2_SRC)
369 
370 #define IC_INT_4CAPTURE 0x0060 /* Interrupt on fourth Capture*/
371 #define IC_INT_3CAPTURE 0x0040 /* Interrupt on third Capture */
372 #define IC_INT_2CAPTURE 0x0020 /* Interrupt on second Capture*/
373 #define IC_INT_1CAPTURE 0x0000 /* Interrupt on first Capture */
374 #define IC_INT_CAPTURE_MASK (~IC_INT_4CAPTURE)
375 
376 #define IC_INTERRUPT 0x0007 /* Interrupt pin only in CPU sleep and idle mode */
377 #define IC_EVERY_16_RISE_EDGE 0x0005 /* Every 16th rising edge */
378 #define IC_EVERY_4_RISE_EDGE 0x0004 /* Every 4th rising edge */
379 #define IC_EVERY_RISE_EDGE 0x0003 /* Every rising edge */
380 #define IC_EVERY_FALL_EDGE 0x0002 /* Every falling edge */
381 #define IC_EVERY_EDGE 0x0001 /* Every rising/falling edge */
382 #define IC_INPUTCAP_OFF 0x0000 /* Input Capture Off */
383 #define IC_CAPTURE_MODE_MASK (~IC_INTERRUPT)
384 #endif
385 
386 //Output Compare macros
387 
388 /*
389 The following macros are a subset of the AND/OR macros found in the
390 the MPLAB C30/src/peripheral_24F/outcompare.h file and placed
391 in this header for use solely and exclusively on Microchip
392 PICmicro Microcontroller products as
393 specified in the MPLAB C30/src/peripheral_24F/outcompare.h header.
394 */
395 
396 #if (defined(__dsPIC33E__) || defined(__PIC24E__))
397 #define OC_IDLE_CON 0x0000 /* continue operation in idle mode */
398 #define OC_IDLE_STOP 0x2000 /* stop in idle mode */
399 #define OC_IDLE_MASK (~OC_IDLE_STOP)
400 #define OC_TIMER2_SRC (0 << 10) /* Timer2 is the clock source for OutputCompare */
401 #define OC_TIMER3_SRC (1 << 10) /* Timer3 is the clock source for OutputCompare */
402 #define OC_TIMER4_SRC (2 << 10) /* Timer3 is the clock source for OutputCompare */
403 #define OC_TIMER5_SRC (3 << 10) /* Timer3 is the clock source for OutputCompare */
404 #define OC_TIMER1_SRC (4 << 10) /* Timer3 is the clock source for OutputCompare */
405 #define OC_FP_SRC (7 << 10) /* Peripheral Clock is the clock source for OutputCompare */
406 
407 
408 #define OC_PWM_CENTER_ALIGN 0x0007 /* PWM Mode on OCx, fault pin enabled, (TxIF bit is set for PWM, OCxIF is set for fault)*/
409 #define OC_PWM_EDGE_ALIGN 0x0006 /* PWM Mode on OCx, fault pin disabled */
410 #define OC_CONTINUE_PULSE 0x0005 /* Generates Continuous Output pulse on OCx Pin */
411 #define OC_SINGLE_PULSE 0x0004 /* Generates Single Output pulse on OCx Pin */
412 #define OC_TOGGLE_PULSE 0x0003 /* Compare1 toggles OCx pin*/
413 #define OC_HIGH_LOW 0x0002 /* Compare1 forces OCx pin Low*/
414 #define OC_LOW_HIGH 0x0001 /* Compare1 forces OCx pin High*/
415 #define OC_OFF 0x0000 /* OutputCompare x Off*/
416 #define OC_PWM_MODE_MASK (~OC_PWM_FAULT_PIN_ENABLE)
417 
418 #define OC_PWM_FAULT_PIN_ENABLE 0x0007 /* PWM Mode on OCx, keep for compatibility with PIC24H source*/
419 #define OC_PWM_FAULT_PIN_DISABLE 0x0006 /* PWM Mode on OCx, keep for compatibility with PIC24H source */
420 
421 //OCxCON2 register bits (dsPIC33E/PIC24E)
422 #define OC_FLTMD_ON (0x01 << 15)
423 #define OC_FLTMD_OFF (0x00 << 15)
424 #define OC_FLTOUT_ON (0x01 << 14)
425 #define OC_FLTOUT_OFF (0x00 << 14)
426 #define OC_FLTTRIEN_ON (0x01 << 13)
427 #define OC_FLTTRIEN_OFF (0x00 << 13)
428 #define OC_OCINV_ON (0x01 << 12)
429 #define OC_OCINV_OFF (0x00 << 12)
430 
431 #define OC_IC32_ON (0x01 << 8)
432 #define OC_IC32_OFF (0x00 << 8)
433 #define OC_TRIG_MODE (0x01 << 7)
434 #define OC_SYNC_MODE (0x00 << 7)
435 #define OC_TRIS_ON (0x01 << 5)
436 #define OC_TRIS_OFF (0x00 << 5)
437 
438 //Sync/Trigger Bits for Input Capture
439 //these are device dependent, but this works for many devices
440 #define OC_SYNCSEL_NOSYNC 0x00
441 #define OC_SYNCSEL_OC1 0x01
442 #define OC_SYNCSEL_OC2 0x02
443 #define OC_SYNCSEL_OC3 0x03
444 #define OC_SYNCSEL_OC4 0x04
445 #define OC_SYNCSEL_PTGO 0x0A
446 #define OC_SYNCSEL_TIMER1 0x0B
447 #define OC_SYNCSEL_TIMER2 0x0C
448 #define OC_SYNCSEL_TIMER3 0x0D
449 #define OC_SYNCSEL_TIMER4 0x0E
450 #define OC_SYNCSEL_TIMER5 0x0F
451 #define OC_SYNCSEL_IC1 0x10
452 #define OC_SYNCSEL_IC2 0x11
453 #define OC_SYNCSEL_IC3 0x12
454 #define OC_SYNCSEL_IC4 0x13
455 #define OC_SYNCSEL_CMP1 0x18
456 #define OC_SYNCSEL_CMP2 0x19
457 #define OC_SYNCSEL_CMP3 0x1A
458 #define OC_SYNCSEL_ADC1 0x1B
459 #define OC_SYNCSEL_CTMU 0x1C
460 #define OC_SYNCSEL_INT1 0x1D
461 #define OC_SYNCSEL_INT2 0x1E
462 #define OC_SYNCSEL_OCxRS 0x1F
463 
464 #else
465 /* Section : Output Compare Stop in Idle mode Bit defines */
466 #define OC_IDLE_CON 0x0000 /* continue operation in idle mode */
467 #define OC_IDLE_STOP 0x2000 /* stop in idle mode */
468 #define OC_IDLE_MASK (~OC_IDLE_STOP)
469 
470 /*Section : Output Compare timer select Bit Defines */
471 #define OC_TIMER2_SRC 0x0000 /* Timer2 is the clock source for OutputCompare */
472 #define OC_TIMER3_SRC 0x0008 /* Timer3 is the clock source for OutputCompare */
473 #define OC_TIMER_SRC_MASK (~OC_TIMER3_SRC)
474 
475 #define OC_PWM_FAULT_PIN_ENABLE 0x0007 /* PWM Mode on OCx, fault pin enabled, (TxIF bit is set for PWM, OCxIF is set for fault)*/
476 #define OC_PWM_FAULT_PIN_DISABLE 0x0006 /* PWM Mode on OCx, fault pin disabled */
477 #define OC_CONTINUE_PULSE 0x0005 /* Generates Continuous Output pulse on OCx Pin */
478 #define OC_SINGLE_PULSE 0x0004 /* Generates Single Output pulse on OCx Pin */
479 #define OC_TOGGLE_PULSE 0x0003 /* Compare1 toggles OCx pin*/
480 #define OC_HIGH_LOW 0x0002 /* Compare1 forces OCx pin Low*/
481 #define OC_LOW_HIGH 0x0001 /* Compare1 forces OCx pin High*/
482 #define OC_OFF 0x0000 /* OutputCompare x Off*/
483 #define OC_PWM_MODE_MASK (~OC_PWM_FAULT_PIN_ENABLE)
484 #endif
uint16_t getTimerPrescaleBits(uint8_t u8_TCKPS)
Definition: pic24_timer.c:158
uint16_t computeDeltaTicks(uint16_t u16_start, uint16_t u16_end, uint16_t u16_tmrPR)
Definition: pic24_timer.c:193
uint32_t computeDeltaTicksLong(uint16_t u16_start, uint16_t u16_end, uint16_t u16_tmrPR, uint16_t u16_oflows)
Definition: pic24_timer.c:172
uint32_t ticksToMs(uint32_t u32_ticks, uint16_t u16_tmrPre)
Definition: pic24_timer.c:106
Configures the system clock.
uint16_t msToU16Ticks(uint16_t u16_ms, uint16_t u16_pre)
Definition: pic24_timer.c:53
uint32_t usToU32Ticks(uint32_t u32_us, uint16_t u16_pre)
Definition: pic24_timer.c:90
uint32_t ticksToUs(uint32_t u32_ticks, uint16_t u16_tmrPre)
Definition: pic24_timer.c:123
uint32_t ticksToNs(uint32_t u32_ticks, uint16_t u16_tmrPre)
Definition: pic24_timer.c:139
unsigned char uint8_t
An abbreviation for an 8-bit unsigned integer.
Definition: dataXferImpl.h:194
uint16_t usToU16Ticks(uint16_t u16_us, uint16_t u16_pre)
Definition: pic24_timer.c:71