2692 views|4 replies

2870

Posts

4

Resources
The OP
 

Does anyone know how to initialize the input capture function of GD32? [Copy link]

The following code is the input capture function of GD32F303CBT6 that I wrote according to the information on the Internet. It uses PA0 and TIME4_CH0. The PA0 pin has input a 50% signal of 1KHZ.

#include "gd32f30x.h"
#include "gd32f303c_start.h"
#include "systick.h"


void timer_config4(void);
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/

int main(void)
{
    /* configure systick */
    systick_config();
    
    /* enable the LEDs GPIO clock */
    rcu_periph_clock_enable(RCU_GPIOB);
    /* configure LED1 LED2 GPIO port */
    gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
    /*Configure PA0(TIMER4_CH0) as alternate function*/
	  gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
		timer_config4();
    /* reset LED1 LED2 GPIO pin */
    gpio_bit_reset(GPIOB, GPIO_PIN_1);

    while(1){

        gpio_bit_set(GPIOB, GPIO_PIN_1);
        delay_1ms(1000);
        gpio_bit_reset(GPIOB, GPIO_PIN_1);
        delay_1ms(1000);
    }
}

/**
    \brief      configure the TIMER peripheral
    \param[in]  none
    \param[out] none
    \retval     none
  */
void timer_config4(void)
{
    
	  
	  /* TIMER1 configuration: generate PWM signals with different duty cycles:
       TIMER1CLK = SystemCoreClock / 120 = 1MHz */
    timer_ic_parameter_struct timer_icinitpara;
    timer_parameter_struct timer_initpara;

		/* connect IRC40K clock to the TIMER4_CH3 input for calibration */
		//rcu_periph_clock_enable(RCU_AF);
		//gpio_pin_remap_config(GPIO_TIMER4CH3_IREMAP, ENABLE);
		rcu_periph_clock_enable(RCU_TIMER4);
		timer_deinit(TIMER4);
	
	  nvic_priority_group_set(NVIC_PRIGROUP_PRE1_SUB3);
    nvic_irq_enable(TIMER4_IRQn, 1, 1);     
		/* initialize TIMER init parameter struct */
		timer_struct_para_init(&timer_initpara);
		/* TIMER4 configuration */
		timer_initpara.prescaler = 71;
		timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
		timer_initpara.counterdirection = TIMER_COUNTER_UP;
		timer_initpara.period = 0xFFFF;
		timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
		timer_init(TIMER4, &timer_initpara);

		/* TIMER4 configuration */
		/* initialize TIMER channel input parameter struct */
		timer_channel_input_struct_para_init(&timer_icinitpara);
		/* TIMER4 CH3 input capture configuration */
		timer_icinitpara.icpolarity = TIMER_IC_POLARITY_FALLING;
		timer_icinitpara.icselection = TIMER_IC_SELECTION_DIRECTTI;
		timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;
		timer_icinitpara.icfilter = 0x0;
		timer_input_capture_config(TIMER4, TIMER_CH_0, &timer_icinitpara);
		
		
		/* auto-reload preload enable */
		timer_auto_reload_shadow_enable(TIMER4);
		/* clear channel 3 interrupt bit */
		//timer_interrupt_flag_clear(TIMER4, TIMER_INT_FLAG_CH0);
		timer_interrupt_flag_clear(TIMER4, TIMER_INT_CH0);
		/* channel 3 interrupt enable */
		timer_interrupt_enable(TIMER4, TIMER_INT_CH0);
		/* TIMER4 counter enable */
		timer_enable(TIMER4);

}

Interrupt code


void TIMER4_IRQHandler(void)
{
		 if(SET == timer_interrupt_flag_get(TIMER4, TIMER_INT_CH0)){
			 /* clear channel 3 interrupt bit */
			 timer_interrupt_flag_clear(TIMER4, TIMER_INT_CH0);
			 timer_capture_num++;
		 if(1 == timer_capture_num){
					/* get the input capture value */
					timer_capture1 = timer_channel_capture_value_register_read(TIMER4,TIMER_CH_0);
		 }else if(2 == timer_capture_num){
					/* get the input capture value */
					timer_capture2 = timer_channel_capture_value_register_read(TIMER4,TIMER_CH_0);
					/* end capture, disable TIMER4 and CH3 interrupt */
					timer_interrupt_disable(TIMER4, TIMER_INT_CH0);
					timer_disable(TIMER4);
				}
		 }
}

After the program is running, it cannot enter the interruption state. Please give me some advice if you have done this before.

This post is from GD32 MCU

Latest reply

rcu_periph_clock_enable(RCU_AF);Is the AF function enabled?   Details Published on 2022-11-4 09:04
 

1

Posts

0

Resources
2
 

From the code it seems that the interrupt is not enabled

This post is from GD32 MCU

Comments

Hello, what interrupt is this? The interrupts for the entire system are already enabled. nvic_priority_group_set(NVIC_PRIGROUP_PRE1_SUB3); nvic_irq_enable(TIMER4_IRQn, 1, 1); The TIMER4 interrupt is also enabled.   Details Published on 2022-11-3 17:41
 
 
 

2870

Posts

4

Resources
3
 
Enzo Ferrari posted on 2022-11-3 17:36 From the code, it seems that interrupts are not enabled

Hello, what kind of interrupt is this? The interrupts for the entire system have been enabled.

nvic_priority_group_set(NVIC_PRIGROUP_PRE1_SUB3);
nvic_irq_enable(TIMER4_IRQn, 1, 1);

TIME4 interruption has also been opened

This post is from GD32 MCU
 
 
 

6841

Posts

11

Resources
4
 

The official has already had a routine.

This post is from GD32 MCU
 
 
 

6075

Posts

6

Resources
5
 

rcu_periph_clock_enable(RCU_AF);Is the AF function enabled?

This post is from GD32 MCU
 
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
To our members and visitors!!

http://www.sy-dj.gov.cn/song/list/lyyq/005.mp3 More... I hope everyone will post I hope ev ...

A boy confessed his love to a girl at KFC [Repost]

 Yesterday I went to KFC. The couple behind me ordered a lot of food and then sat next to me.   After sitting down, t ...

Contradictions and tradeoffs in switching power supply design

Overview Designing a switching power supply is a process full of contradictions. You can't have your cake and eat it ...

MSP430F5529 uses DMA to receive serial port data and respond

#include "msp430.h" #define CPU ((double)4000000) #define delay_ms(x) __delay_cycles((long)(CPU*(double)x/100 ...

Oscilloscope AC coupling will have DC bias

I used an oscilloscope's AC coupling to test a high-voltage power supply with an output of 1KV, but the oscilloscope sho ...

RTD Circuit Design

RTD Circuit Design PT100/1000 meaning Common RTDs are PT100 and PT1000. 100 and 1000 mean that when the temperature is 0 ...

Learn to make and use Tina's Docker image compilation from scratch

This post was last edited by walker2048 on 2022-8-28 10:43 ### Foreword This is the first time that a novice player has ...

Microprocessor design: from design planning to process manufacturing

This book focuses on microprocessor design and covers the entire design process from design planning to process manufact ...

Review shortlist: remotely controllable USB packet capture tool tinySniffer

Thanks to the netizens who participated in the evaluation of tinySniffer, a remotely controlled USB packet capture tool ...

Structure and parameters of op amp

This post was last edited by Luanshi Zujiu Luntianxia on 2024-7-25 19:34 Structure and parameters of op amp 1. Single- ...

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list