你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

DMA+TIM_Burst

[复制链接]
pearlh 提问时间:2018-9-9 16:56 /
  1. void DMA_TIM1_Burst(void)         
  2. {  
  3.         /*!< At this stage the microcontroller clock setting is already configured,
  4.        this is done through SystemInit() function which is called from startup
  5.        file (startup_stm32f10x_xx.s) before to branch to application main.
  6.        To reconfigure the default setting of SystemInit() function, refer to
  7.        system_stm32f10x.c file
  8.      */   
  9.    GPIO_InitTypeDef         GPIO_InitStructure;
  10.    DMA_InitTypeDef          DMA_InitStructure;
  11.    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  12.    TIM_OCInitTypeDef        TIM_OCInitStructure;       
  13.    TIM_BDTRInitTypeDef      TIM_BDTRInitStructure;
  14.        
  15.   /* TIM1 and GPIOA clock enable */
  16.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 | RCC_APB2Periph_GPIOA| RCC_APB2Periph_GPIOB |RCC_APB2Periph_AFIO, ENABLE);

  17.   /* DMA clock enable */
  18.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
  19.   
  20.   /*channel1 ,channel2  --> PA.8,PA.9, PA.10*
  21.         *channel1N,channel2N --> PB.13,PB.14, PB.15*/
  22.   /* GPIOA Configuration: Channel 1 as alternate function push-pull */
  23.   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 ;
  24.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  25.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  26.   GPIO_Init(GPIOA, &GPIO_InitStructure);  

  27.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 |GPIO_Pin_14 | GPIO_Pin_15;
  28.         GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化GPIOB

  29.   /* TIM1 DeInit */
  30.   TIM_DeInit(TIM1);

  31.   /* DMA1 Channel5 Config */
  32.   DMA_DeInit(DMA1_Channel5);

  33.   DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)TIM1_DMAR_ADDRESS;
  34.   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SRC_Buffer;
  35.   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
  36.   DMA_InitStructure.DMA_BufferSize = 6;
  37.   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  38.   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  39.   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  40.   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  41.   DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  42.   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  43.   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  44.   DMA_Init(DMA1_Channel5, &DMA_InitStructure);
  45.   
  46.   /* Time base configuration */
  47.   /* -----------------------------------------------------------------------
  48.     TIM1 Configuration: generate 1 PWM signal using the DMA burst mode:
  49.     The TIM1CLK frequency is set to SystemCoreClock (Hz), to get TIM1 counter
  50.     clock at 24 MHz the Prescaler is computed as following:
  51.      - Prescaler = (TIM1CLK / TIM1 counter clock) - 1
  52.     SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density
  53.     and Connectivity line devices and to 24 MHz for Low-Density Value line and
  54.     Medium-Density Value line devices

  55.     The TIM1 period is 5.8 KHz: TIM1 Frequency = TIM1 counter clock/(ARR + 1)
  56.                                                = 24 MHz / 4096 = 5.8KHz KHz
  57.     TIM1 Channel1 duty cycle = (TIM1_CCR1/ TIM1_ARR)* 100 = 33.33%
  58.   ----------------------------------------------------------------------- */  
  59.   TIM_TimeBaseStructure.TIM_Period = 0xFFFF;         
  60.   TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t) (SystemCoreClock / 24000000) - 1;      
  61.   TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
  62.   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;   
  63.   TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

  64.   /* TIM Configuration in PWM Mode */
  65.   TIM_OCInitStructure.TIM_OCMode =  TIM_OCMode_PWM1;   
  66.   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;         
  67.   TIM_OCInitStructure.TIM_OutputNState=TIM_OutputNState_Enable;
  68.         TIM_OCInitStructure.TIM_Pulse = 0xFFF;  

  69.   TIM_OC1Init(TIM1, &TIM_OCInitStructure);
  70.   TIM_OC2Init(TIM1, &TIM_OCInitStructure);
  71.   TIM_OC3Init(TIM1, &TIM_OCInitStructure);

  72.   /* TIM1 DMAR Base register and DMA Burst Length Config */
  73.   TIM_DMAConfig(TIM1, TIM_DMABase_ARR, TIM_DMABurstLength_3Transfers);

  74.   /* TIM1 DMA Update enable */
  75.   TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE);
  76.        
  77.         /*死区和刹车功能配置*/
  78.         TIM_BDTRInitStructure.TIM_OSSRState       = TIM_OSSRState_Enable;
  79.         TIM_BDTRInitStructure.TIM_OSSIState       = TIM_OSSIState_Enable;
  80.         TIM_BDTRInitStructure.TIM_LOCKLevel       = TIM_LOCKLevel_1;
  81.         TIM_BDTRInitStructure.TIM_DeadTime        =50;                   //设置TIM1_BDTR的DTG,死区时间DTG[7:0]
  82.         TIM_BDTRInitStructure.TIM_Break           = TIM_Break_Disable;
  83.         TIM_BDTRInitStructure.TIM_BreakPolarity   = TIM_BreakPolarity_High;
  84.         TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
  85.         TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);

  86.   /* TIM1 enable */
  87.   TIM_Cmd(TIM1, ENABLE);
  88.   
  89.   /* TIM1 PWM Outputs Enable */
  90.   TIM_CtrlPWMOutputs(TIM1, ENABLE);

  91.   /* DMA1 Channel5 enable */
  92.   DMA_Cmd(DMA1_Channel5, ENABLE);

  93.   /* Wait until DMA1 Channel5 end of Transfer */
  94.   while (!DMA_GetFlagStatus(DMA1_FLAG_TC5))
  95.   {
  96.   }

  97.   /* Infinite loop */                                 
  98. }
复制代码


IMG_20180909_143609.jpg
收藏 评论1 发布时间:2018-9-9 16:56

举报

1个回答
七哥 回答时间:2018-9-10 16:30:25
这是分享呢?还是提问呢?
恕我眼拙,没看出问题来呀

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版