1、增加引脚定义适配新版本(V2.1)电路。
This commit is contained in:
@@ -30,8 +30,8 @@ void DCMOTORDBGOnOff(uint8_t OnOff)
|
||||
DBG_LOG("\r\nDcMotor Display Disable!\r\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if(MCU == HC32F460JETA)
|
||||
#if(0) //旧版本PCB
|
||||
/* Timer4 CNT */
|
||||
#define TIMER4_UNIT (M4_TMR41)
|
||||
#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_L_PORT (PortB) /* TIM4_1_OUL_B:PE8 TIM4_1_OVL_B:PE10 TIM4_1_OWL_B:PE12 */
|
||||
#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)
|
||||
@@ -86,7 +100,7 @@ void Timer41_Init(uint8_t dir)
|
||||
|
||||
|
||||
/* 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 */
|
||||
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);
|
||||
|
||||
/* Timer4 PWM: Initialize PWM configuration structure */
|
||||
//重载定时器中断
|
||||
stcPwmInit.enRtIntMaskCmd = Enable;
|
||||
stcPwmInit.enClkDiv = PwmPlckDiv1;
|
||||
stcPwmInit.enOutputState = E_PWM_OS; /*输出PWMH信号不改变电平,输出PWML信号反转*/
|
||||
stcPwmInit.enMode = PwmThroughMode;
|
||||
//计数时钟分频
|
||||
stcPwmInit.enClkDiv = PwmPlckDiv1; /*滤波计数器和死区计数器的计数时钟分频*/
|
||||
//PWM输出极性控制
|
||||
stcPwmInit.enOutputState = E_PWM_OS; /*输出PWMH信号不改变电平,输出PWML信号反转*/
|
||||
//PWM输出模式
|
||||
stcPwmInit.enMode = PwmThroughMode; /*直通模式*/
|
||||
TIMER4_PWM_Init(TIMER4_UNIT, TIMER4_PWM_CH, &stcPwmInit); /* Initialize timer4 pwm */
|
||||
|
||||
/* Clear && Start CNT */
|
||||
@@ -360,14 +378,14 @@ void dcmotor_init(void)
|
||||
PORT_Init(SHUTDOWN1_GPIO_Port, SHUTDOWN1_Pin, &stcPortInit);
|
||||
PORT_SetBits(SHUTDOWN1_GPIO_Port, SHUTDOWN1_Pin);
|
||||
|
||||
PORT_Init(PortA, Pin03, &stcPortInit);
|
||||
PORT_SetBits(PortA, Pin03);
|
||||
/* SD拉低,关闭输出 */
|
||||
|
||||
dcmotor_stop(); /* 停止电机 */
|
||||
dcmotor_dir(0); /* 设置正转 */
|
||||
dcmotor_speed(0); /* 速度设置为0 */
|
||||
dcmotor_start(); /* 开启电机 */
|
||||
// PORT_Init(PortA, Pin03, &stcPortInit);
|
||||
// PORT_SetBits(PortA, Pin03);
|
||||
// /* SD拉低,关闭输出 */
|
||||
//
|
||||
// dcmotor_stop(); /* 停止电机 */
|
||||
// dcmotor_dir(0); /* 设置正转 */
|
||||
// dcmotor_speed(0); /* 速度设置为0 */
|
||||
// dcmotor_start(); /* 开启电机 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,6 +511,8 @@ void dcmotor_speed(uint16_t para)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief 电机控制
|
||||
* @param para: pwm比较值 ,正数电机为正转,负数为反转
|
||||
|
||||
@@ -2,19 +2,29 @@
|
||||
#ifndef __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 TIMER6 1
|
||||
|
||||
#define TIMER TIMER4
|
||||
#define TIMER TIMER4 //HC32F460单片机PWM输出控制定时器选择
|
||||
#endif
|
||||
|
||||
// 电机控制参数
|
||||
#define PWM_PERIOD TIM_PERIOD // PWM周期值 (ARR)
|
||||
#define MAX_SPEED 480 // 最大速度(PWM占空比)
|
||||
#define ACCEL_STEP 10 // 加速步进值
|
||||
#define DECEL_STEP 10 // 减速步进值
|
||||
#define ACCEL_INTERVAL 10 // 加减速间隔(ms)
|
||||
#define ACCEL_INTERVAL 2 // 加减速间隔(ms)
|
||||
|
||||
|
||||
|
||||
@@ -46,17 +56,18 @@ typedef enum {
|
||||
/* 停止引脚操作宏定义
|
||||
* 此引脚控制H桥是否生效以达到开启和关闭电机的效果
|
||||
*/
|
||||
#define SHUTDOWN1_Pin Pin12
|
||||
#define SHUTDOWN1_Pin Pin07
|
||||
#define SHUTDOWN1_GPIO_Port PortB
|
||||
|
||||
//#define SHUTDOWN2_Pin GPIO_PIN_2
|
||||
//#define SHUTDOWN2_GPIO_Port GPIOF
|
||||
#define SHUTDOWN_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOF_CLK_ENABLE(); }while(0) /* PF口时钟使能 */
|
||||
|
||||
#if(MCU == HC32F460JETA)
|
||||
/* 电机停止引脚定义 这里默认是接口1 */
|
||||
#define ENABLE_MOTOR PORT_SetBits(SHUTDOWN1_GPIO_Port,SHUTDOWN1_Pin)
|
||||
#define DISABLE_MOTOR PORT_ResetBits(SHUTDOWN1_GPIO_Port,SHUTDOWN1_Pin)
|
||||
|
||||
#endif
|
||||
/******************************************************************************************/
|
||||
|
||||
void dcmotor_init(void); /* 直流有刷电机初始化 */
|
||||
|
||||
Reference in New Issue
Block a user