cancel
Showing results for 
Search instead for 
Did you mean: 

Timer prescaler doesn't work

sdianoff
Associate II
Posted on July 06, 2015 at 05:19

Timer works in Input capture mode. It captures period of rectangular wave. I would like to get interrupt on each eighth front, but interrupt does not dependent of prescaler. Controller: stm32f030f6p6. There is code fragment indicatind problem.

&sharpdefine TIMER_TEMP TIM2

&sharpdefine TIMER_HUM TIM3

&sharpdefine GET_PERIOD_TEMP (TIM_GetCapture2(TIMER_TEMP))

&sharpdefine GET_PERIOD_HUM (TIM_GetCapture1(TIMER_HUM))

int temp = 0;

int hum = 0;

void PeriphInit(void)

{

        GPIO_InitTypeDef gpio;

        TIM_TimeBaseInitTypeDef tim;

        TIM_ICInitTypeDef timIn;

        

        NVIC_InitTypeDef nvic;

          

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3, ENABLE);

        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

           GPIO_StructInit(&gpio);

   gpio.GPIO_Pin=GPIO_Pin_1;

   gpio.GPIO_Mode=GPIO_Mode_AF;

   gpio.GPIO_Speed=GPIO_Speed_50MHz;

   gpio.GPIO_OType = GPIO_OType_PP;

   gpio.GPIO_PuPd  = GPIO_PuPd_NOPULL;

   GPIO_Init(GPIOA,&gpio);

        GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_2);

        TIM_TimeBaseStructInit(&tim);

   tim.TIM_Prescaler = (SystemCoreClock/12000000)-1;

   tim.TIM_Period =  0xFFFFFFFF;

   tim.TIM_CounterMode = TIM_CounterMode_Up;

   TIM_TimeBaseInit(TIMER_TEMP, &tim);

   timIn.TIM_Channel = TIM_Channel_2;

   timIn.TIM_ICPolarity = TIM_ICPolarity_Rising;

   timIn.TIM_ICSelection = TIM_ICSelection_DirectTI;

   timIn.TIM_ICPrescaler = TIM_ICPSC_DIV4;//This prescaler doesn't work

   timIn.TIM_ICFilter = 0x0;

   TIM_SelectInputTrigger(TIMER_TEMP, TIM_TS_TI2FP2);

   TIM_SelectSlaveMode(TIMER_TEMP, TIM_SlaveMode_Reset);

   TIM_PWMIConfig(TIMER_TEMP, &timIn);

        TIM_SetCounter(TIMER_TEMP, 0); 

        nvic.NVIC_IRQChannel=TIM2_IRQn;

        nvic.NVIC_IRQChannelPriority = 0;

        nvic.NVIC_IRQChannelCmd = DISABLE;

        NVIC_Init(&nvic);

        NVIC_EnableIRQ(TIM2_IRQn);

        TIM_ITConfig(TIMER_TEMP, TIM_IT_CC2, ENABLE);

        TIM_Cmd(TIMER_TEMP, ENABLE);

}

void TIM2_IRQHandler()

{

    temp = GET_PERIOD_TEMP;

    TIM_ClearITPendingBit(TIMER_TEMP, TIM_FLAG_CC2);

}

int main()

{

    PeriphInit(); 

    while (1);

}

#timer
0 REPLIES 0