cancel
Showing results for 
Search instead for 
Did you mean: 

TimerX chain or master example

stst9184
Associate II
Posted on October 30, 2012 at 10:10

I want to measure distance between two pulses, pulses come from an another timer. Ist there any example for it?

#timer-master-slave
3 REPLIES 3
stst9184
Associate II
Posted on October 30, 2012 at 11:53

This is not yet working:(

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

    /* Timer 4 is encoder

       Timer 2 is speed measurement

     */  

    TIM_DeInit(TIM4);

    TIM_DeInit(TIM2);

    // Configure the timer

    TIM_EncoderInterfaceConfig(TIM4, TIM_EncoderMode_TI12,

                             TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);

    /*NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = TIMx_PRE_EMPTION_PRIORITY;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = TIMx_SUB_PRIORITY;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    

    TIM_ClearFlag(TIM4, TIM_FLAG_Update);

    TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);*/

    

    /* Select the Master Slave Mode */

    TIM_SelectMasterSlaveMode(TIM4, TIM_MasterSlaveMode_Enable);

    /* Master Mode selection */

    TIM_SelectOutputTrigger(TIM4, TIM_TRGOSource_OC1Ref);

    

    

    /* Slaves Configuration:  */

    

    TIM_TimeBaseInitTypeDef     TIM_TimeBaseStructure;

    TIM_ICInitTypeDef           TIM_ICInitStructure;

    

    TIM_TimeBaseStructure.TIM_Period            = 65535;

    TIM_TimeBaseStructure.TIM_Prescaler         = 0;

    TIM_TimeBaseStructure.TIM_ClockDivision     = 0;

    TIM_TimeBaseStructure.TIM_CounterMode       = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

        

    TIM_ICInitStructure.TIM_Channel             = TIM_Channel_1;

    TIM_ICInitStructure.TIM_ICPolarity          = TIM_ICPolarity_BothEdge;

    TIM_ICInitStructure.TIM_ICSelection         = TIM_ICSelection_TRC;

    TIM_ICInitStructure.TIM_ICPrescaler         = TIM_ICPSC_DIV1;

    TIM_ICInitStructure.TIM_ICFilter            = 0x0;

    TIM_ICInit(TIM2, &TIM_ICInitStructure);

    

    /* Select the slave Mode: Reset Mode */

    TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);

    TIM_SelectInputTrigger(TIM2, TIM_TS_ITR2);

    /* Enable the Master/Slave Mode */

    TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);

    

    // TIM2, TIM4 counter enable

    TIM_Cmd(TIM2, ENABLE);

    TIM_Cmd(TIM4, ENABLE);

Posted on October 30, 2012 at 12:14

How exactly is it not working?

JW
stst9184
Associate II
Posted on October 30, 2012 at 12:38

Hi Jan,

I want to reset a timer 2 on any edge going out from timer 4. Byt timer 2 incremnets up to max.