1、增加引脚定义适配新版本(V2.1)电路。

This commit is contained in:
cui635
2025-10-12 19:59:47 +08:00
parent 66ca2c8004
commit b2c97d6a78
6 changed files with 115 additions and 49 deletions
+18 -24
View File
@@ -3,19 +3,16 @@
{ {
"name": "Debug", "name": "Debug",
"includePath": [ "includePath": [
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\driver\\inc", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\mcu\\common",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\mcu\\common", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\Project\\HC32F460\\source\\User\\Inc",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\User\\Inc", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\Project\\HC32F460\\source\\User\\Src",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\Module\\Debug", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\driver\\src",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\Module\\SDCard", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\driver\\inc",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\Module\\FatFS\\source", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\Project\\HC32F460\\source\\Module\\CS1237",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\Module\\LIS2HH12", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\Project\\HC32F460\\source\\Module\\dc_motor",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\Module\\RS485",
"C:\\Keil_v5\\ARM\\ARMCC\\include", "C:\\Keil_v5\\ARM\\ARMCC\\include",
"C:\\Keil_v5\\ARM\\ARMCC\\include\\rw", "C:\\Keil_v5\\ARM\\ARMCC\\include\\rw",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\MDK", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\Project\\HC32F460\\MDK"
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\User\\Src",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\driver\\src"
], ],
"defines": [ "defines": [
"__DEBUG", "__DEBUG",
@@ -100,21 +97,18 @@
{ {
"name": "Release", "name": "Release",
"includePath": [ "includePath": [
"d:\\CUI\\Electronics\\SynologyDrive\\mcu\\common", "d:\\CUI\\SynologyDrive\\JOB\\mcu\\common",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\Project\\HC32F460\\source",
"d:\\CUI\\Electronics\\SynologyDrive\\driver\\inc", "d:\\CUI\\SynologyDrive\\JOB\\driver\\inc",
"d:\\CUI\\Electronics\\SynologyDrive\\bsp\\ev_hc32f460_lqfp100_v2", "d:\\CUI\\SynologyDrive\\JOB\\bsp\\ev_hc32f460_lqfp100_v2",
"C:\\Keil_v5\\ARM\\ARMCC\\include", "C:\\Keil_v5\\ARM\\ARMCC\\include",
"C:\\Keil_v5\\ARM\\ARMCC\\include\\rw", "C:\\Keil_v5\\ARM\\ARMCC\\include\\rw",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\MDK", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\Project\\HC32F460\\MDK",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\mcu\\common", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\mcu\\common",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\User\\Src", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\driver\\src",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\driver\\src", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\Project\\HC32F460\\source\\User\\Src",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\Module\\Debug", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\Project\\HC32F460\\source\\Module\\CS1237",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\Module\\SDCard", "d:\\CUI\\SynologyDrive\\JOB\\Project\\HC32F460\\Project\\HC32F460\\source\\Module\\dc_motor"
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\Module\\FatFS\\source",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\Module\\LIS2HH12",
"d:\\CUI\\Electronics\\SynologyDrive\\HC32F460PRO\\HC32F460JEUA-SonarSenser_V1.5-2024-04-10\\Project\\SonarSensor\\source\\Module\\RS485"
], ],
"defines": [ "defines": [
"HC32F460", "HC32F460",
+14
View File
@@ -20,3 +20,17 @@
[info] Log at : 2024/6/12|17:35:35|GMT+0800 [info] Log at : 2024/6/12|17:35:35|GMT+0800
[info] Log at : 2025/9/17|09:28:29|GMT+0800
[info] Log at : 2025/9/17|09:28:37|GMT+0800
[info] Log at : 2025/9/17|11:25:21|GMT+0800
[info] Log at : 2025/9/17|11:30:43|GMT+0800
[info] Log at : 2025/9/18|09:27:20|GMT+0800
[info] project closed: HC32F460
[info] Log at : 2025/9/19|10:56:08|GMT+0800
[info] project closed: HC32F460
+31 -5
View File
@@ -150,16 +150,16 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>DLGUARM</Key> <Key>DLGUARM</Key>
<Name>?</Name> <Name></Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint> <Breakpoint>
<Bp> <Bp>
<Number>0</Number> <Number>0</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>57</LineNumber> <LineNumber>71</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
<Address>30944</Address> <Address>17972</Address>
<ByteObject>0</ByteObject> <ByteObject>0</ByteObject>
<HtxType>0</HtxType> <HtxType>0</HtxType>
<ManyObjects>0</ManyObjects> <ManyObjects>0</ManyObjects>
@@ -168,7 +168,23 @@
<BreakIfRCount>1</BreakIfRCount> <BreakIfRCount>1</BreakIfRCount>
<Filename>..\source\Module\dc_motor\dc_motor.c</Filename> <Filename>..\source\Module\dc_motor\dc_motor.c</Filename>
<ExecCommand></ExecCommand> <ExecCommand></ExecCommand>
<Expression>\\BombSensor\../source/Module/dc_motor/dc_motor.c\57</Expression> <Expression>\\BombSensor\../source/Module/dc_motor/dc_motor.c\71</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>747</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>6022</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\source\Module\dc_motor\dc_motor.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\BombSensor\../source/Module/dc_motor/dc_motor.c\747</Expression>
</Bp> </Bp>
</Breakpoint> </Breakpoint>
<WatchWindow1> <WatchWindow1>
@@ -262,6 +278,16 @@
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>DcMotorDispEn</ItemText> <ItemText>DcMotorDispEn</ItemText>
</Ww> </Ww>
<Ww>
<count>18</count>
<WinNumber>1</WinNumber>
<ItemText>newSpeed,0x0A</ItemText>
</Ww>
<Ww>
<count>19</count>
<WinNumber>1</WinNumber>
<ItemText>g_motorSpeed,0x0A</ItemText>
</Ww>
</WatchWindow1> </WatchWindow1>
<Tracepoint> <Tracepoint>
<THDelay>0</THDelay> <THDelay>0</THDelay>
@@ -1058,7 +1084,7 @@
<GroupNumber>3</GroupNumber> <GroupNumber>3</GroupNumber>
<FileNumber>49</FileNumber> <FileNumber>49</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>1</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\source\User\Src\Debug.c</PathWithFileName> <PathWithFileName>..\source\User\Src\Debug.c</PathWithFileName>
@@ -30,8 +30,8 @@ void DCMOTORDBGOnOff(uint8_t OnOff)
DBG_LOG("\r\nDcMotor Display Disable!\r\n"); DBG_LOG("\r\nDcMotor Display Disable!\r\n");
} }
#if(MCU == HC32F460JETA)
#if(0) //旧版本PCB
/* Timer4 CNT */ /* Timer4 CNT */
#define TIMER4_UNIT (M4_TMR41) #define TIMER4_UNIT (M4_TMR41)
#define TIMER4_CNT_CYCLE_VAL (500u) /* Timer4 counter cycle value */ #define TIMER4_CNT_CYCLE_VAL (500u) /* Timer4 counter cycle value */
@@ -47,10 +47,24 @@ void DCMOTORDBGOnOff(uint8_t OnOff)
#define TIMER4_PWM_H_PIN (Pin08) #define TIMER4_PWM_H_PIN (Pin08)
#define TIMER4_PWM_L_PORT (PortB) /* TIM4_1_OUL_B:PE8 TIM4_1_OVL_B:PE10 TIM4_1_OWL_B:PE12 */ #define TIMER4_PWM_L_PORT (PortB) /* TIM4_1_OUL_B:PE8 TIM4_1_OVL_B:PE10 TIM4_1_OWL_B:PE12 */
#define TIMER4_PWM_L_PIN (Pin13) #define TIMER4_PWM_L_PIN (Pin13)
#endif
#if(1) //V2.1版本PCB
/* Timer4 CNT */
#define TIMER4_UNIT (M4_TMR41)
#define TIMER4_CNT_CYCLE_VAL (500u) /* Timer4 counter cycle value */
/* Timer4 OCO */
#define TIMER4_OCO_HIGH_CH (Timer4OcoOvh) /* only Timer4OcoOuh Timer4OcoOvh Timer4OcoOwh */
/* Timer4 PWM */
#define TIMER4_PWM_CH (Timer4PwmV) /* only Timer4PwmU Timer4PwmV Timer4PwmW */
#define TIMER4_PWM_H_PORT (PortA) /* TIM4_1_OUH_B:PE9 TIM4_1_OVH_B:PE11 TIM4_1_OWH_B:PE13 */
#define TIMER4_PWM_H_PIN (Pin09)
#define TIMER4_PWM_L_PORT (PortB) /* TIM4_1_OUL_B:PE8 TIM4_1_OVL_B:PE10 TIM4_1_OWL_B:PE12 */
#define TIMER4_PWM_L_PIN (Pin14)
#endif
void Timer41_Init(uint8_t dir) void Timer41_Init(uint8_t dir)
@@ -86,7 +100,7 @@ void Timer41_Init(uint8_t dir)
/* Enable peripheral clock */ /* Enable peripheral clock */
PWC_Fcg2PeriphClockCmd(PWC_FCG2_PERIPH_TIM41 | PWC_FCG2_PERIPH_TIM42 | PWC_FCG2_PERIPH_TIM43, Enable); PWC_Fcg2PeriphClockCmd(PWC_FCG2_PERIPH_TIM41, Enable);
/* Timer4 CNT : Initialize CNT configuration structure */ /* Timer4 CNT : Initialize CNT configuration structure */
stcCntInit.enBufferCmd = Disable; stcCntInit.enBufferCmd = Disable;
@@ -178,10 +192,14 @@ void Timer41_Init(uint8_t dir)
PORT_SetFunc(TIMER4_PWM_L_PORT, TIMER4_PWM_L_PIN, Func_Tim4, Disable); PORT_SetFunc(TIMER4_PWM_L_PORT, TIMER4_PWM_L_PIN, Func_Tim4, Disable);
/* Timer4 PWM: Initialize PWM configuration structure */ /* Timer4 PWM: Initialize PWM configuration structure */
//重载定时器中断
stcPwmInit.enRtIntMaskCmd = Enable; stcPwmInit.enRtIntMaskCmd = Enable;
stcPwmInit.enClkDiv = PwmPlckDiv1; //计数时钟分频
stcPwmInit.enClkDiv = PwmPlckDiv1; /*滤波计数器和死区计数器的计数时钟分频*/
//PWM输出极性控制
stcPwmInit.enOutputState = E_PWM_OS; /*输出PWMH信号不改变电平,输出PWML信号反转*/ stcPwmInit.enOutputState = E_PWM_OS; /*输出PWMH信号不改变电平,输出PWML信号反转*/
stcPwmInit.enMode = PwmThroughMode; //PWM输出模式
stcPwmInit.enMode = PwmThroughMode; /*直通模式*/
TIMER4_PWM_Init(TIMER4_UNIT, TIMER4_PWM_CH, &stcPwmInit); /* Initialize timer4 pwm */ TIMER4_PWM_Init(TIMER4_UNIT, TIMER4_PWM_CH, &stcPwmInit); /* Initialize timer4 pwm */
/* Clear && Start CNT */ /* Clear && Start CNT */
@@ -360,14 +378,14 @@ void dcmotor_init(void)
PORT_Init(SHUTDOWN1_GPIO_Port, SHUTDOWN1_Pin, &stcPortInit); PORT_Init(SHUTDOWN1_GPIO_Port, SHUTDOWN1_Pin, &stcPortInit);
PORT_SetBits(SHUTDOWN1_GPIO_Port, SHUTDOWN1_Pin); PORT_SetBits(SHUTDOWN1_GPIO_Port, SHUTDOWN1_Pin);
PORT_Init(PortA, Pin03, &stcPortInit); // PORT_Init(PortA, Pin03, &stcPortInit);
PORT_SetBits(PortA, Pin03); // PORT_SetBits(PortA, Pin03);
/* SD拉低,关闭输出 */ // /* SD拉低,关闭输出 */
//
dcmotor_stop(); /* 停止电机 */ // dcmotor_stop(); /* 停止电机 */
dcmotor_dir(0); /* 设置正转 */ // dcmotor_dir(0); /* 设置正转 */
dcmotor_speed(0); /* 速度设置为0 */ // dcmotor_speed(0); /* 速度设置为0 */
dcmotor_start(); /* 开启电机 */ // dcmotor_start(); /* 开启电机 */
} }
/** /**
@@ -493,6 +511,8 @@ void dcmotor_speed(uint16_t para)
} }
} }
#endif
/** /**
* @brief 电机控制 * @brief 电机控制
* @param para: pwm比较值 ,正数电机为正转,负数为反转 * @param para: pwm比较值 ,正数电机为正转,负数为反转
@@ -2,19 +2,29 @@
#ifndef __DCMOTOR_H #ifndef __DCMOTOR_H
#define __DCMOTOR_H #define __DCMOTOR_H
#include "hc32_ddl.h"
#define HC32F170 (0u) //HC32F170JATA
#define HC32L170 (1u) //HC32L170JATA
#define HC32F460JETA (2u) //HC32F460JETA
#define MCU HC32F460JETA
#if(MCU == HC32F460JETA)
#include "hc32_ddl.h"
#define TIMER4 0 #define TIMER4 0
#define TIMER6 1 #define TIMER6 1
#define TIMER TIMER4 #define TIMER TIMER4 //HC32F460单片机PWM输出控制定时器选择
#endif
// 电机控制参数 // 电机控制参数
#define PWM_PERIOD TIM_PERIOD // PWM周期值 (ARR) #define PWM_PERIOD TIM_PERIOD // PWM周期值 (ARR)
#define MAX_SPEED 480 // 最大速度(PWM占空比) #define MAX_SPEED 480 // 最大速度(PWM占空比)
#define ACCEL_STEP 10 // 加速步进值 #define ACCEL_STEP 10 // 加速步进值
#define DECEL_STEP 10 // 减速步进值 #define DECEL_STEP 10 // 减速步进值
#define ACCEL_INTERVAL 10 // 加减速间隔(ms) #define ACCEL_INTERVAL 2 // 加减速间隔(ms)
@@ -46,17 +56,18 @@ typedef enum {
/* 停止引脚操作宏定义 /* 停止引脚操作宏定义
* 此引脚控制H桥是否生效以达到开启和关闭电机的效果 * 此引脚控制H桥是否生效以达到开启和关闭电机的效果
*/ */
#define SHUTDOWN1_Pin Pin12 #define SHUTDOWN1_Pin Pin07
#define SHUTDOWN1_GPIO_Port PortB #define SHUTDOWN1_GPIO_Port PortB
//#define SHUTDOWN2_Pin GPIO_PIN_2 //#define SHUTDOWN2_Pin GPIO_PIN_2
//#define SHUTDOWN2_GPIO_Port GPIOF //#define SHUTDOWN2_GPIO_Port GPIOF
#define SHUTDOWN_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOF_CLK_ENABLE(); }while(0) /* PF口时钟使能 */ #define SHUTDOWN_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOF_CLK_ENABLE(); }while(0) /* PF口时钟使能 */
#if(MCU == HC32F460JETA)
/* 电机停止引脚定义 这里默认是接口1 */ /* 电机停止引脚定义 这里默认是接口1 */
#define ENABLE_MOTOR PORT_SetBits(SHUTDOWN1_GPIO_Port,SHUTDOWN1_Pin) #define ENABLE_MOTOR PORT_SetBits(SHUTDOWN1_GPIO_Port,SHUTDOWN1_Pin)
#define DISABLE_MOTOR PORT_ResetBits(SHUTDOWN1_GPIO_Port,SHUTDOWN1_Pin) #define DISABLE_MOTOR PORT_ResetBits(SHUTDOWN1_GPIO_Port,SHUTDOWN1_Pin)
#endif
/******************************************************************************************/ /******************************************************************************************/
void dcmotor_init(void); /* 直流有刷电机初始化 */ void dcmotor_init(void); /* 直流有刷电机初始化 */
+2 -1
View File
@@ -8,6 +8,7 @@
#include "CS1237_RIGHTUP.h" #include "CS1237_RIGHTUP.h"
#include "CS1237_RIGHTLOW.h" #include "CS1237_RIGHTLOW.h"
#include "dc_motor.h"
#define SPI_MASTER_MODE #define SPI_MASTER_MODE
#define SPI3_MASTER_MODE #define SPI3_MASTER_MODE
@@ -1357,7 +1358,7 @@ void BSP_Init(void)
//SdioInit(); //SdioInit();
//Spi_Config(); //Spi_Config();
// Spi3_Config(); // Spi3_Config();
dcmotor_init();
//Adc1_Config(); //Adc1_Config();
//Dma_Config(); //Dma_Config();
//FeedDog(); //FeedDog();