我直接加载KeilARMExamplesSTSTM32F10xTIMExample1中的项目文件编译正常,下载到STM32F103VB评估板后,测试PC0/PC1/PC2/PC3四个脚的波形,却发现都是一样的波形大约100HZ不到的方波,而按照readme的说明 This example shows how to configure the TIM2 peripheral to generate four different signals with four different frequencies.
The TIM2CLK frequency is set to 36 MHz, the Prescaler is set to 0x2, and used in Output Compare Toggle Mode.
TIM2 counter clock = TIMxCLK / (Prescaler +1) = 12 MHz
The TIM2 CC1 register value is equal to 0x8000: CC1 update rate = TIM2 counter clock / CCR1_Val = 366.2 Hz, so the TIM2 Channel 1 generates a periodic signal with a frequency equal to 183.1 Hz.
The TIM2 CC2 register is equal to 0x4000: CC2 update rate = TIM2 counter clock / CCR2_Val = 732.4 Hz so the TIM2 channel 2 generates a periodic signal with a frequency equal to 366.3 Hz.
The TIM2 CC3 register is equal to 0x2000: CC3 update rate = TIM2 counter clock / CCR3_Val = 1464.8 Hz so the TIM2 channel 3 generates a periodic signal with a frequency equal to 732.4 Hz.
The TIM2 CC4 register is equal to 0x1000: CC4 update rate = TIM2 counter clock / CCR4_Val = 2929.6 Hz so the TIM2 channel 4 generates a periodic signal with a frequency equal to 1464.8 Hz.
应该是输出4个不同频率的OCX输出啊,甚至文档都给出了四个波形的示波器的图形,可是不知为什么我编译后会成这样。我是直接加载该项目文件然后什么都没修改,直接BUILD ALL然后用ULINK下载到FLASH的。 /* --------------------------------------------------------------- TIM2 Configuration: Output Compare Toggle Mode: TIM2CLK = 36 MHz, Prescaler = 0x2, TIM2 counter clock = 12 MHz CC1 update rate = TIM2 counter clock / CCR1_Val = 366.2 Hz CC2 update rate = TIM2 counter clock / CCR2_Val = 732.4 Hz CC3 update rate = TIM2 counter clock / CCR3_Val = 1464.8 Hz CC4 update rate = TIM2 counter clock / CCR4_Val = 2929.6 Hz --------------------------------------------------------------- */
/* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 0xFFFF; TIM_TimeBaseStructure.TIM_Prescaler = 0x02; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* Output Compare Toggle Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle; TIM_OCInitStructure.TIM_Channel = TIM_Channel_1; TIM_OCInitStructure.TIM_Pulse = CCR1_Val; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInit(TIM2, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable); /* TIM enable counter */ TIM_Cmd(TIM2, ENABLE); 昨晚还试了ST网站上下载的该例程也是如此情况,发现上面程序中修改CCR1_VAL的值,PA0的输出也是没有任何改变,其他CHANNEL也都如此,着实不解。哪位能帮我看看,究竟是啥原因啊,谢谢
|