feat: 完成互补pwm输出接口

This commit is contained in:
2024-04-16 18:17:30 +08:00
parent 58af6f0c89
commit f0cbc9f1d3
16 changed files with 765 additions and 82 deletions

View File

@@ -59,7 +59,7 @@ extern "C" {
#define CRM_MODULE_ENABLED
#define DEBUG_MODULE_ENABLED
/*#define DMA_MODULE_ENABLED----------------------*/
#define EXINT_MODULE_ENABLED
/*#define EXINT_MODULE_ENABLED--------------------*/
#define FLASH_MODULE_ENABLED
#define GPIO_MODULE_ENABLED
/*#define I2C_MODULE_ENABLED----------------------*/

View File

@@ -74,9 +74,6 @@ extern "C" {
/* init can1 function. */
void wk_can1_init(void);
/* init pwc function. */
void wk_pwc_init(void);
/* init usart2 function. */
void wk_usart2_init(void);

View File

@@ -65,7 +65,7 @@
* @brief system clock config program
* @note the system clock is configured as follow:
* system clock (sclk) = hext / 2 * pll_mult
* system clock source = pll (hext)
* system clock source = HEXT_VALUE
* - hext = HEXT_VALUE
* - sclk = 200000000
* - ahbdiv = 1
@@ -182,9 +182,6 @@ void wk_periph_clock_config(void)
/* enable can1 periph clock */
crm_periph_clock_enable(CRM_CAN1_PERIPH_CLOCK, TRUE);
/* enable pwc periph clock */
crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
}
/**
@@ -217,9 +214,17 @@ void wk_nvic_config(void)
*/
void wk_gpio_config(void)
{
/* add user code begin gpio_config 0 */
/* add user code end gpio_config 0 */
gpio_init_type gpio_init_struct;
gpio_default_para_init(&gpio_init_struct);
/* add user code begin gpio_config 1 */
/* add user code end gpio_config 1 */
/* gpio input config */
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_3 | GPIO_PINS_4 | GPIO_PINS_5 | GPIO_PINS_6;
@@ -235,46 +240,10 @@ void wk_gpio_config(void)
gpio_init_struct.gpio_pins = GPIO_PINS_15;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct);
}
/**
* @brief init pwc function.
* @param none
* @retval none
*/
void wk_pwc_init(void)
{
/* add user code begin pwc_init 0 */
/* add user code begin gpio_config 2 */
/* add user code end pwc_init 0 */
exint_init_type exint_init_struct;
/* add user code begin pwc_init 1 */
/* add user code end pwc_init 1 */
/* set the threshold voltage*/
pwc_pvm_level_select(PWC_PVM_VOLTAGE_2V8);
/* enable power voltage monitor */
pwc_power_voltage_monitor_enable(TRUE);
exint_default_para_init(&exint_init_struct);
exint_init_struct.line_enable = TRUE;
exint_init_struct.line_mode = EXINT_LINE_INTERRUPUT;
exint_init_struct.line_select = EXINT_LINE_16;
exint_init_struct.line_polarity = EXINT_TRIGGER_RISING_EDGE;
exint_init(&exint_init_struct);
/**
* Users need to configure PWC interrupt functions according to the actual application.
* 1. Add the user's interrupt handler code into the below function in the at32f413_int.c file.
* --void PVM_IRQHandler (void)
*/
/* add user code begin pwc_init 2 */
/* add user code end pwc_init 2 */
/* add user code end gpio_config 2 */
}
/**
@@ -379,7 +348,7 @@ void wk_tmr1_init(void)
gpio_init(GPIOA, &gpio_init_struct);
/* configure counter settings */
tmr_base_init(TMR1, 65535, 0);
tmr_base_init(TMR1, 999, 499);
tmr_cnt_dir_set(TMR1, TMR_COUNT_UP);
tmr_clock_source_div_set(TMR1, TMR_CLOCK_DIV1);
tmr_repetition_counter_set(TMR1, 0);
@@ -389,30 +358,37 @@ void wk_tmr1_init(void)
tmr_sub_sync_mode_set(TMR1, FALSE);
tmr_primary_mode_select(TMR1, TMR_PRIMARY_SEL_RESET);
/* configure overflow event */
tmr_overflow_event_disable(TMR1, TRUE);
/* configure channel 1 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = TRUE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.oc_idle_state = TRUE;
tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_1, 0);
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_1, 500);
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_1, FALSE);
tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_1, FALSE);
/* configure channel 2 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = TRUE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.oc_idle_state = TRUE;
tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, 0);
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, 500);
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_2, FALSE);
tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_2, FALSE);
/* configure break and dead-time settings */
tmr_brkdt_struct.brk_enable = FALSE;
tmr_brkdt_struct.auto_output_enable = FALSE;

View File

@@ -30,6 +30,8 @@
/* private includes ----------------------------------------------------------*/
/* add user code begin private includes */
#include "dwt_delay.h"
#include "by_motion.h"
/* add user code end private includes */
/* private typedef -----------------------------------------------------------*/
@@ -71,7 +73,7 @@ int main(void)
{
/* add user code begin 1 */
/* add user code end 1 */
/* add user code end 1 */
/* system clock config. */
wk_system_clock_config();
@@ -82,9 +84,6 @@ int main(void)
/* init debug function. */
wk_debug_config();
/* init pwc function. */
wk_pwc_init();
/* nvic config. */
wk_nvic_config();
@@ -110,16 +109,14 @@ int main(void)
wk_gpio_config();
/* add user code begin 2 */
DWT_Init();
/* add user code end 2 */
DWT_Init();
by_motion_init();
/* add user code end 2 */
while(1)
{
/* add user code begin 3 */
gpio_bits_reset(GPIOB, GPIO_PINS_15);
DWT_Delay(500000);
gpio_bits_set(GPIOB, GPIO_PINS_15);
DWT_Delay(500000);
/* add user code end 3 */
/* add user code end 3 */
}
}