From 212ffff06b4ed213fef35b6b11dd2869c440f9ef Mon Sep 17 00:00:00 2001 From: yelvlab Date: Wed, 25 Sep 2024 11:00:47 +0800 Subject: [PATCH] change the timer of LED to TIMER5(basic timer) --- inc/ultrasonic_driver.h | 5 +++-- src/gd32e23x_it.c | 16 +++++++--------- src/ultrasonic_driver.c | 10 +++++----- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/inc/ultrasonic_driver.h b/inc/ultrasonic_driver.h index b39d5be..6307fba 100644 --- a/inc/ultrasonic_driver.h +++ b/inc/ultrasonic_driver.h @@ -10,8 +10,9 @@ #define LED_PORT GPIOA #define LED_PIN GPIO_PIN_9 #define LED_RCU RCU_GPIOA -#define LED_TIMER TIMER16 -#define LED_IRQ TIMER16_IRQn +#define LED_TIMER_RCU RCU_TIMER5 +#define LED_TIMER TIMER5 +#define LED_IRQ TIMER5_IRQn #define USART_RCU RCU_USART0 #define USART_GPIO_RCU RCU_GPIOA diff --git a/src/gd32e23x_it.c b/src/gd32e23x_it.c index 1925547..b0c38fe 100644 --- a/src/gd32e23x_it.c +++ b/src/gd32e23x_it.c @@ -98,20 +98,18 @@ void SysTick_Handler(void) { } -void TIMER16_IRQHandler(void) { - if (timer_interrupt_flag_get(TIMER16, TIMER_INT_FLAG_UP) == SET) +void TIMER5_IRQHandler(void) { + if (timer_interrupt_flag_get(LED_TIMER, TIMER_INT_FLAG_UP) == SET) { - timer_interrupt_flag_clear(TIMER16, TIMER_INT_FLAG_UP); + timer_interrupt_flag_clear(LED_TIMER, TIMER_INT_FLAG_UP); static uint8_t led_status = 0; if (led_status) { - //! turn on led & reconfig timer13 period to 19000(1900ms) - gpio_bit_write(GPIOA, GPIO_PIN_9, RESET); - timer_autoreload_value_config(TIMER16, 19200); + gpio_bit_write(LED_PORT, LED_PIN, RESET); + timer_autoreload_value_config(LED_TIMER, 19200); } else { - //! turn off led & reconfig timer13 period to 1000(100ms) - gpio_bit_write(GPIOA, GPIO_PIN_9, SET); - timer_autoreload_value_config(TIMER16, 800); + gpio_bit_write(LED_PORT, LED_PIN, SET); + timer_autoreload_value_config(LED_TIMER, 800); } led_status = !led_status; } diff --git a/src/ultrasonic_driver.c b/src/ultrasonic_driver.c index 1021253..8402fce 100644 --- a/src/ultrasonic_driver.c +++ b/src/ultrasonic_driver.c @@ -6,8 +6,6 @@ #include "gd32e23x.h" #include "systick.h" -uint8_t speed_pwm = 30; //bldc default pwm is 30 - void led_config(void) { rcu_periph_clock_enable(LED_RCU); @@ -16,8 +14,8 @@ void led_config(void) gpio_output_options_set(LED_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LED_PIN); gpio_bit_write(LED_PORT, LED_PIN, SET); - rcu_periph_clock_enable(RCU_TIMER13); - timer_deinit(RCU_TIMER13); + rcu_periph_clock_enable(LED_TIMER_RCU); + timer_deinit(LED_TIMER); timer_parameter_struct timer_initpara; timer_struct_para_init(&timer_initpara); @@ -30,8 +28,10 @@ void led_config(void) timer_auto_reload_shadow_enable(LED_TIMER); timer_interrupt_enable(LED_TIMER, TIMER_INT_UP); - nvic_irq_enable(LED_IRQ, 3); + timer_enable(LED_TIMER); + + nvic_irq_enable(LED_IRQ, 0); } void usart_config(void)