STR736 TIMER0的OCMPA0输出脉冲,设置如下: GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure1.GPIO_Pins = GPIO_PIN_8 | GPIO_PIN_9; GPIO_Init (GPIO1, &GPIO_InitStructure1);
TIM0_InitStructure.TIM_Clock_Source = TIM_CLK_INTERNAL; TIM0_InitStructure.TIM_Prescaler = 0x02; TIM0_InitStructure.TIM_Mode = TIM_OCM_CHANNELA; TIM0_InitStructure.TIM_OCA_Modes = TIM_Wave; TIM0_InitStructure.TIM_Clock_Edge = TIM_Rising; TIM0_InitStructure.TIM_Pulse_Level_A = TIM_High; TIM0_InitStructure.TIM_Pulse_Length_A = 0x8A00; TIM_Init (TIM0, &TIM0_InitStructure); TIM_CounterCmd(TIM0, TIM_START);
使用以下程序进行电平切换: while(TRUE){ if(TIM_FlagStatus ( TIM0, TIM_FLAG_OCA)) TIM_CounterCmd(TIM0, TIM_STOP); n1=~n1; n1=n1&0x01; if(n1==0) TIM0_InitStructure.TIM_Pulse_Level_A = TIM_Low; else TIM0_InitStructure.TIM_Pulse_Level_A = TIM_High; TIM_FlagClear (TIM0, TIM_FLAG_OCA); TIM_Init (TIM0, &TIM0_InitStructure); TIM_CounterCmd(TIM0, TIM_START); } 结果是脉冲是有输出,但长度不一样,请指教. |