void pwm_gpio_config(void)
{
rcu_periph_clock_enable(RCU_GPIOC);
gpio_init(GPIOC,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_6);
}
我们现在的项目用到DMA(从内存到外设)+PWM(调占空比),用的芯片是GD32F103RBT6。
我们现在DMA1+PWM(TIMER7)的配置上,是否能提供例程
我们自己配置以下:帮忙确认一下是否有错
void timer_config(void)
{
/* TIMER0 configuration: generate PWM signals with different duty cycles:
TIMER0CLK = SystemCoreClock / 108 = 1MHz */
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER7);
timer_deinit(TIMER7);
/* TIMER0 configuration */
timer_initpara.prescaler = 107;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 500;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER7,&timer_initpara);
/* CH0 configuration in PWM mode */
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_ocintpara.outputnstate = TIMER_CCXN_DISABLE;
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH;
timer_ocintpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW;
timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
timer_channel_output_config(TIMER7,TIMER_CH_0,&timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER7,TIMER_CH_0,250);
timer_channel_output_mode_config(TIMER7,TIMER_CH_0,TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER7,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
timer_primary_output_config(TIMER7,ENABLE);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER7);
timer_enable(TIMER7);
}
/*!
\brief configure PWM DMA
\param[in] none
\param[out] none
\retval none
*/
void pwm_dma_config(void)
{
dma_parameter_struct dma_init_struct;
/* enable DMA1 */
rcu_periph_clock_enable(RCU_DMA1);
/* deinitialize DMA channel2(TIMER7 TIMER_CH_0) */
dma_deinit(DMA1, DMA_CH2);
dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL;//从内存到外设
dma_init_struct.memory_addr = (uint32_t)MY_WS2812_GRB_BUF;//DMA数组
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_init_struct.memory_width = DMA_MEMORY_WIDTH_16BIT;//数组是U16的,是否这样设置
dma_init_struct.number = ARRAYNUM(MY_WS2812_GRB_BUF);//DMA数组的大小
dma_init_struct.periph_addr = PWM_TIMER7_DATA_ADDRESS;//((uint32_t)0x40013400) TIMER7是否是这个地址
dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;//数组是U16的,是否这样设置
dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH;
dma_init(DMA1, DMA_CH2, &dma_init_struct);
/* configure DMA mode */
dma_circulation_disable(DMA1, DMA_CH2);
dma_memory_to_memory_disable(DMA1, DMA_CH2);
}
我们对DMA配置不太了解
这样就配置好了吗?
数组通过DMA输出到PWM调整占空比,还需要用到那些库函数
还有外设的地址是否有错
谢谢
使用特权更多操作 |