1 /******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
2 * File Name : 75x_tim.c
3 * Author : MCD Application Team
4 * Date First Issued : 03/10/2006
5 * Description : This file provides all the TIM software functions.
6 ********************************************************************************
10 ********************************************************************************
11 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
13 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
14 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
15 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
16 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 *******************************************************************************/
19 /* Includes ------------------------------------------------------------------*/
23 /* Private typedef -----------------------------------------------------------*/
24 /* Private define ------------------------------------------------------------*/
25 /* Private macro -------------------------------------------------------------*/
26 /* Private variables ---------------------------------------------------------*/
27 /* TIM interrupt masks */
28 #define TIM_IT_Clear_Mask 0x7FFF
29 #define TIM_IT_Enable_Mask 0x7FFF
31 /* TIM Input Capture Selection Set/Reset */
32 #define TIM_IC1S_Set 0x0001
33 #define TIM_IC1S_Reset 0x003E
35 /* TIM Input Capture Selection Set/Reset */
36 #define TIM_IC2S_Set 0x0002
37 #define TIM_IC2S_Reset 0x003D
39 /* TIM_SCR Masks bit */
40 #define TIM_Encoder_Mask 0x731C
41 #define TIM_SlaveModeSelection_Mask 0x7307
42 #define TIM_TriggerSelection_Mask 0x701F
43 #define TIM_InternalTriggerSelection_Mask 0x031F
45 /* TIM Encoder mode Set value */
46 #define TIM_Encoder1_Set 0x0001
47 #define TIM_Encoder2_Set 0x0002
48 #define TIM_Encoder3_Set 0x0003
50 /* TIM Slave Mode Enable Set/Reset value */
51 #define TIM_SME_Reset 0x731B
52 #define TIM_SME_Set 0x0004
54 /* TIM Internal Trigger Selection value */
55 #define TIM_ITS_TIM0 0x1000
56 #define TIM_ITS_TIM1 0x2000
57 #define TIM_ITS_TIM2 0x3000
58 #define TIM_ITS_PWM 0x4000
60 /* TIM Trigger Selection value */
61 #define TIM_TS_IC1_Set 0x0200
62 #define TIM_TS_IC2_Set 0x0300
64 /* TIM Slave Mode selction external clock Set value */
65 #define TIM_SMS_EXTCLK_Set 0x0008
66 #define TIM_SMS_RESETCLK_Set 0x0000
68 /* TIM_CR Masks bit */
69 #define TIM_DBASE_Mask 0x077F
70 #define TIM_MasterModeSelection_Mask 0xFC7F
71 #define TIM_CounterMode_Mask 0xFF8F
73 /* TIM Update flag selection Set/Reset value */
74 #define TIM_UFS_Reset 0xFFFE
75 #define TIM_UFS_Set 0x0001
77 /* TIM Counter value */
78 #define TIM_COUNTER_Reset 0x0002
79 #define TIM_COUNTER_Start 0x0004
80 #define TIM_COUNTER_Stop 0xFFFB
82 /* TIM One pulse Mode set value */
83 #define TIM_OPM_Set 0x0008
84 #define TIM_OPM_Reset 0xFFF7
86 /* TIM Debug Mode Set/Reset value */
87 #define TIM_DBGC_Set 0x0400
88 #define TIM_DBGC_Reset 0xFB7F
90 /* TIM Input Capture Enable/Disable value */
91 #define TIM_IC1_Enable 0x0004
92 #define TIM_IC2_Enable 0x0010
94 /* TIM Input Capture Polarity Set/Reset value */
95 #define TIM_IC1P_Set 0x0008
96 #define TIM_IC2P_Set 0x0020
97 #define TIM_IC1P_Reset 0x0037
98 #define TIM_IC2P_Reset 0x001F
100 /* TIM Output Compare Polarity Set/Reset value */
101 #define TIM_OC1P_Set 0x0020
102 #define TIM_OC2P_Set 0x2000
103 #define TIM_OC1P_Reset 0x3F1F
104 #define TIM_OC2P_Reset 0x1F3F
106 /* TIM Output Compare control mode constant */
107 #define TIM_OCControl_PWM 0x000C
108 #define TIM_OCControl_OCToggle 0x0006
109 #define TIM_OCControl_OCInactive 0x0004
110 #define TIM_OCControl_OCActive 0x0002
111 #define TIM_OCControl_OCTiming 0x0000
113 /* TIM Output Compare mode Enable value */
114 #define TIM_OC1_Enable 0x0010
115 #define TIM_OC2_Enable 0x1000
117 /* TIM Output Compare mode Mask value */
118 #define TIM_OC1C_Mask 0x3F31
119 #define TIM_OC2C_Mask 0x313F
121 /* TIM Preload bit Set/Reset value */
122 #define TIM_PLD1_Set 0x0001
123 #define TIM_PLD1_Reset 0xFFFE
125 #define TIM_PLD2_Set 0x0100
126 #define TIM_PLD2_Reset 0xFEFF
128 /* TIM OCRM Set/Reset value */
129 #define TIM_OCRM_Set 0x0080
130 #define TIM_OCRM_Reset 0x030D
132 /* Reset Register Masks */
133 #define TIM_Pulse2_Reset_Mask 0x0000
134 #define TIM_Prescaler_Reset_Mask 0x0000
135 #define TIM_Pulse1_Reset_Mask 0x0000
136 #define TIM_Period_Reset_Mask 0xFFFF
137 #define TIM_Counter_Reset 0x0002
139 /* Private function prototypes -----------------------------------------------*/
140 static void ICAP_ModuleConfig(TIM_TypeDef* TIMx, TIM_InitTypeDef* TIM_InitStruct);
141 static void Encoder_ModeConfig(TIM_TypeDef* TIMx, TIM_InitTypeDef* TIM_InitStruct);
142 static void OCM_ModuleConfig(TIM_TypeDef* TIMx, TIM_InitTypeDef* TIM_InitStruct);
144 /* Private functions ---------------------------------------------------------*/
146 /******************************************************************************
147 * Function Name : TIM_DeInit
148 * Description : Deinitializes TIM peripheral registers to their default reset
150 * Input : TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
153 *******************************************************************************/
154 void TIM_DeInit(TIM_TypeDef *TIMx)
158 MRCC_PeripheralSWResetConfig(MRCC_Peripheral_TIM0,ENABLE);
159 MRCC_PeripheralSWResetConfig(MRCC_Peripheral_TIM0,DISABLE);
161 else if(TIMx == TIM1)
163 MRCC_PeripheralSWResetConfig(MRCC_Peripheral_TIM1,ENABLE);
164 MRCC_PeripheralSWResetConfig(MRCC_Peripheral_TIM1,DISABLE);
166 else if(TIMx == TIM2)
168 MRCC_PeripheralSWResetConfig(MRCC_Peripheral_TIM2,ENABLE);
169 MRCC_PeripheralSWResetConfig(MRCC_Peripheral_TIM2,DISABLE);
173 /*******************************************************************************
174 * Function Name : TIM_Init
175 * Description : Initializes the TIMx peripheral according to the specified
176 * parameters in the TIM_InitStruct .
177 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
178 * - TIM_InitStruct: pointer to a TIM_InitTypeDef structure that
179 * contains the configuration information for the specified TIM
183 *******************************************************************************/
184 void TIM_Init(TIM_TypeDef* TIMx, TIM_InitTypeDef* TIM_InitStruct)
186 /* Set the prescaler value */
187 TIMx->PSC = TIM_InitStruct->TIM_Prescaler;
189 /* Select the clock source */
190 TIM_ClockSourceConfig(TIMx, TIM_InitStruct->TIM_ClockSource,
191 TIM_InitStruct->TIM_ExtCLKEdge);
193 /* Select the counter mode */
194 TIMx->CR &= TIM_CounterMode_Mask;
195 TIMx->CR |= TIM_InitStruct->TIM_CounterMode;
197 /* Set the period value */
198 TIMx->ARR = TIM_InitStruct->TIM_Period;
200 switch(TIM_InitStruct->TIM_Mode)
202 case TIM_Mode_OCTiming: case TIM_Mode_OCActive: case TIM_Mode_OCInactive:
203 case TIM_Mode_OCToggle: case TIM_Mode_PWM:
204 OCM_ModuleConfig(TIMx, TIM_InitStruct);
207 case TIM_Mode_PWMI: case TIM_Mode_IC:
208 ICAP_ModuleConfig(TIMx, TIM_InitStruct);
211 case TIM_Mode_Encoder1: case TIM_Mode_Encoder2: case TIM_Mode_Encoder3:
212 Encoder_ModeConfig(TIMx, TIM_InitStruct);
215 case TIM_Mode_OPM_PWM: case TIM_Mode_OPM_Toggle: case TIM_Mode_OPM_Active:
217 /* Output module configuration */
218 OCM_ModuleConfig(TIMx, TIM_InitStruct);
220 /* Input module configuration */
221 ICAP_ModuleConfig(TIMx, TIM_InitStruct);
223 /* Set the slave mode to trigger Mode */
224 TIMx->SCR |= TIM_SynchroMode_Trigger;
226 /* Repetitive pulse state selection */
227 if(TIM_InitStruct->TIM_RepetitivePulse == TIM_RepetitivePulse_Disable)
229 TIMx->CR |= TIM_OPM_Set;
233 TIMx->CR &= TIM_OPM_Reset;
242 /*******************************************************************************
243 * Function Name : TIM_StructInit
244 * Description : Fills each TIM_InitStruct member with its default value.
245 * Input : TIM_InitStruct : pointer to a TIM_InitTypeDef structure
246 * which will be initialized.
249 *******************************************************************************/
250 void TIM_StructInit(TIM_InitTypeDef *TIM_InitStruct)
252 /* Set the default configuration */
253 TIM_InitStruct->TIM_Mode = TIM_Mode_OCTiming;
254 TIM_InitStruct->TIM_Prescaler = TIM_Prescaler_Reset_Mask;
255 TIM_InitStruct->TIM_ClockSource = TIM_ClockSource_Internal;
256 TIM_InitStruct->TIM_ExtCLKEdge = TIM_ExtCLKEdge_Rising;
257 TIM_InitStruct->TIM_CounterMode = TIM_CounterMode_Up;
258 TIM_InitStruct->TIM_Period = TIM_Period_Reset_Mask;
259 TIM_InitStruct->TIM_Channel = TIM_Channel_ALL;
260 TIM_InitStruct->TIM_Pulse1 = TIM_Pulse1_Reset_Mask;
261 TIM_InitStruct->TIM_Pulse2 = TIM_Pulse2_Reset_Mask;
262 TIM_InitStruct->TIM_RepetitivePulse = TIM_RepetitivePulse_Disable;
263 TIM_InitStruct->TIM_Polarity1 = TIM_Polarity1_Low;
264 TIM_InitStruct->TIM_Polarity2 = TIM_Polarity2_Low;
265 TIM_InitStruct->TIM_IC1Selection = TIM_IC1Selection_TI1;
266 TIM_InitStruct->TIM_IC2Selection = TIM_IC2Selection_TI1;
267 TIM_InitStruct->TIM_IC1Polarity = TIM_IC1Polarity_Rising;
268 TIM_InitStruct->TIM_IC2Polarity = TIM_IC2Polarity_Rising;
269 TIM_InitStruct->TIM_PWMI_ICSelection = TIM_PWMI_ICSelection_TI1;
270 TIM_InitStruct->TIM_PWMI_ICPolarity = TIM_PWMI_ICPolarity_Rising;
273 /*******************************************************************************
274 * Function Name : TIM_Cmd
275 * Description : Enables or disables the specified TIM peripheral.
276 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
277 * - Newstate: new state of the TIMx peripheral.
278 * This parameter can be: ENABLE or DISABLE.
281 *******************************************************************************/
282 void TIM_Cmd(TIM_TypeDef *TIMx, FunctionalState Newstate)
284 if(Newstate == ENABLE)
286 TIMx->CR |= TIM_COUNTER_Start;
290 TIMx->CR &= TIM_COUNTER_Stop;
294 /*******************************************************************************
295 * Function Name : TIM_ITConfig
296 * Description : Enables or disables the TIM interrupts.
297 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
298 * - TIM_IT: specifies the TIM interrupts sources to be enabled
300 * This parameter can be any combination of the following values:
301 * - TIM_IT_IC1: Input Capture 1 Interrupt
302 * - TIM_IT_OC1: Output Compare 1 Interrupt
303 * - TIM_IT_Update: Timer update Interrupt
304 * - TIM_IT_GlobalUpdate: Timer global update Interrupt
305 * - TIM_IT_IC2: Input Capture 2 Interrupt
306 * - TIM_IT_OC2: Output Compare 2 Interrupt
307 * - Newstate: new state of the specified TIMx interrupts.
308 * This parameter can be: ENABLE or DISABLE.
311 *******************************************************************************/
312 void TIM_ITConfig(TIM_TypeDef *TIMx, u16 TIM_IT, FunctionalState Newstate)
314 u16 TIM_IT_Enable = 0;
316 TIM_IT_Enable = TIM_IT & TIM_IT_Enable_Mask;
318 if(Newstate == ENABLE)
320 /* Update interrupt global source: overflow/undeflow, counter reset operation
321 or slave mode controller in reset mode */
322 if((TIM_IT & TIM_IT_GlobalUpdate) == TIM_IT_GlobalUpdate)
324 TIMx->CR &= TIM_UFS_Reset;
326 /* Update interrupt source: counter overflow/underflow */
327 else if((TIM_IT & TIM_IT_Update) == TIM_IT_Update)
329 TIMx->CR |= TIM_UFS_Set;
331 /* Select and enable the interrupts requests */
332 TIMx->RSR |= TIM_IT_Enable;
333 TIMx->RER |= TIM_IT_Enable;
335 /* Disable the interrupts requests */
338 TIMx->RSR &= ~TIM_IT_Enable;
339 TIMx->RER &= ~TIM_IT_Enable;
343 /*******************************************************************************
344 * Function Name : TIM_PreloadConfig
345 * Description : Enables or disables TIM peripheral Preload register on OCRx.
346 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
347 * - TIM_Channel: specifies the TIM channel to be used.
348 * This parameter can be one of the following values:
349 * - TIM_Channel_1: TIM Channel 1 is used
350 * - TIM_Channel_2: TIM Channel 2 is used
351 * - TIM_Channel_ALL: TIM Channel 1and 2 are used
352 * - Newstate: new state of the TIMx peripheral Preload register
353 * This parameter can be: ENABLE or DISABLE.
356 *******************************************************************************/
357 void TIM_PreloadConfig(TIM_TypeDef *TIMx, u16 TIM_Channel, FunctionalState Newstate)
359 if(Newstate == ENABLE)
364 TIMx->OMR1 |= TIM_PLD1_Set;
368 TIMx->OMR1 |= TIM_PLD2_Set;
371 case TIM_Channel_ALL:
372 TIMx->OMR1 |= TIM_PLD1_Set | TIM_PLD2_Set;
384 TIMx->OMR1 &= TIM_PLD1_Reset;
388 TIMx->OMR1 &= TIM_PLD2_Reset;
391 case TIM_Channel_ALL:
392 TIMx->OMR1 &= TIM_PLD1_Reset & TIM_PLD2_Reset;
401 /*******************************************************************************
402 * Function Name : TIM_DMAConfig
403 * Description : Configures the TIM0
\92s DMA interface.
404 * Input : - TIM_DMASources: specifies the DMA Request sources.
405 * This parameter can be any combination of the following values:
406 * - TIM_DMASource_OC1: Output Compare 1 DMA source
407 * - TIM_DMASource_OC2: Output Compare 2 DMA source
408 * - TIM_DMASource_IC1: Input Capture 1 DMA source
409 * - TIM_DMASource_IC2: Input Capture 2 DMA source
410 * - TIM_DMASource_Update: Timer Update DMA source
411 * - TIM_OCRMState: the state of output compare request mode.
412 * This parameter can be one of the following values:
413 * - TIM_OCRMState_Enable
414 * - TIM_OCRMState_Disable
415 * - TIM_DMABase:DMA Base address.
416 * This parameter can be one of the following values:
417 * TIM_DMABase_CR, TIM_DMABase_SCR, TIM_DMABase_IMCR,
418 * TIM_DMABase_OMR1, TIM_DMABase_RSR,
419 * TIM_DMABase_RER, TIM_DMABase_ISR, TIM_DMABase_CNT,
420 * TIM_DMABase_PSC, TIM_DMABase_ARR, TIM_DMABase_OCR1,
421 * TIM_DMABase_OCR2, TIM_DMABase_ICR1, TIM_DMABase_ICR2
424 *******************************************************************************/
425 void TIM_DMAConfig(u16 TIM_DMASources, u16 TIM_OCRMState, u16 TIM_DMABase)
427 /* Select the DMA requests */
428 TIM0->RSR &= TIM_DMASources;
430 /* Set the OCRM state */
431 if(TIM_OCRMState == TIM_OCRMState_Enable)
433 TIM0->RSR |= TIM_OCRM_Set;
437 TIM0->RSR &= TIM_OCRM_Reset;
440 /* Set the DMA Base address */
441 TIM0->CR &= TIM_DBASE_Mask;
442 TIM0->CR |= TIM_DMABase;
445 /*******************************************************************************
446 * Function Name : TIM_DMACmd
447 * Description : Enables or disables the TIM0
\92s DMA interface.
448 * Input : - TIM_DMASources: specifies the DMA Request sources.
449 * This parameter can be any combination of the following values:
450 * - TIM_DMASource_OC1: Output Compare 1 DMA source
451 * - TIM_DMASource_OC2: Output Compare 2 DMA source
452 * - TIM_DMASource_IC1: Input Capture 1 DMA source
453 * - TIM_DMASource_IC2: Input Capture 2 DMA source
454 * - TIM_DMASource_Update: Timer Update DMA source
455 * - Newstate: new state of the DMA Request sources.
456 * This parameter can be: ENABLE or DISABLE.
459 *******************************************************************************/
460 void TIM_DMACmd(u16 TIM_DMASources, FunctionalState Newstate)
462 if(Newstate == ENABLE)
464 TIM0->RER |= TIM_DMASources;
468 TIM0->RER &= ~TIM_DMASources;
472 /*******************************************************************************
473 * Function Name : TIM_ClockSourceConfig
474 * Description : Configures the TIM clock source.
475 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
476 * - TIM_ClockSource: specifies the TIM clock source to be
478 * This parameter can be one of the following values:
479 * - TIM_ClockSource_Internal: CK_TIM internal clock
480 * - TIM_ClockSource_TI11: External input pin TI1
481 * connected to IC1 channel.
482 * - TIM_ClockSource_TI12: External input pin TI1
483 * connected to IC2 channel.
484 * - TIM_ClockSource_TI22: External input pin TI2
485 * connected to IC2 channel.
486 * - TIM_ClockSource_TI21: External input pin TI2
487 * connected to IC1 channel.
488 * - TIM_ExtCLKEdge: specifies the External input signal edge.
489 * This parameter can be one of the following values:
490 * - TIM_ExtCLKEdge_Falling : Falling edge selected.
491 * - TIM_ExtCLKEdge_Rising : Rising edge selected.
494 *******************************************************************************/
495 void TIM_ClockSourceConfig(TIM_TypeDef *TIMx, u16 TIM_ClockSource,
498 if(TIM_ClockSource == TIM_ClockSource_Internal)
500 /* CK_TIM is used as clock source */
501 TIMx->SCR &= TIM_SME_Reset & TIM_SlaveModeSelection_Mask & TIM_TriggerSelection_Mask;
504 /* Input Captures are used as TIM external clock */
506 TIMx->SCR &= TIM_SME_Reset & TIM_SlaveModeSelection_Mask & TIM_TriggerSelection_Mask;
507 TIMx->SCR |= TIM_SMS_EXTCLK_Set | TIM_SME_Set;
509 if((TIM_ClockSource == TIM_ClockSource_TI11) ||
510 (TIM_ClockSource == TIM_ClockSource_TI21))
511 /* Input Capture 1 is selected */
513 /* Input capture Enable */
514 TIMx->IMCR |= TIM_IC1_Enable;
515 TIMx->SCR |= TIM_TS_IC1_Set;
517 if(TIM_ExtCLKEdge == TIM_ExtCLKEdge_Falling)
518 /* Set the corresponding polarity */
520 TIMx->IMCR |= TIM_IC1P_Set;
524 TIMx->IMCR &= TIM_IC1P_Reset;
526 if(TIM_ClockSource == TIM_ClockSource_TI11)
528 /* External signal TI1 connected to IC1 channel */
529 TIMx->IMCR &= TIM_IC1S_Reset;
533 /* External signal TI2 connected to IC1 channel */
534 TIMx->IMCR |= TIM_IC1S_Set;
538 /* Input Capture 2 is selected */
540 /* Input capture Enable */
541 TIMx->IMCR |= TIM_IC2_Enable;
542 TIMx->SCR |= TIM_TS_IC2_Set;
544 if(TIM_ExtCLKEdge == TIM_ExtCLKEdge_Falling)
545 /* Set the corresponding polarity */
547 TIMx->IMCR |= TIM_IC2P_Set;
551 TIMx->IMCR &= TIM_IC2P_Reset;
553 if(TIM_ClockSource == TIM_ClockSource_TI22)
555 /* External signal TI2 connected to IC2 channel */
556 TIMx->IMCR &= TIM_IC2S_Reset;
560 /* External signal TI1 connected to IC2 channel */
561 TIMx->IMCR |= TIM_IC2S_Set;
567 /*******************************************************************************
568 * Function Name : TIM_SetPrescaler
569 * Description : Sets the TIM prescaler value.
570 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
571 * - Prescaler: TIM prescaler new value.
574 *******************************************************************************/
575 void TIM_SetPrescaler(TIM_TypeDef* TIMx, u16 Prescaler)
577 TIMx->PSC = Prescaler;
580 /*******************************************************************************
581 * Function Name : TIM_SetPeriod
582 * Description : Sets the TIM period value.
583 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
584 * - Period: TIM period new value.
587 *******************************************************************************/
588 void TIM_SetPeriod(TIM_TypeDef* TIMx, u16 Period)
593 /*******************************************************************************
594 * Function Name : TIM_SetPulse
595 * Description : Sets the TIM pulse value.
596 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
597 * - TIM_Channel: specifies the TIM channel to be used.
598 * This parameter can be one of the following values:
599 * - TIM_Channel_1: TIM Channel 1 is used
600 * - TIM_Channel_2: TIM Channel 2 is used
601 * - TIM_Channel_ALL: TIM Channel 1and 2 are used
602 * - Pulse: TIM pulse new value.
605 *******************************************************************************/
606 void TIM_SetPulse(TIM_TypeDef* TIMx, u16 TIM_Channel, u16 Pulse)
608 /* Set Channel 1 pulse value */
609 if(TIM_Channel == TIM_Channel_1)
613 /* Set Channel 2 pulse value */
614 else if(TIM_Channel == TIM_Channel_2)
618 /* Set Channel 1 and Channel 2 pulse values */
619 else if(TIM_Channel == TIM_Channel_ALL)
626 /*******************************************************************************
627 * Function Name : TIM_GetICAP1
628 * Description : Gets the Input Capture 1 value.
629 * Input : TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
631 * Return : Input Capture 1 Register value.
632 *******************************************************************************/
633 u16 TIM_GetICAP1(TIM_TypeDef *TIMx)
638 /*******************************************************************************
639 * Function Name : TIM_GetICAP2
640 * Description : Gets the Input Capture 2 value.
641 * Input : TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
643 * Return : Input Capture 2 Register value
644 *******************************************************************************/
645 u16 TIM_GetICAP2(TIM_TypeDef *TIMx)
650 /*******************************************************************************
651 * Function Name : TIM_GetPWMIPulse
652 * Description : Gets the PWM Input pulse value.
653 * Input : TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
655 * Return : Input Capture 2 Register value
656 *******************************************************************************/
657 u16 TIM_GetPWMIPulse(TIM_TypeDef *TIMx)
662 /*******************************************************************************
663 * Function Name : TIM_GetPWMIPeriod
664 * Description : Gets the PWM Input period value.
665 * Input : TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
667 * Return : Input Capture 1 Register value
668 *******************************************************************************/
669 u16 TIM_GetPWMIPeriod(TIM_TypeDef *TIMx)
674 /*******************************************************************************
675 * Function Name : TIM_DebugCmd
676 * Description : Enables or disables the specified TIM peripheral Debug control.
677 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
678 * - Newstate: new state of the TIMx Debug control.
679 This parameter can be: ENABLE or DISABLE.
682 *******************************************************************************/
683 void TIM_DebugCmd(TIM_TypeDef *TIMx, FunctionalState Newstate)
685 if(Newstate == ENABLE)
687 TIMx->CR |= TIM_DBGC_Set;
691 TIMx->CR &= TIM_DBGC_Reset;
695 /*******************************************************************************
696 * Function Name : TIM_CounterModeConfig
697 * Description : Specifies the Counter Mode to be used.
698 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
699 * - TIM_CounterMode: specifies the Counter Mode to be used
700 * This parameter can be one of the following values:
701 * - TIM_CounterMode_Up: TIM Up Counting Mode
702 * - TIM_CounterMode_Down: TIM Down Counting Mode
703 * - TIM_CounterMode_CenterAligned1: TIM Center Aligned Mode1
704 * - TIM_CounterMode_CenterAligned2: TIM Center Aligned Mode2
705 * - TIM_CounterMode_CenterAligned3: TIM Center Aligned Mode3
708 *******************************************************************************/
709 void TIM_CounterModeConfig(TIM_TypeDef* TIMx, u16 TIM_CounterMode)
711 /* Counter mode configuration */
712 TIMx->CR &= TIM_CounterMode_Mask;
713 TIMx->CR |= TIM_CounterMode;
716 /*******************************************************************************
717 * Function Name : TIM_ForcedOCConfig
718 * Description : Forces the TIM output waveform to active or inactive level.
719 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
720 * - TIM_Channel: specifies the TIM channel to be used.
721 * This parameter can be one of the following values:
722 * - TIM_Channel_1: Timer Channel 1 is used
723 * - TIM_Channel_2: Timer Channel 2 is used
724 * - TIM_Channel_ALL: Timer Channel 1 and 2 are used
725 * - TIM_ForcedAction: specifies the forced Action to be set to
726 * the output waveform.
727 * This parameter can be one of the following values:
728 * - TIM_ForcedAction_Active: Force active level on OCxREF
729 * - TIM_ForcedAction_InActive: Force inactive level on
733 *******************************************************************************/
734 void TIM_ForcedOCConfig(TIM_TypeDef* TIMx, u16 TIM_Channel,u16 TIM_ForcedAction)
736 /* Channel 1 Forced Output Compare mode configuration */
737 if(TIM_Channel == TIM_Channel_1)
739 TIMx->OMR1 &= TIM_OC1C_Mask;
740 TIMx->OMR1 |= TIM_ForcedAction;
742 /* Channel 2 Forced Output Compare mode configuration */
745 if(TIM_Channel == TIM_Channel_2)
747 TIMx->OMR1 &= TIM_OC2C_Mask;
748 TIMx->OMR1 |= (TIM_ForcedAction<<8);
750 /* Channel 1 and Channel 2 Forced Output Compare mode configuration */
753 TIMx->OMR1 &= TIM_OC1C_Mask & TIM_OC2C_Mask;
754 TIMx->OMR1 |= TIM_ForcedAction |(TIM_ForcedAction<<8);
759 /*******************************************************************************
760 * Function Name : TIM_ResetCounter
761 * Description : Re-intializes the TIM counter and generates an update of the
763 * Input : TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
766 *******************************************************************************/
767 void TIM_ResetCounter(TIM_TypeDef* TIMx)
769 /* Re-intialize the TIM counter */
770 TIMx->CR |= TIM_COUNTER_Reset;
773 /*******************************************************************************
774 * Function Name : TIM_SynchroConfig
775 * Description : Synchronizes two Timers in a specified mode.
776 * Input : - Master: specifies the peripheral master.
777 * This parameter can be one of the following values:
778 * PWM_Master, TIM0_Master, TIM1_Master or TIM2_Master.
779 * - Slave: specifies the peripheral slave.
780 * This parameter can be one of the following values:
781 * PWM_Slave, TIM0_Slave, TIM1_Slave or TIM2_Slave.
782 * - TIM_SynchroAction: specifies the synchronization Action to
784 * This parameter can be one of the following values:
785 * - TIM_SynchroAction_Enable: The CNT_EN bit is used as TRGO
786 * - TIM_SynchroAction_Update: The Update event is used as TRGO
787 * - TIM_SynchroAction_Reset: The CNT_RST bit is used as TRGO
788 * - TIM_SynchroAction_OC: The OC1 signal is used as TRGO
789 * - TIM_SynchroMode: specifies the synchronization Mode to be used.
790 * This parameter can be one of the following values:
791 * - TIM_SynchroMode_Gated: Both start and stop of the
792 * counter is controlled.
793 * - TIM_SynchroMode_Trigger: Only the start of the
794 * counter is controlled.
795 * - TIM_SynchroMode_External: The rising edge of selected trigger
796 * clocks the counter.
797 * - TIM_SynchroMode_Reset: The rising edge of the selected trigger
798 * signal resets the counter and generates an update of the registers.
801 *******************************************************************************/
802 void TIM_SynchroConfig(Master_TypeDef Master, Slave_TypeDef Slave,
803 u16 TIM_SynchroAction, u16 TIM_SynchroMode)
809 PWM->SCR &= TIM_SME_Reset & TIM_TriggerSelection_Mask & TIM_SlaveModeSelection_Mask &
810 TIM_InternalTriggerSelection_Mask;
811 PWM->SCR |= TIM_SynchroMode | TIM_SME_Set;
813 if(Master == TIM1_Master)
815 /* Set the internal trigger */
816 PWM->SCR |= TIM_ITS_TIM1;
818 /* Set the synchronization action */
819 TIM1->CR &= TIM_MasterModeSelection_Mask;
820 TIM1->CR |= TIM_SynchroAction;
823 else if(Master == TIM0_Master)
825 /* Set the internal trigger */
826 PWM->SCR |= TIM_ITS_TIM0;
828 /* Set the synchronization action */
829 TIM0->CR &= TIM_MasterModeSelection_Mask;
830 TIM0->CR |= TIM_SynchroAction;
833 else if(Master == TIM2_Master)
835 /* Set the internal trigger */
836 PWM->SCR |= TIM_ITS_TIM2;
838 /* Set the synchronization action */
839 TIM2->CR &= TIM_MasterModeSelection_Mask;
840 TIM2->CR |= TIM_SynchroAction;
847 TIM0->SCR &= TIM_SME_Reset & TIM_TriggerSelection_Mask & TIM_SlaveModeSelection_Mask &
848 TIM_InternalTriggerSelection_Mask;
849 TIM0->SCR |= TIM_SynchroMode | TIM_SME_Set;
851 if(Master == PWM_Master)
853 /* Set the internal trigger */
854 TIM0->SCR |= TIM_ITS_PWM;
856 /* Set the synchronization action */
857 PWM->CR &= TIM_MasterModeSelection_Mask;
858 PWM->CR |= TIM_SynchroAction;
861 else if(Master == TIM1_Master)
863 /* Set the internal trigger */
864 TIM0->SCR |= TIM_ITS_TIM1;
866 /* Set the synchronization action */
867 TIM1->CR &= TIM_MasterModeSelection_Mask;
868 TIM1->CR |= TIM_SynchroAction;
871 else if(Master == TIM2_Master)
873 /* Set the internal trigger */
874 TIM0->SCR |= TIM_ITS_TIM2;
876 /* Set the synchronization action */
877 TIM2->CR &= TIM_MasterModeSelection_Mask;
878 TIM2->CR |= TIM_SynchroAction;
886 TIM1->SCR &= TIM_SME_Reset & TIM_TriggerSelection_Mask & TIM_SlaveModeSelection_Mask &
887 TIM_InternalTriggerSelection_Mask;
888 TIM1->SCR |= TIM_SynchroMode | TIM_SME_Set;
890 if(Master == PWM_Master)
892 /* Set the internal trigger */
893 TIM1->SCR |= TIM_ITS_PWM;
895 /* Set the synchronization action */
896 PWM->CR &= TIM_MasterModeSelection_Mask;
897 PWM->CR |= TIM_SynchroAction;
899 else if(Master == TIM0_Master)
901 /* Set the internal trigger */
902 TIM1->SCR |= TIM_ITS_TIM0;
904 /* Set the synchronization action */
905 TIM0->CR &= TIM_MasterModeSelection_Mask;
906 TIM0->CR |= TIM_SynchroAction;
909 else if(Master == TIM2_Master)
911 /* Set the internal trigger */
912 TIM1->SCR |= TIM_ITS_TIM2;
914 /* Set the synchronization action */
915 TIM2->CR &= TIM_MasterModeSelection_Mask;
916 TIM2->CR |= TIM_SynchroAction;
924 TIM2->SCR &= TIM_SME_Reset & TIM_TriggerSelection_Mask & TIM_SlaveModeSelection_Mask &
925 TIM_InternalTriggerSelection_Mask;
926 TIM2->SCR |= TIM_SynchroMode | TIM_SME_Set;
928 if(Master == PWM_Master)
930 /* Internal trigger selection */
931 TIM2->SCR |= TIM_ITS_PWM;
933 /* Set the synchronization action */
934 PWM->CR &= TIM_MasterModeSelection_Mask;
935 PWM->CR |= TIM_SynchroAction;
938 else if(Master == TIM1_Master)
940 /* Internal trigger selection */
941 TIM2->SCR |= TIM_ITS_TIM1;
943 /* Set the synchronization action */
944 TIM1->CR &= TIM_MasterModeSelection_Mask;
945 TIM1->CR |= TIM_SynchroAction;
948 else if(Master == TIM0_Master)
950 /* Internal trigger selection */
951 TIM2->SCR |= TIM_ITS_TIM0;
953 /* Set the synchronization action */
954 TIM0->CR &= TIM_MasterModeSelection_Mask;
955 TIM0->CR |= TIM_SynchroAction;
965 /*******************************************************************************
966 * Function Name : TIM_GetFlagStatus
967 * Description : Checks whether the specified TIM flag is set or not.
968 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
969 * - TIM_FLAG: specifies the flag to check.
970 * This parameter can be one of the following values:
971 * - TIM_FLAG_IC1: Input Capture 1 Flag
972 * - TIM_FLAG_OC1: Output Compare 1 Flag
973 * - TIM_FLAG_Update: Timer update Flag
974 * - TIM_FLAG_IC2: Input Capture 2 Flag
975 * - TIM_FLAG_OC2: Output Compare 2 Flag
977 * Return : The new state of TIM_FLAG (SET or RESET).
978 *******************************************************************************/
979 FlagStatus TIM_GetFlagStatus(TIM_TypeDef* TIMx, u16 TIM_FLAG)
981 if((TIMx->ISR & TIM_FLAG) != RESET )
991 /*******************************************************************************
992 * Function Name : TIM_ClearFlag
993 * Description : Clears the TIMx's pending flags.
994 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
995 * - TIM_FLAG: specifies the flag bit to clear.
996 * This parameter can be any combination of the following values:
997 * - TIM_FLAG_IC1: Timer Input Capture 1 flag
998 * - TIM_FLAG_OC1: Timer Output Compare 1 flag
999 * - TIM_FLAG_Update: Timer update flag
1000 * - TIM_FLAG_IC2: Timer Input Capture 2 flag
1001 * - TIM_FLAG_OC2: Timer Output Compare 2 flag
1004 *******************************************************************************/
1005 void TIM_ClearFlag(TIM_TypeDef* TIMx, u16 TIM_FLAG)
1007 /* Clear the flags */
1008 TIMx->ISR &= ~TIM_FLAG;
1011 /*******************************************************************************
1012 * Function Name : TIM_GetITStatus
1013 * Description : Checks whether the specified TIM interrupt has occurred or not.
1014 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
1015 * - TIM_IT: specifies the TIM interrupt source to check.
1016 * This parameter can be one of the following values:
1017 * - TIM_IT_IC1: Input Capture 1 interrupt
1018 * - TIM_IT_OC1: Output Compare 1 interrupt
1019 * - TIM_IT_Update: Timer update interrupt
1020 * - TIM_IT_GlobalUpdate: Timer global update interrupt
1021 * - TIM_IT_IC2: Input Capture 2 interrupt
1022 * - TIM_IT_OC2: Output Compare 2 interrupt
1024 * Return : The new state of TIM_IT(SET or RESET).
1025 *******************************************************************************/
1026 ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, u16 TIM_IT)
1028 u16 TIM_IT_Check = 0;
1030 /* Calculates the pending bits to be checked */
1031 TIM_IT_Check = TIM_IT & TIM_IT_Clear_Mask;
1033 if((TIMx->ISR & TIM_IT_Check) != RESET )
1043 /*******************************************************************************
1044 * Function Name : TIM_ClearITPendingBit
1045 * Description : Clears the TIM's interrupt pending bits.
1046 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
1047 * - TIM_IT: specifies the interrupt pending bit to clear.
1048 * This parameter can be one of the following values:
1049 * - TIM_IT_IC1: Input Capture 1 Interrupt
1050 * - TIM_IT_OC1: Output Compare 1 Interrupt
1051 * - TIM_IT_Update: Timer update Interrupt
1052 * - TIM_IT_GlobalUpdate: Timer global update Interrupt
1053 * - TIM_IT_IC2: Input Capture 2 Interrupt
1054 * - TIM_IT_OC2: Output Compare 2 Interrupt
1057 *******************************************************************************/
1058 void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, u16 TIM_IT)
1060 u16 TIM_IT_Clear = 0;
1062 /* Calculate the pending bits to be cleared */
1063 TIM_IT_Clear = TIM_IT & TIM_IT_Clear_Mask;
1065 /* Clear the pending bits */
1066 TIMx->ISR &= ~TIM_IT_Clear;
1069 /*******************************************************************************
1070 * Function Name : OCM_ModuleConfig
1071 * Description : Output Compare Module configuration
1072 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
1073 * - TIM_InitStruct: pointer to a TIM_InitTypeDef structure that
1074 * contains the configuration information for the specified TIM
1078 *******************************************************************************/
1079 static void OCM_ModuleConfig(TIM_TypeDef* TIMx, TIM_InitTypeDef* TIM_InitStruct)
1081 u16 TIM_OCControl = 0x0000;
1083 if(TIM_InitStruct->TIM_Mode == TIM_Mode_OCTiming)
1085 TIM_OCControl = TIM_OCControl_OCTiming;
1089 if((TIM_InitStruct->TIM_Mode == TIM_Mode_OCActive) ||
1090 (TIM_InitStruct->TIM_Mode == TIM_Mode_OPM_Active))
1092 TIM_OCControl = TIM_OCControl_OCActive;
1096 if(TIM_InitStruct->TIM_Mode == TIM_Mode_OCInactive)
1098 TIM_OCControl = TIM_OCControl_OCInactive;
1102 if((TIM_InitStruct->TIM_Mode == TIM_Mode_OCToggle) ||
1103 (TIM_InitStruct->TIM_Mode == TIM_Mode_OPM_Toggle))
1105 TIM_OCControl = TIM_OCControl_OCToggle;
1109 TIM_OCControl = TIM_OCControl_PWM;
1116 if(TIM_InitStruct->TIM_Channel == TIM_Channel_1)
1118 /* Configure Channel 1 on Output Compare mode */
1119 TIMx->OMR1 &= TIM_OC1C_Mask;
1120 TIMx->OMR1 |= TIM_OCControl|TIM_OC1_Enable;
1121 TIMx->OMR1 |= TIM_PLD1_Set;
1122 TIMx->OCR1 = TIM_InitStruct->TIM_Pulse1;
1124 /* Set the OC1 wave polarity */
1125 if(TIM_InitStruct->TIM_Polarity1 == TIM_Polarity1_Low)
1127 TIMx->OMR1 |= TIM_OC1P_Set;
1131 TIMx->OMR1 &= TIM_OC1P_Reset;
1136 if(TIM_InitStruct->TIM_Channel == TIM_Channel_2)
1138 /* Configure Channel 2 on Output Compare mode */
1139 TIMx->OMR1 &= TIM_OC2C_Mask;
1140 TIMx->OMR1 |= TIM_OCControl<<8|TIM_OC2_Enable;
1141 TIMx->OMR1 |= TIM_PLD2_Set;
1142 TIMx->OCR2 = TIM_InitStruct->TIM_Pulse2;
1144 /* Set the OCB wave polarity */
1145 if(TIM_InitStruct->TIM_Polarity2 == TIM_Polarity2_Low)
1147 TIMx->OMR1 |= TIM_OC2P_Set;
1151 TIMx->OMR1 &= TIM_OC2P_Reset;
1154 /* Configure Channel 1 and Channel 2 on Output Compare mode */
1157 TIMx->OMR1 &= TIM_OC1C_Mask & TIM_OC2C_Mask;
1158 TIMx->OMR1 |= TIM_OCControl|(TIM_OCControl<<8)|TIM_OC1_Enable|TIM_OC2_Enable|
1159 TIM_PLD1_Set|TIM_PLD2_Set;
1161 TIMx->OCR1 = TIM_InitStruct->TIM_Pulse1;
1162 TIMx->OCR2 = TIM_InitStruct->TIM_Pulse2;
1164 /* Set the OC1 wave polarity */
1165 if(TIM_InitStruct->TIM_Polarity1 == TIM_Polarity1_Low)
1167 TIMx->OMR1 |= TIM_OC1P_Set;
1171 TIMx->OMR1 &= TIM_OC1P_Reset;
1174 /* Set the OC2 wave polarity */
1175 if(TIM_InitStruct->TIM_Polarity2 == TIM_Polarity2_Low)
1177 TIMx->OMR1 |= TIM_OC2P_Set;
1181 TIMx->OMR1 &= TIM_OC2P_Reset;
1187 /*******************************************************************************
1188 * Function Name : ICAP_ModuleConfig
1189 * Description : Input Capture Module configuration
1190 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
1191 * - TIM_InitStruct: pointer to a TIM_InitTypeDef structure that
1192 * contains the configuration information for the specified TIM
1196 *******************************************************************************/
1197 static void ICAP_ModuleConfig(TIM_TypeDef* TIMx, TIM_InitTypeDef* TIM_InitStruct)
1199 if(TIM_InitStruct->TIM_Mode == TIM_Mode_PWMI)
1200 { /* PWM input mode configuration */
1201 TIMx->SCR |= TIM_TS_IC1_Set|TIM_SMS_RESETCLK_Set|TIM_SME_Set;
1203 /* Channel 1 and channel 2 input selection */
1204 if(TIM_InitStruct->TIM_PWMI_ICSelection == TIM_PWMI_ICSelection_TI1)
1206 TIMx->IMCR &= TIM_IC1S_Reset;
1207 TIMx->IMCR |= TIM_IC2S_Set;
1211 TIMx->IMCR |= TIM_IC1S_Set;
1212 TIMx->IMCR &= TIM_IC2S_Reset;
1215 /* Channel polarity */
1216 if(TIM_InitStruct->TIM_PWMI_ICPolarity == TIM_PWMI_ICPolarity_Rising)
1218 TIMx->IMCR &= TIM_IC1P_Reset;
1219 TIMx->IMCR |= TIM_IC2P_Set;
1223 TIMx->IMCR |= TIM_IC1P_Set;
1224 TIMx->IMCR &= TIM_IC2P_Reset;
1227 /* Input capture Enable */
1228 TIMx->IMCR |= TIM_IC1_Enable |TIM_IC2_Enable;
1232 if(TIM_InitStruct->TIM_Channel == TIM_Channel_1)
1234 /* Input Capture 1 mode configuration */
1235 TIMx->SCR &= TIM_TriggerSelection_Mask & TIM_SlaveModeSelection_Mask;
1236 TIMx->SCR |= TIM_TS_IC1_Set|TIM_SMS_RESETCLK_Set|TIM_SME_Set;
1238 /* Channel 1 input selection */
1239 if(TIM_InitStruct->TIM_IC1Selection == TIM_IC1Selection_TI1)
1241 TIMx->IMCR &= TIM_IC1S_Reset;
1245 TIMx->IMCR |= TIM_IC1S_Set;
1247 /* Channel 1 polarity */
1248 if(TIM_InitStruct->TIM_IC1Polarity == TIM_IC1Polarity_Rising)
1250 TIMx->IMCR &= TIM_IC1P_Reset;
1254 TIMx->IMCR |= TIM_IC1P_Set;
1257 /* Input capture Enable */
1258 TIMx->IMCR |= TIM_IC1_Enable;
1262 /* Input Capture 2 mode configuration */
1263 TIMx->SCR &= (TIM_TriggerSelection_Mask & TIM_SlaveModeSelection_Mask);
1264 TIMx->SCR |= TIM_TS_IC2_Set|TIM_SMS_RESETCLK_Set|TIM_SME_Set;
1266 /* Channel 2 input selection */
1267 if(TIM_InitStruct->TIM_IC2Selection == TIM_IC2Selection_TI2)
1269 TIMx->IMCR &= TIM_IC2S_Reset;
1273 TIMx->IMCR |= TIM_IC2S_Set;
1276 /* Channel 2 polarity */
1277 if(TIM_InitStruct->TIM_IC2Polarity == TIM_IC2Polarity_Rising)
1279 TIMx->IMCR &= TIM_IC2P_Reset;
1283 TIMx->IMCR |= TIM_IC2P_Set;
1286 /* Input capture Enable */
1287 TIMx->IMCR |= TIM_IC2_Enable;
1292 /*******************************************************************************
1293 * Function Name : Encoder_ModeConfig
1294 * Description : Encoder Mode configuration
1295 * Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
1296 * - TIM_InitStruct: pointer to a TIM_InitTypeDef structure that
1297 * contains the configuration information for the specified TIM
1301 *******************************************************************************/
1302 static void Encoder_ModeConfig(TIM_TypeDef* TIMx, TIM_InitTypeDef* TIM_InitStruct)
1304 /* Set Encoder mode */
1305 TIMx->SCR &= TIM_Encoder_Mask;
1307 if(TIM_InitStruct->TIM_Mode == TIM_Mode_Encoder1)
1309 TIMx->SCR |= TIM_Encoder1_Set;
1311 else if (TIM_InitStruct->TIM_Mode == TIM_Mode_Encoder2)
1313 TIMx->SCR |= TIM_Encoder2_Set;
1317 TIMx->SCR |= TIM_Encoder3_Set;
1320 /* Channel 1 input selection */
1321 if(TIM_InitStruct->TIM_IC1Selection == TIM_IC1Selection_TI2)
1323 TIMx->IMCR |= TIM_IC1S_Set;
1327 TIMx->IMCR &= TIM_IC1S_Reset;
1330 /* Channel 2 input selection */
1331 if(TIM_InitStruct->TIM_IC2Selection == TIM_IC2Selection_TI1)
1333 TIMx->IMCR |= TIM_IC2S_Set;
1337 TIMx->IMCR &= TIM_IC2S_Reset;
1340 /* Channel 1 polarity */
1341 if(TIM_InitStruct->TIM_IC1Polarity == TIM_IC1Polarity_Falling)
1343 TIMx->IMCR |= TIM_IC1P_Set;
1347 TIMx->IMCR &= TIM_IC1P_Reset;
1350 /* Channel 2 polarity */
1351 if(TIM_InitStruct->TIM_IC2Polarity == TIM_IC2Polarity_Falling)
1353 TIMx->IMCR |= TIM_IC2P_Set;
1357 TIMx->IMCR &= TIM_IC2P_Reset;
1360 /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/