|
参考AN2820文档
分别使用TIM4_CH4与DMA_CHANNEL7
TIM3_CH4与DMA_CHANNEL3
TIM2_CH4与DMA_CHANNEL2
以上3种TIMx工作在TIM_OCMode_Toggle方式,都能正确输出可变的频率
但是用TIM1_CH1与DMA_CHANNEL5时,就不行了,没有波形输出,但能进DMA_CHANNEL5的中断
代码:
/*0001*/ u16 SRC_Buffer_INC[20] ={60000,60000,55000,55000,50000,50000,45000,45000,40000,40000,
/*0002*/ 35000,35000,30000,30000,25000,25000,20000,20000,15000,15000};
/*0003*/
/*0004*/ void Init_RCC()
/*0005*/ {
/*0006*/ ...................
/*0007*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
/*0008*/ }
/*0009*/
/*0010*/ void DMA_TIM_OCToggle()
/*0011*/ {
/*0012*/ GPIO_InitTypeDef GPIO_InitStructure;
/*0013*/ TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/*0014*/ TIM_OCInitTypeDef TIM_OCInitStructure;
/*0015*/ DMA_InitTypeDef DMA_InitStructure;
/*0016*/
/*0017*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
/*0018*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
/*0019*/ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
/*0020*/ GPIO_Init(GPIOA, &GPIO_InitStructure);
/*0021*/
/*0022*/ TIM_TimeBaseStructure.TIM_Period = 60000;
/*0023*/ TIM_TimeBaseStructure.TIM_Prescaler = 2;
/*0024*/ TIM_TimeBaseStructure.TIM_ClockDivision = 0;
/*0025*/ TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
/*0026*/ TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/*0027*/
/*0028*/ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
/*0029*/ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
/*0030*/ TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
/*0031*/ TIM_OCInitStructure.TIM_Pulse = 0;
/*0032*/ TIM_OC1Init(TIM1, &TIM_OCInitStructure);
/*0033*/
/*0034*/ TIM_ARRPreloadConfig(TIM1, ENABLE);
/*0035*/
/*0036*/ TIM_Cmd(TIM1, ENABLE);
/*0037*/
/*0038*/ DMA_DeInit(DMA1_Channel5);
/*0039*/ DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40012C2C;
/*0040*/ DMA_InitStructure.DMA_MemoryBaseAddr = (u32)SRC_Buffer_INC;
/*0041*/ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
/*0042*/ DMA_InitStructure.DMA_BufferSize = BufferSize;
/*0043*/ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
/*0044*/ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
/*0045*/ DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
/*0046*/ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
/*0047*/ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
/*0048*/ DMA_InitStructure.DMA_Priority = DMA_Priority_High;
/*0049*/ DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
/*0050*/ DMA_Init(DMA1_Channel5, &DMA_InitStructure);
/*0051*/
/*0052*/ DMA_ITConfig(DMA1_Channel5, DMA_IT_TC, ENABLE);
/*0053*/
/*0054*/ DMA_Cmd(DMA1_Channel5, ENABLE);
/*0055*/
/*0056*/ TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE);
/*0057*/ }
/*0058*/
/*0059*/ void DMA1_Channel5_IRQHandler(void)
/*0060*/ {
/*0061*/ TIM1->DIER &= ~TIM_DMA_Update;
/*0062*/
/*0063*/ DMA1_Channel5->CCR &= ((u32)0xFFFFFFFE); // 通道禁用
/*0064*/
/*0065*/ if(acceleration == SET)
/*0066*/ {
/*0067*/ DMA1_Channel5->CMAR = (u32)SRC_Buffer_INC;
/*0068*/ DMA1_Channel5->CNDTR = 20;
/*0069*/ DMA1_Channel5->CCR |= ((u32)0x00000001); // 通道使能
/*0070*/ TIM1->DIER |= TIM_DMA_Update;
/*0071*/ acceleration = SET;
/*0072*/ }
/*0073*/ else
/*0074*/ {
/*0075*/ //if(SysTick_Config(SystemFrequency / 8000))
/*0076*/ //{
/*0077*/ // while(1);
/*0078*/ // }
/*0079*/ acceleration = SET;
/*0080*/ }
/*0081*/ DMA1->IFCR = DMA1_FLAG_TC5; // 清中断标志
/*0082*/
/*0083*/ GPIO_WriteBit(GPIOB, GPIO_Pin_5, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_5)));
/*0084*/ } |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|