大家好,请问大家,我在使用GD32E230的定时器触发ADC转换时,基于官方的这个例程把TIMER0改成TIMER14后集成在程序里不能工作(TIMER0在程序里做其他用途了,所以要改成TIMER14)。使能ADC转换完成中断后,未能进中断,用软件触发方式则可以进中断,我感觉是配置有问题未能触发ADC转换。观察TIMER14的寄存器,发现计数器是滚动的。请问大家有没有相关经验,或者哪位大神能帮我解决一下这个问题,可以适当有偿报酬。
- /*
- ***************************************************************************************************
- * Includes
- ***************************************************************************************************
- */
- /* global declarations */
- #include "common.h"
- /* module import interface */
- #include "Adc_Inf.h"
- /* private module interface */
- #include "Adc_Prv.h"
- /*
- ***************************************************************************************************
- * Variables
- ***************************************************************************************************
- */
- MEMORY_ALIGNED(4) volatile uint16 Adc_aResultValue[2];
- /*
- ***************************************************************************************************
- * used functions
- ***************************************************************************************************
- */
- void Adc_DmaConfig(void);
- void Adc_TrigTimerConfig(void);
- /**
- ***************************************************************************************************
- * Adc_Init - Initializes the ADC hardware unit and the driver.
- *
- *
- *
- * \param none
- * \return none
- * \retval none
- * \seealso
- * \usedresources
- ***************************************************************************************************
- */
- void Adc_Init(void)
- {
- /* Enable ADC clock */
- rcu_periph_clock_enable(RCU_ADC);
- /* Config ADC clock */
- rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
- /* Reset ADC */
- adc_deinit();
-
- /* DMA configuration */
- Adc_DmaConfig();
- #if (ADC_TRIG_TIMER_ENABLE == STD_ON)
- /* Trigger Timer configuration */
- Adc_TrigTimerConfig();
- #endif
- /* ADC scan function enable */
- adc_special_function_config(ADC_SCAN_MODE, ENABLE);
- /* ADC data alignment config */
- adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
- /* ADC channel length config */
- adc_channel_length_config(ADC_REGULAR_CHANNEL, 2);
- /* ADC regular channel config */
- adc_regular_channel_config(0, ADC_CHANNEL_0, ADC_SAMPLETIME_55POINT5);
- adc_regular_channel_config(1, ADC_CHANNEL_1, ADC_SAMPLETIME_55POINT5);
-
- /* ADC trigger config */
- #if (ADC_TRIG_TIMER_ENABLE == STD_OFF)
- adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_NONE);
- #else
- adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_T14_CH0);
- #endif
- adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);
- /* Enable ADC interface */
- adc_enable();
- Cpu_WaitTime(CPU_MS_TO_TICKS(1));
- /* ADC calibration and reset calibration */
- adc_calibration_enable();
- #if (ADC_TRIG_TIMER_ENABLE == STD_OFF)
- /* ADC software trigger enable */
- adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
- #endif
- /* ADC DMA function enable */
- adc_dma_mode_enable();
- #if (ADC_TRIG_TIMER_ENABLE == STD_ON)
- /* Enable Trigger Timer */
- timer_enable(ADC_TRIG_TIMER);
- #endif
-
- /* ADC interrupt config */
- nvic_irq_enable(ADC_CMP_IRQn, 0U);
- adc_interrupt_enable(ADC_INT_EOC);
- }
- /**
- ***************************************************************************************************
- * Adc_DmaConfig - DMA configuration function.
- *
- *
- *
- * \param none
- * \return none
- * \retval none
- * \seealso
- * \usedresources
- ***************************************************************************************************
- */
- void Adc_DmaConfig(void)
- {
- dma_parameter_struct dma_init_struct;
- /* Enable DMA clock */
- rcu_periph_clock_enable(RCU_DMA);
-
- /* Initialize DMA channel */
- dma_deinit(DMA_CH0);
- dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY;
- dma_init_struct.memory_addr = (uint32)Adc_aResultValue;
- dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
- dma_init_struct.memory_width = DMA_MEMORY_WIDTH_16BIT;
- dma_init_struct.number = 2;
- dma_init_struct.periph_addr = (uint32)&(ADC_RDATA);
- dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
- dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
- dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH;
- dma_init(DMA_CH0, &dma_init_struct);
-
- /* configure DMA mode */
- dma_circulation_enable(DMA_CH0);
- dma_memory_to_memory_disable(DMA_CH0);
-
- /* enable DMA channel0 */
- dma_channel_enable(DMA_CH0);
- }
- /**
- ***************************************************************************************************
- * Adc_TrigTimerConfig - Initializes the ADC trigger timer.
- *
- *
- *
- * \param none
- * \return none
- * \retval none
- * \seealso
- * \usedresources
- ***************************************************************************************************
- */
- void Adc_TrigTimerConfig(void)
- {
- timer_oc_parameter_struct timer_ocintpara;
- timer_parameter_struct timer_initpara;
- /* Enable timer clock */
- rcu_periph_clock_enable(RCU_TIMER14);
-
- /* Deinit a timer */
- timer_deinit(TIMER14);
- /* Initialize TIMER init parameter struct */
- timer_struct_para_init(&timer_initpara);
- /* Timer configuration */
- timer_initpara.prescaler = 5;
- timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
- timer_initpara.counterdirection = TIMER_COUNTER_UP;
- timer_initpara.period = 399;
- timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
- timer_initpara.repetitioncounter = 0;
- timer_init(TIMER14, &timer_initpara);
- /* CHx configuration in PWM mode1 */
- timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_LOW;
- timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
- timer_channel_output_config(TIMER14, TIMER_CH_0, &timer_ocintpara);
- timer_channel_output_pulse_value_config(TIMER14, TIMER_CH_0, 100);
- timer_channel_output_mode_config(TIMER14, TIMER_CH_0, TIMER_OC_MODE_PWM1);
- timer_channel_output_shadow_config(TIMER14, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE);
-
- /* Auto-reload preload enable */
- timer_auto_reload_shadow_enable(TIMER14);
- timer_primary_output_config(TIMER14, ENABLE);
- }
|