(图片与文章内容无关,来源于网络) 精确控制PWM个数采用的是主从方案, TIM3产生PWM,为TIM2提供时钟,然后TIM2计数 测试代码如下(待完善),仅供参考 主要的文件就是time.c文件 main.c文件 # include "stm32f10x.h" # include "time.h" # include "usart.h" void Delay ( unsigned int Time) { if (Time == 0 ) return ; while (Time--); } int main () { //NVIC_ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); TIM2_init( 7199 , 999 ); /// 1/10=0.01 TIM3_init( 7199 , 99 ); /// 1/100=0.1 //99 usart1_init( 115200 ); //SetPWMValue(TIM2,1,500); SetPWMValue(TIM3, 1 , 50 ); UartPutChar(USART1, 0X56 ); while ( 1 ) { // UartPutChar(USART1,0X56); Delay( 100 ); if (flag== 1 ) { TIM3_init( 7199 ,(