上程序:
- #include "main.h"
- #include "Board.h"
- #include "apm32f4xx_tmr.h"
- /** @addtogroup Examples
- @{
- */
- /** @addtogroup TMR_PWMOutput
- @{
- */
- /** @defgroup TMR_PWMOutput_Functions Functions
- @{
- */
- #ifdef APM32F411
- #define DIV 99
- #else
- #define DIV 167
- #endif
- /**@} end of group TMR_PWMOutput_Functions */
- /*!
- * [url=home.php?mod=space&uid=247401]@brief[/url] Main program
- *
- * @param None
- *
- * @retval None
- */
- int main(void)
- {
- GPIO_Config_T GPIO_ConfigStruct;
- TMR_BaseConfig_T TMR_TimeBaseStruct;
- TMR_OCConfig_T OCcongigStruct;
- RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_TMR1);
- RCM_EnableAHB1PeriphClock(RCM_AHB1_PERIPH_GPIOA | RCM_AHB1_PERIPH_GPIOB);
- GPIO_ConfigPinAF(GPIOA, GPIO_PIN_SOURCE_8, GPIO_AF_TMR1);
- GPIO_ConfigPinAF(GPIOA, GPIO_PIN_SOURCE_7, GPIO_AF_TMR1);
- /* Config PA7 and PA8 for complementary output PWM */
- GPIO_ConfigStruct.pin = GPIO_PIN_7 | GPIO_PIN_8;
- GPIO_ConfigStruct.mode = GPIO_MODE_AF;
- GPIO_ConfigStruct.otype = GPIO_OTYPE_PP;
- GPIO_ConfigStruct.speed = GPIO_SPEED_100MHz;
- GPIO_Config(GPIOA, &GPIO_ConfigStruct);
- /* config TMR1 */
- TMR_TimeBaseStruct.clockDivision = TMR_CLOCK_DIV_1;
- TMR_TimeBaseStruct.countMode = TMR_COUNTER_MODE_UP;
- TMR_TimeBaseStruct.division = DIV;
- TMR_TimeBaseStruct.period = 999;
- TMR_ConfigTimeBase(TMR1, &TMR_TimeBaseStruct);
- OCcongigStruct.idleState = TMR_OC_IDLE_STATE_RESET;
- OCcongigStruct.mode = TMR_OC_MODE_PWM1;
- OCcongigStruct.nIdleState = TMR_OC_NIDLE_STATE_RESET;
- OCcongigStruct.nPolarity = TMR_OC_NPOLARITY_HIGH;
- OCcongigStruct.outputNState = TMR_OC_NSTATE_ENABLE;
- OCcongigStruct.outputState = TMR_OC_STATE_ENABLE;
- OCcongigStruct.polarity = TMR_OC_POLARITY_HIGH;
- OCcongigStruct.pulse = 300;
- TMR_ConfigOC1(TMR1, &OCcongigStruct);
- TMR_ConfigOC1Preload(TMR1, TMR_OC_PRELOAD_ENABLE);
- TMR_EnableAutoReload(TMR1);
- TMR_Enable(TMR1);
- TMR_EnablePWMOutputs(TMR1);
- while(1)
- {
- }
- }
请问高手,程序有问题吗?谢谢
|