2012-12-05 08:34 AM
Hi guys,
I am new to the STM32 Micro and I am dealing with a STM32F0 discovery board. I am messing around with the TIMER peripheral trying to get a 400 Khz, however I have some issues with the TIM3 settings, below my code form TrueStudio: int main(void){ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* TIM Configuration */ TIM_Config(); /* ----------------------------------------------------------------------- TIM3 Configuration: Output Compare Timing Mode: In this example TIM3 input clock (TIM3CLK) is set to APB1 clock (PCLK1), => TIM3CLK = PCLK1 = SystemCoreClock = 48 MHz Prescaler Value = 2 CCR4_VAL = 120 CCR3_VAL = xxx Don't Care ----------------------------------------------------------------------- */ /* Compute the prescaler value */ PrescalerValue = (uint16_t)(SystemCoreClock / 24000000) - 1; /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); /* Prescaler configuration */ TIM_PrescalerConfig(TIM3, PrescalerValue, TIM_PSCReloadMode_Immediate); /* Output Compare Timing Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; /* Output Compare Timing Mode configuration: Channel3 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR3_Val; TIM_OC3Init(TIM3, &TIM_OCInitStructure); TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Disable); /* Output Compare Timing Mode configuration: Channel4 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR4_Val; TIM_OC4Init(TIM3, &TIM_OCInitStructure); TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Disable); /* TIM Interrupts enable */ TIM_ITConfig(TIM3, TIM_IT_CC4, ENABLE); /* TIM3 enable counter */ TIM_Cmd(TIM3, ENABLE); /* Infinite loop */ while (1) { }}in the lab I see that for values of CCR4_VAL = 240 I expect a wave of 100 Khz instead I measure 50 Khz for CCR4_VAL = 120 the waveform is 183.5 Hz (?????).Can you help me,please to understand what the is going on ??? Do I miss something ???Thnak you very much in advance2012-12-05 11:11 AM
Conveniently you don't show your interrupt handler. One might guess that a) you are toggling the output, and thus halving the frequency observed, and b) saturating the processor with too many interrupts.
The smarter way would be to have the hardware generate the signal, not software interrupts.2012-12-05 11:38 PM