AnsweredAssumed Answered

Configure channel3 Timer2

Question asked by guif on Sep 10, 2013
Latest reply on Sep 11, 2013 by guif
Hi,

For the moment I am using the channel2 of the Timer 2 in capture mode. At each rising edge of the signal, the timer is captured and reseted; It works fine;
My code is this following:
01.GPIO_InitTypeDef GPIO_InitStructure;
02.    /* GPIOC Periph clock enable */
03.    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
04. 
05.    /* Configure PB10 in input*/
06.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 ;
07.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
08.    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
09.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
10.    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
11.    GPIO_Init(GPIOB, &GPIO_InitStructure);
12. 
13.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_TIM2);
14. 
15.    /* Enable the TIM2 global Interrupt */
16.        //configure NVIC
17.        //select NVIC channel to configure
18.        NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
19.        //set priority to highest
20.        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
21.        //set sub-priority to highest
22.        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;
23.        //enable IRQ channel
24.        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
25.        //update NVIC registers
26.        NVIC_Init(&NVIC_InitStructure);
27. 
28.
    // Timerx Periph clock enable
34.    RCC_APB1PeriphClockCmd( SYNCH_TIMER_CLK, ENABLE );
35.    // Configures the Timerx internal Clock
36.    TIM_InternalClockConfig ( SYNCH_TIMER_BASE );

42.    TIM_DeInit( SYNCH_TIMER_BASE );
43.    TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
44.    TIM_TimeBaseStructure.TIM_Prescaler = TIM_ICPSC_DIV1;
45.    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
46.    TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
47.    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
48.    // Initializes the Timerx Time Base Unit peripheral
49.    TIM_TimeBaseInit( SYNCH_TIMER_BASE, &TIM_TimeBaseStructure );
50. 
51.    TIM_ICInitStructure.TIM_Channel     = TIM_Channel_2;
52.    TIM_ICInitStructure.TIM_ICPolarity  = TIM_ICPolarity_Rising;
53.    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
54.    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
55.    TIM_ICInitStructure.TIM_ICFilter = 0x0;
56.    TIM_ICInit(SYNCH_TIMER_BASE, &TIM_ICInitStructure);
57. 
58.    TIM_SelectSlaveMode(SYNCH_TIMER_BASE , TIM_SlaveMode_Reset);
59.//
60.//  SYNCH_TIMER_BASE->SMCR |= 0x04; /* timer in reset mode */
61.//  SYNCH_TIMER_BASE->SMCR |= 0x70;
62.//  SYNCH_TIMER_BASE->SMCR |= 0x80;
63.//  TIM_SelectMasterSlaveMode(SYNCH_TIMER_BASE , TIM_MasterSlaveMode_Enable);
64.//
65. 
66.    /* TIM enable counter */
67.    TIM_Cmd(SYNCH_TIMER_BASE, ENABLE);
68. 
69.    /* DISABLE the CC2 Interrupt Request */
70.    TIM_ITConfig(SYNCH_TIMER_BASE, TIM_IT_CC2, ENABLE);

Now I would like to use the channel 3 , so My configuration is this following:
01.GPIO_InitTypeDef GPIO_InitStructure;
02.    /* GPIOC Periph clock enable */
03.    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
04. 
05.    /* Configure PB10 in input*/
06.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ;
07.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
08.    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
09.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
10.    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
11.    GPIO_Init(GPIOB, &GPIO_InitStructure);
12. 
13.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_TIM2);
14. 
15.    /* Enable the TIM2 global Interrupt */
16.        //configure NVIC
17.        //select NVIC channel to configure
18.        NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
19.        //set priority to highest
20.        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
21.        //set sub-priority to highest
22.        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;
23.        //enable IRQ channel
24.        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
25.        //update NVIC registers
26.        NVIC_Init(&NVIC_InitStructure);
27. 
28. 
29.    // Timerx Periph clock enable
30.    RCC_APB1PeriphClockCmd( SYNCH_TIMER_CLK, ENABLE );
31.    // Configures the Timerx internal Clock
32.    TIM_InternalClockConfig ( SYNCH_TIMER_BASE );
33.     
34. 
35.    TIM_DeInit( SYNCH_TIMER_BASE );
36.    TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
37.    TIM_TimeBaseStructure.TIM_Prescaler = TIM_ICPSC_DIV1;
38.    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
39.    TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
40.    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
41.    // Initializes the Timerx Time Base Unit peripheral
42.    TIM_TimeBaseInit( SYNCH_TIMER_BASE, &TIM_TimeBaseStructure );
43. 
44.    /*TIMx_CCR3 must be linked to the TI3 input*/
45.    SYNCH_TIMER_BASE->CCMR2 |= 0x01; /* CC3S = 01 :: IC3 is mapped on TI3 */
46.     
47.    TIM_ICInitStructure.TIM_Channel     = TIM_Channel_3;
48.    TIM_ICInitStructure.TIM_ICPolarity  = TIM_ICPolarity_Rising;
49.    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
50.    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
51.    TIM_ICInitStructure.TIM_ICFilter = 0x0;
52.    TIM_ICInit(SYNCH_TIMER_BASE, &TIM_ICInitStructure);
53. 
54.    TIM_SelectSlaveMode(SYNCH_TIMER_BASE , TIM_SlaveMode_Reset);
55. 
56.    /* TIM enable counter */
57.    TIM_Cmd(SYNCH_TIMER_BASE, ENABLE);
58. 
59.    /* DISABLE the CC3 Interrupt Request */
60.    TIM_ITConfig(SYNCH_TIMER_BASE, TIM_IT_CC3, ENABLE);

but with the channel 3, the reset mode doesn't work.
I don't understand why. Is it possible to do the same thing with channels 1/2 and channels 3/4 ?

Thank you very much,
GF.

Outcomes