This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

pwm input mode low frequncy

hi

i work with stm32f107

pleas answer me

how i can measure frequency in 50 hz with input pwm

i read about it and find out i can measure frequency with input pwm up to 1100
but input pwm have TIM_ICPrescaler that i think devide pwm frequncy

it is true ?

if no , please say me how i can measure 50 hz?

Parents
  • For a start off, forget about microcontrollers.

    Think about what are the basic principles of frequency measurement:

    - what do you need to detect?

    - what do you need to measure?

    - how do you deduce frequency from the measurement(s)?

    If you don't understand the fundamental principles, you won't be able to implement them - whether with a microcontroller or anything else!

    Once you do understand the fundamental principles, then you can look at the features available on your microcontroller, and see which will be useful ...

Reply
  • For a start off, forget about microcontrollers.

    Think about what are the basic principles of frequency measurement:

    - what do you need to detect?

    - what do you need to measure?

    - how do you deduce frequency from the measurement(s)?

    If you don't understand the fundamental principles, you won't be able to implement them - whether with a microcontroller or anything else!

    Once you do understand the fundamental principles, then you can look at the features available on your microcontroller, and see which will be useful ...

Children
  • thanks for your answer

    i get pwm with micero controller and i wanted measure frequncy and duty cycle and i can measure 1100 hz

    i have some problem please answer me :

    this is my code :

      NVIC_InitStructure.NVIC_IRQChannel                   = TIM2_IRQn;
      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority        =1;
      NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
      NVIC_Init(&NVIC_InitStructure);
    
            TIM_ICInitStructure.TIM_Channel       = TIM_Channel_1;
      TIM_ICInitStructure.TIM_ICPolarity    = TIM_ICPolarity_Rising;
      TIM_ICInitStructure.TIM_ICSelection   = TIM_ICSelection_DirectTI;
      TIM_ICInitStructure.TIM_ICPrescaler   = TIM_ICPSC_DIV1;
      TIM_ICInitStructure.TIM_ICFilter      = 0x0;
      TIM_ICInit(TIM3, &TIM_ICInitStructure);
      TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);
      TIM_SelectInputTrigger(TIM2,TIM_TS_TI1FP1);
    
      TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);
    
      TIM_SelectMasterSlaveMode(TIM2,TIM_MasterSlaveMode_Enable);
    
      TIM_Cmd(TIM2, ENABLE);
      TIM_ITConfig(TIM2,TIM_IT_CC1,ENABLE);
    
    
    

    and this is my handler :

    {
    
            GPIO_SetBits(GPIOC,GPIO_Pin_2);
    
      TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
    
            IC2Value = TIM_GetCapture1(TIM2);
    //      IC1=TIM_GetCapture1(TIM2);
    //      IC2=TIM_GetCapture2(TIM2);
             if (IC2Value != 0)
      {
        /* Duty cycle computation */
        DutyCycle = (TIM_GetCapture2(TIM2) * 100) / IC2Value;
        /* Frequency computation */
        Frequency = SystemCoreClock / IC2Value;
                    IC2Value=0;
      }
      else
      {
        DutyCycle = 0;
        Frequency = 0;
      }
    }
    
    

    please say when during the current code i go to this handler

  • For low speeds you'd need to configure the timebase to run slower so the ticks in the period you are measuring don't exceed the 16-bit counter's limit.

    Use the timebase prescaler to divide down the SystemCoreClock

  • yes

    I did this work but was like befor , it didn't has effect.