- void DMA_TIM1_Burst(void)
- {
- /*!< At this stage the microcontroller clock setting is already configured,
- this is done through SystemInit() function which is called from startup
- file (startup_stm32f10x_xx.s) before to branch to application main.
- To reconfigure the default setting of SystemInit() function, refer to
- system_stm32f10x.c file
- */
- GPIO_InitTypeDef GPIO_InitStructure;
- DMA_InitTypeDef DMA_InitStructure;
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
- TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
-
- /* TIM1 and GPIOA clock enable */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 | RCC_APB2Periph_GPIOA| RCC_APB2Periph_GPIOB |RCC_APB2Periph_AFIO, ENABLE);
- /* DMA clock enable */
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
-
- /*channel1 ,channel2 --> PA.8,PA.9, PA.10*
- *channel1N,channel2N --> PB.13,PB.14, PB.15*/
- /* GPIOA Configuration: Channel 1 as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 ;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 |GPIO_Pin_14 | GPIO_Pin_15;
- GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化GPIOB
- /* TIM1 DeInit */
- TIM_DeInit(TIM1);
- /* DMA1 Channel5 Config */
- DMA_DeInit(DMA1_Channel5);
- DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)TIM1_DMAR_ADDRESS;
- DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SRC_Buffer;
- DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
- DMA_InitStructure.DMA_BufferSize = 6;
- DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
- DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
- DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
- DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
- DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
- DMA_InitStructure.DMA_Priority = DMA_Priority_High;
- DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
- DMA_Init(DMA1_Channel5, &DMA_InitStructure);
-
- /* Time base configuration */
- /* -----------------------------------------------------------------------
- TIM1 Configuration: generate 1 PWM signal using the DMA burst mode:
- The TIM1CLK frequency is set to SystemCoreClock (Hz), to get TIM1 counter
- clock at 24 MHz the Prescaler is computed as following:
- - Prescaler = (TIM1CLK / TIM1 counter clock) - 1
- SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density
- and Connectivity line devices and to 24 MHz for Low-Density Value line and
- Medium-Density Value line devices
- The TIM1 period is 5.8 KHz: TIM1 Frequency = TIM1 counter clock/(ARR + 1)
- = 24 MHz / 4096 = 5.8KHz KHz
- TIM1 Channel1 duty cycle = (TIM1_CCR1/ TIM1_ARR)* 100 = 33.33%
- ----------------------------------------------------------------------- */
- TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
- TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t) (SystemCoreClock / 24000000) - 1;
- TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
- /* TIM Configuration in PWM Mode */
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_OutputNState=TIM_OutputNState_Enable;
- TIM_OCInitStructure.TIM_Pulse = 0xFFF;
- TIM_OC1Init(TIM1, &TIM_OCInitStructure);
- TIM_OC2Init(TIM1, &TIM_OCInitStructure);
- TIM_OC3Init(TIM1, &TIM_OCInitStructure);
- /* TIM1 DMAR Base register and DMA Burst Length Config */
- TIM_DMAConfig(TIM1, TIM_DMABase_ARR, TIM_DMABurstLength_3Transfers);
- /* TIM1 DMA Update enable */
- TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE);
-
- /*死区和刹车功能配置*/
- TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
- TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
- TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
- TIM_BDTRInitStructure.TIM_DeadTime =50; //设置TIM1_BDTR的DTG,死区时间DTG[7:0]
- TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable;
- TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
- TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
- TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
- /* TIM1 enable */
- TIM_Cmd(TIM1, ENABLE);
-
- /* TIM1 PWM Outputs Enable */
- TIM_CtrlPWMOutputs(TIM1, ENABLE);
- /* DMA1 Channel5 enable */
- DMA_Cmd(DMA1_Channel5, ENABLE);
- /* Wait until DMA1 Channel5 end of Transfer */
- while (!DMA_GetFlagStatus(DMA1_FLAG_TC5))
- {
- }
- /* Infinite loop */
- }
复制代码
|
恕我眼拙,没看出问题来呀