0
\$\begingroup\$

Regarding my Post I put a counter in my interrupt, In the output I have a 1000Hz signal which it means I should have 1000 pulses in each second, but I get 100 pulses each second. what is my problem?

Prescale=7;Periode=7999;Pulse=3998;

void PWMControl(unsigned int Freq){
TIM_TimeBaseInitTypeDef     TimeStructureure; 
TIM_OCInitTypeDef       TIMOCStructureure;  
        
        TimeStructure.TIM_Prescaler=Prescale;
        TimeStructure.TIM_CounterMode=TIM_CounterMode_Up;
        TimeStructure.TIM_Period=Period;
        TimeStructure.TIM_ClockDivision=TIM_CKD_DIV1;
        TimeStructure.TIM_RepetitionCounter=0;
        TIM_TimeBaseInit(TIM4, &TimeStructure);
        TIM_Cmd(TIM4, ENABLE);  
    
        TIMOCStructure.TIM_OCMode=TIM_OCMode_PWM2;
        TIMOCStructure.TIM_OutputState=TIM_OutputState_Enable;
        TIMOCStructure.TIM_OCPolarity=TIM_OCPolarity_Low;
        TIMOCStructure.TIM_Pulse=Pulse;
        TIM_OC1Init(TIM4, &TIMOCStructure);
        //TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);     
        TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);    
}
    


\$\endgroup\$
8
  • \$\begingroup\$ What clock speed is your STM32 running at? Do you have any clock hardware divisor set? \$\endgroup\$
    – jwh20
    Commented Jan 20, 2021 at 10:37
  • \$\begingroup\$ Thank you for your comment, My STM MCU is running at 64Mhz, and TIM4 APB1 clock is the same. My output wave form is an exact 1Khz but the counter shows me a different value. I don't have any other divider. \$\endgroup\$
    – John Jin
    Commented Jan 20, 2021 at 10:55
  • \$\begingroup\$ I'm not at all clear when you say the "wave form is an exact 1kHz" but at the same time "counter shows me a different value". What do you mean EXACTLY? Remember that anyone here can only go by what you post in the question and you have posted very little. \$\endgroup\$
    – jwh20
    Commented Jan 20, 2021 at 10:58
  • \$\begingroup\$ Sorry if I my explanation was not clear. It means I see a 1Khz PWM with 50% duty cycle. Based on the output signal, I expect to have 1K pulses each second but I see 100 pulses each second instead. \$\endgroup\$
    – John Jin
    Commented Jan 20, 2021 at 11:02
  • \$\begingroup\$ Still unclear. You say you see a 1kHz but you expect that and see 100 pps. WHICH IS IT? \$\endgroup\$
    – jwh20
    Commented Jan 20, 2021 at 11:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.