change the timer of LED to TIMER5(basic timer)
This commit is contained in:
parent
4252d59581
commit
212ffff06b
@ -10,8 +10,9 @@
|
|||||||
#define LED_PORT GPIOA
|
#define LED_PORT GPIOA
|
||||||
#define LED_PIN GPIO_PIN_9
|
#define LED_PIN GPIO_PIN_9
|
||||||
#define LED_RCU RCU_GPIOA
|
#define LED_RCU RCU_GPIOA
|
||||||
#define LED_TIMER TIMER16
|
#define LED_TIMER_RCU RCU_TIMER5
|
||||||
#define LED_IRQ TIMER16_IRQn
|
#define LED_TIMER TIMER5
|
||||||
|
#define LED_IRQ TIMER5_IRQn
|
||||||
|
|
||||||
#define USART_RCU RCU_USART0
|
#define USART_RCU RCU_USART0
|
||||||
#define USART_GPIO_RCU RCU_GPIOA
|
#define USART_GPIO_RCU RCU_GPIOA
|
||||||
|
@ -98,20 +98,18 @@ void SysTick_Handler(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TIMER16_IRQHandler(void) {
|
void TIMER5_IRQHandler(void) {
|
||||||
if (timer_interrupt_flag_get(TIMER16, TIMER_INT_FLAG_UP) == SET)
|
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;
|
static uint8_t led_status = 0;
|
||||||
if (led_status)
|
if (led_status)
|
||||||
{
|
{
|
||||||
//! turn on led & reconfig timer13 period to 19000(1900ms)
|
gpio_bit_write(LED_PORT, LED_PIN, RESET);
|
||||||
gpio_bit_write(GPIOA, GPIO_PIN_9, RESET);
|
timer_autoreload_value_config(LED_TIMER, 19200);
|
||||||
timer_autoreload_value_config(TIMER16, 19200);
|
|
||||||
} else {
|
} else {
|
||||||
//! turn off led & reconfig timer13 period to 1000(100ms)
|
gpio_bit_write(LED_PORT, LED_PIN, SET);
|
||||||
gpio_bit_write(GPIOA, GPIO_PIN_9, SET);
|
timer_autoreload_value_config(LED_TIMER, 800);
|
||||||
timer_autoreload_value_config(TIMER16, 800);
|
|
||||||
}
|
}
|
||||||
led_status = !led_status;
|
led_status = !led_status;
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
#include "gd32e23x.h"
|
#include "gd32e23x.h"
|
||||||
#include "systick.h"
|
#include "systick.h"
|
||||||
|
|
||||||
uint8_t speed_pwm = 30; //bldc default pwm is 30
|
|
||||||
|
|
||||||
void led_config(void)
|
void led_config(void)
|
||||||
{
|
{
|
||||||
rcu_periph_clock_enable(LED_RCU);
|
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_output_options_set(LED_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LED_PIN);
|
||||||
gpio_bit_write(LED_PORT, LED_PIN, SET);
|
gpio_bit_write(LED_PORT, LED_PIN, SET);
|
||||||
|
|
||||||
rcu_periph_clock_enable(RCU_TIMER13);
|
rcu_periph_clock_enable(LED_TIMER_RCU);
|
||||||
timer_deinit(RCU_TIMER13);
|
timer_deinit(LED_TIMER);
|
||||||
|
|
||||||
timer_parameter_struct timer_initpara;
|
timer_parameter_struct timer_initpara;
|
||||||
timer_struct_para_init(&timer_initpara);
|
timer_struct_para_init(&timer_initpara);
|
||||||
@ -30,8 +28,10 @@ void led_config(void)
|
|||||||
|
|
||||||
timer_auto_reload_shadow_enable(LED_TIMER);
|
timer_auto_reload_shadow_enable(LED_TIMER);
|
||||||
timer_interrupt_enable(LED_TIMER, TIMER_INT_UP);
|
timer_interrupt_enable(LED_TIMER, TIMER_INT_UP);
|
||||||
nvic_irq_enable(LED_IRQ, 3);
|
|
||||||
timer_enable(LED_TIMER);
|
timer_enable(LED_TIMER);
|
||||||
|
|
||||||
|
nvic_irq_enable(LED_IRQ, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usart_config(void)
|
void usart_config(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user