瀏覽代碼

增加直线加减速功能

feature/PLSR功能
1923777848 2 天之前
父節點
當前提交
42778b3d2c
共有 5 個檔案被更改,包括 518 行新增88 行删除
  1. +93
    -7
      TrainCamp_zhangcheng_PLSR/app/inc/plsr.h
  2. +366
    -62
      TrainCamp_zhangcheng_PLSR/app/src/plsr.c
  3. +26
    -1
      TrainCamp_zhangcheng_PLSR/bsp/src/gpio.c
  4. +32
    -17
      TrainCamp_zhangcheng_PLSR/bsp/src/time.c
  5. +1
    -1
      TrainCamp_zhangcheng_PLSR/system/src/system.c

+ 93
- 7
TrainCamp_zhangcheng_PLSR/app/inc/plsr.h 查看文件

@@ -9,7 +9,16 @@
*/


#include "../../modbus/inc/modbus.h"
#include "../../modbus/inc/modbus.h"


/**
* @brief 最大支持脉冲段
* @details
* @note
* @attention
*/
#define PLSR_PULSE_MAX_SEGMENT_NUM 10


/**
@@ -42,6 +51,57 @@ typedef enum {
} PLSR_OUTPUT_PORT;


/**
* @brief 输出方向端口
* @details
* @note
* @attention
*/
typedef enum {
OUTPUT_DIR_PORT_Y12 = 0, ///< 输出方向端子Y12
OUTPUT_DIR_PORT_Y13, ///< 输出方向端子Y13
OUTPUT_DIR_PORT_Y14, ///< 输出方向端子Y14
OUTPUT_DIR_PORT_Y15 ///< 输出方向端子Y15
} PLSR_OUTPUT_DIR_PORT;


/**
* @brief 方向端子方向逻辑
* @details
* @note
* @attention
*/
typedef enum {
OUTPUT_DIR_CORRECT = 0, ///< 正逻辑
OUTPUT_DIR_NEGATIVE, ///< 负逻辑
} PLSR_OUTPUT_DIR_PORT_LOGIC;


/**
* @brief 输入信号端口
* @details
* @note
* @attention
*/
typedef enum {
INPUT_EXT_PORT_X4 = 0, ///< 输入端子X4
INPUT_EXT_PORT_X5, ///< 输入端子X5
} PLSR_INPUT_EXT_PORT;


/**
* @brief 加减速模式模式
* @details
* @note
* @attention
*/
typedef enum {
STRAIGHT_LINE_MODE = 0, ///< 直线加减速模式
S_CURVE_MODE, ///< S曲线加减速模式
SINE_CURVE_MODE ///< 正弦曲线加减速模式
} PLSR_ACC_DEC_SPEED_MODE;


/**
* @brief 输出模式
* @details
@@ -66,6 +126,21 @@ typedef enum {
} PLSR_ERROR_TYPE;


/**
* @brief PLSR脉冲段
* @details
* @note
* @attention
*/
typedef struct
{
int32_t pulseFreq;
int32_t pulseNumber;
int16_t waitType;
int16_t jumpNumber;
} PLSR_SEGMENT;


/**
* @brief PLSR指令结构类型
* @details
@@ -74,12 +149,23 @@ typedef enum {
*/
typedef struct
{
uint16_t *dataStartAddr; ///< 起始数据地址
uint16_t *userParamBlockAddr; ///< 用户参数块地址
PLSR_SYSTEM_PARAM_BLOCK systemParamBlock; ///< 系统参数
PLSR_OUTPUT_PORT outputPort; ///< 输出端子
PLSR_OUTPUT_PORT mode; ///< 输出模式
} PLSR_CMD;
PLSR_OUTPUT_PORT outputPort; ///< 输出端子
PLSR_OUTPUT_DIR_PORT dirPort; ///< 输出方向端子
PLSR_INPUT_EXT_PORT extPort; ///< 输入端子
PLSR_OUTPUT_DIR_PORT_LOGIC dirLogic; ///< 输出方向端子逻辑
PLSR_ACC_DEC_SPEED_MODE accDecSpeedMode; ///< 加减速模式
PLSR_OUTPUT_MODE outMode; ///< 输出模式
uint16_t dirDelayTime; ///< 方向延时时间
uint16_t segmentAllNum; ///< 总段数
uint16_t startRunSegment; ///< 起始执行段数
uint16_t currentSegment; ///< 当前执行段数
uint32_t defaultSpeed; ///< 默认速度
uint16_t defaultAccSpeedTime; ///< 默认加速时间
uint16_t defaultDecSpeedTime; ///< 默认减速时间
int32_t monitorPulseNum; ///< 监控脉冲数量
uint16_t sendEnableState; ///< 脉冲发送使能
PLSR_SEGMENT segment[PLSR_PULSE_MAX_SEGMENT_NUM]; ///< 各段数参数
} PLSR;


/**


+ 366
- 62
TrainCamp_zhangcheng_PLSR/app/src/plsr.c 查看文件

@@ -12,6 +12,19 @@
#include "../../system/inc/system.h"
#include "../../bsp/inc/time.h"
#include "../inc/plsr.h"
#include "../../bsp/inc/gpio.h"


typedef struct {
int32_t inc;
int32_t dec;
int32_t currentSpeed;
uint8_t currentState; ///< 0:无操作 1:匀速 2:加速 3:减速
uint8_t currentPart;
int32_t firstPartNum;
int32_t secondPartNum;
int32_t thirdPartNum;
} SEGMENT_PART;


#define PLSR_MODULE_PRIO 5
@@ -19,6 +32,14 @@
static OS_STK PlsrModuleStack[PLSR_MODULE_STACK_SIZE];
static void PlsrModuleTask(void * pArg);

static void TimCallBack(void *pArg);
static void ReadRegisterParam(PLSR *plsr);
static void configPulsePort(PLSR *plsr);
static void ComputePartNum(PLSR *plsr, SEGMENT_PART *segmentPart);
static void FirstSegmentProc(SEGMENT_PART *segmentPart);
static void SecondSegmentProc(SEGMENT_PART *segmentPart);
static void ThirdSegmentProc(SEGMENT_PART *segmentPart);


/**
* @brief PLSR功能初始化
@@ -56,34 +77,6 @@ RESUIL PLSRInit(void)
}


#include "../../bsp/inc/gpio.h"
void Callack(void *pArg)
{
gpio_obj_t *gpio_f_6;
gpio_f_6 = get_gpio_obj("gpio_f");
gpio_f_6->gpio_init(gpio_f_6, gpio_pin_6, "OUT_PP", "UP");

if (*((uint8_t *)pArg) < 13)
printf("Callback tim2 count %d\r\n", (*((uint8_t *)pArg))++);
else
printf("Callback tim13 count %d\r\n", (*((uint8_t *)pArg))++);
uint16_t read_gpio_pin = 0;
read_gpio_pin = gpio_f_6->gpio_read_output(gpio_f_6);
if(gpio_f_6->gpio_pin & read_gpio_pin)
{
gpio_f_6->gpio_set_output(gpio_f_6, gpio_f_6->gpio_pin, 0);
#ifdef USE_LED_PIN_TRACE
pDev->led_state = "on";
#endif
}
else
{
gpio_f_6->gpio_set_output(gpio_f_6, gpio_f_6->gpio_pin, 1);
#ifdef USE_LED_PIN_TRACE
pDev->led_state = "off";
#endif
}
}
/**
* @brief PLSR处理任务
* @details
@@ -94,63 +87,374 @@ void Callack(void *pArg)
* @retval MODBUS_TURE 成功
* @retval MODBUS_FALSE 失败
*/
TIM_OBJ tim2;
TIM_OBJ tim10;
int32_t accSpeedSlope = 0;
int32_t decSpeedSlope = 0;
int32_t accTime = 0;
int32_t decTime = 0;
int32_t accPulse = 0;
int32_t decPulse = 0;
int32_t uniformTime = 0;
int32_t uniformPulse = 0;
uint8_t currentSegment = 0;
uint32_t currentSpeed = 0;


int32_t pulseFreq = 168 - 1;
uint32_t pulseReload = 20;
SEGMENT_PART currentSeg = {
.currentState = 2,
.currentPart = 1
};
PLSR plsr = {
.segmentAllNum = 1,
.segment[0].jumpNumber = 0
};
void PlsrModuleTask(void *pArg)
{
TIM_OBJ tim2;
TIM_OBJ tim10;
int8_t res;
uint8_t pArgment = 0;
uint8_t RunFlag = 0;


int32_t pulseFreq = 0;
int32_t pulseCount = 0;
uint32_t pulseReload = 0;
uint8_t nextSegment = plsr.startRunSegment;
// ReadRegisterParam(&plsr);

res = GetTimObj("tim2", &tim2);
res = GetTimObj("tim10", &tim10);
if (res)
while (1);
tim10.init(&tim10, 168 - 1, 65535);
// tim10.open(&tim10);
tim10.registerIrq(&tim10, TimCallBack, &currentSeg);
// tim10.openIrq(&tim10);
tim10.pwmInit(&tim10);
tim10.pwmSetPulse(&tim10, TIM10->ARR);

tim2.init(&tim2, 8399, 9999);
tim2.open(&tim2);
tim2.registerIrq(&tim2, &Callack, &pArgment);
tim2.openIrq(&tim2);
plsr.sendEnableState = 0;
plsr.accDecSpeedMode = STRAIGHT_LINE_MODE;
plsr.segment[0].pulseFreq = 2000;
plsr.segment[0].pulseNumber = 3000;
plsr.defaultSpeed = 1000;
plsr.defaultAccSpeedTime = 10;
plsr.defaultDecSpeedTime = 10;
while (1)
{
// ReadRegisterParam(&plsr);
currentSegment = plsr.currentSegment;

tim10.init(&tim10, pulseFreq, pulseCount * 2);
tim10.open(&tim10);
if (plsr.sendEnableState != 1)
{
continue;
}

if (pulseFreq >= 0 || pulseFreq <= 5000)
{
pulseReload = (uint32_t)(((1.f / (float)pulseFreq) * 1000 * 1000) / 20);
tim10.init(&tim10, 1679, pulseReload);
}
else if (pulseFreq >= 5000 || pulseFreq <= 100000)
{
pulseReload = (uint32_t)(((1.f / (float)pulseFreq) * 1000 * 1000) / 1);
tim10.init(&tim10, 83, pulseReload);
}
if (plsr.segment[currentSegment].pulseFreq <= 5000)
pulseFreq = 1680 - 1;
else if ((plsr.segment[currentSegment].pulseFreq > 5000)
&& (plsr.segment[currentSegment].pulseFreq <= 100000))
pulseFreq = 84 - 1;
else
continue;

tim10.pwmInit(&tim10);
tim10.pwmSetPulse(&tim10, pulseReload / 2);
/* 配置输入输出相关端子 */
configPulsePort(&plsr);

while (1)
{
if (plsr.outMode == ABSOLUTE_MODE)
{
if (plsr.monitorPulseNum
>= plsr.segment[currentSegment].pulseNumber)
{
continue;
}
}

if ((plsr.accDecSpeedMode == STRAIGHT_LINE_MODE) && (RunFlag == 0))
{
RunFlag = 1;

ComputePartNum(&plsr, &currentSeg);

switch (currentSeg.currentPart)
{
case 1:
{
FirstSegmentProc(&currentSeg);
break;
}
case 2:
{
SecondSegmentProc(&currentSeg);
break;
}
case 3:
{
ThirdSegmentProc(&currentSeg);
break;
}
}
}
}
}

//1HZ
//psc 1680
//psc 1680 一次10us
//per 50000

//5KHZ
//psc 1680
//per 10

//100KHZ
//psc 84
//per 840

//psc 168 一次0.5us
//per 10
//定时器3 外部输入时钟源ETR引脚PB4,定时器11输出
//定时器4 外部输入时钟源ETR引脚PB6,定时器14输出
//定时器9 内部输入时钟源ITx主从模式定时器10
//定时器12 内部输入时钟源ITx主从模式定时器13
//定时器12 内部输入时钟源ITx主从模式定时器13

void TimCallBack(void *pArg)
{
uint16_t reloadValue = 0;
uint32_t diffValue;
static int32_t pulseCount = 0;
static uint8_t endFlag = 0;

pulseCount++;
if (currentSeg.currentPart == 1)
{
switch (currentSeg.currentState)
{
case 2: ///< 加速
{
if ((currentSpeed + currentSeg.inc) >= plsr.segment[currentSegment].pulseFreq)
{
diffValue = currentSpeed + currentSeg.inc - plsr.segment[currentSegment].pulseFreq;
currentSeg.inc = currentSeg.inc - diffValue;
}
currentSpeed += currentSeg.inc;
reloadValue = 168000000 / (TIM10->PSC + 1) / (currentSpeed);
tim10.setPer(&tim10, reloadValue - 1);
tim10.pwmSetPulse(&tim10, TIM10->ARR / 2 + 1);

if (pulseCount > currentSeg.firstPartNum - 1)
{
currentSeg.currentPart = 2;
pulseCount = 0;
tim10.registerIrq(&tim10, TimCallBack, &currentSeg.currentPart);
}
break;
}
default:
{
break;
}
}
}
else if (currentSeg.currentPart == 2)
{
reloadValue = 168000000 / (TIM10->PSC + 1) / (currentSpeed);
tim10.setPer(&tim10, reloadValue - 1);
tim10.pwmSetPulse(&tim10, TIM10->ARR / 2 + 1);

if (pulseCount > currentSeg.secondPartNum - 1)
{
currentSeg.currentPart = 3;
pulseCount = 0;
tim10.registerIrq(&tim10, TimCallBack, &currentSeg.currentPart);

currentSeg.dec = currentSpeed / currentSeg.thirdPartNum;
}
}
else if (currentSeg.currentPart == 3)
{
if (((currentSpeed - currentSeg.dec) <= 0)
|| (pulseCount > currentSeg.thirdPartNum - 1))
{
pulseCount = 0;
currentSeg.currentPart = 1;
tim10.setPer(&tim10, 100);
tim10.pwmSetPulse(&tim10, 65535);
tim10.closeIrq(&tim10);

tim10.registerIrq(&tim10, TimCallBack, &currentSeg.currentPart);
return;
}
currentSpeed -= currentSeg.dec;
reloadValue = 168000000 / (TIM10->PSC + 1) / (currentSpeed);
tim10.setPer(&tim10, reloadValue - 1);
tim10.pwmSetPulse(&tim10, TIM10->ARR / 2 + 1);
}
}


static void ReadRegisterParam(PLSR *plsr)
{
int16_t *pDataRegister = (uint16_t *)(DATA_REGISTER_ADRR + 0x1000);

plsr->outputPort = pDataRegister[0];
plsr->dirPort = pDataRegister[1];
plsr->extPort = pDataRegister[2];
plsr->dirDelayTime = pDataRegister[3];
plsr->dirLogic = pDataRegister[4];
plsr->accDecSpeedMode = pDataRegister[5];
plsr->outMode = pDataRegister[6];
plsr->segmentAllNum = pDataRegister[7];
plsr->startRunSegment = pDataRegister[8];
plsr->defaultSpeed = *((uint32_t *)pDataRegister[9]);
plsr->defaultAccSpeedTime = pDataRegister[11];
plsr->defaultDecSpeedTime = pDataRegister[12];
plsr->monitorPulseNum = *((int32_t *)(pDataRegister + 0x1000));
plsr->sendEnableState = *(pDataRegister + 0x2000);

pDataRegister += 0x100;
for (uint8_t i = 0; i < PLSR_PULSE_MAX_SEGMENT_NUM; i++)
{
plsr->segment[i].pulseFreq = *((uint32_t *)pDataRegister[i]);
plsr->segment[i].pulseNumber = *((int32_t *)pDataRegister[i + 2]);
plsr->segment[i].waitType = pDataRegister[i + 4];
plsr->segment[i].jumpNumber = pDataRegister[i + 5];

pDataRegister += 0x10;
}
}


static void configPulsePort(PLSR *plsr)
{
gpio_obj_t *outDirPort = NULL;

outDirPort = get_gpio_obj("gpio_h");

if ((outDirPort == NULL) || (plsr == NULL))
return;

switch (plsr->dirPort)
{
case OUTPUT_DIR_PORT_Y12:
{
outDirPort->gpio_init(outDirPort, gpio_pin_9, "OUT_PP", "UP");
outDirPort->gpio_set_output(outDirPort, gpio_pin_9, 1);
break;
}
case OUTPUT_DIR_PORT_Y13:
{
outDirPort->gpio_init(outDirPort, gpio_pin_8, "OUT_PP", "UP");
break;
}
case OUTPUT_DIR_PORT_Y14:
{
outDirPort->gpio_init(outDirPort, gpio_pin_7, "OUT_PP", "UP");
break;
}
case OUTPUT_DIR_PORT_Y15:
{
outDirPort->gpio_init(outDirPort, gpio_pin_6, "OUT_PP", "UP");
break;
}
}
// switch (plsr->outputPort)
// {
// case OUTPUT_PORT_Y0:
// {
// outDirPort->gpio_init(outDirPort, gpio_pin)
// }
// }
}


static void ComputePartNum(PLSR *plsr, SEGMENT_PART *segmentPart)
{
uint32_t target = plsr->segment[currentSegment].pulseFreq;
accSpeedSlope = plsr->defaultSpeed / plsr->defaultAccSpeedTime;
decSpeedSlope = plsr->defaultSpeed / plsr->defaultDecSpeedTime;

/* 最后一段 */
if ((currentSegment == (plsr->segmentAllNum -1))
&& (plsr->segment[currentSegment].jumpNumber == 0))
{
decTime = target / decSpeedSlope;
segmentPart->thirdPartNum = target / 2 * decTime / 1000;
}
else
{
segmentPart->thirdPartNum = 0;
}

if (currentSpeed < target)
{
accTime = (target - currentSpeed) / accSpeedSlope;
segmentPart->firstPartNum = (target + currentSpeed) / 2 * accTime / 1000;
}
else if (currentSpeed > target)
{
decTime = (currentSpeed - target) / decSpeedSlope;
segmentPart->firstPartNum = (target + currentSpeed) / 2 * decTime / 1000;
}
segmentPart->secondPartNum = plsr->segment[currentSegment].pulseNumber
- segmentPart->firstPartNum
- segmentPart->thirdPartNum;
}


static void FirstSegmentProc(SEGMENT_PART *segmentPart)
{
int32_t targetFreq = 0;
int32_t slope = 0;
int32_t diffValue = 0;
static int32_t incAll = 0;

switch (segmentPart->currentState)
{
case 2 :
{
targetFreq = plsr.segment[currentSegment].pulseFreq;
slope = plsr.defaultSpeed / plsr.defaultAccSpeedTime;
segmentPart->inc = ((targetFreq - currentSpeed) / slope)
* ((targetFreq + currentSpeed) / 2) / 1000;
segmentPart->inc = (targetFreq - currentSpeed) / segmentPart->inc;
if ((currentSpeed + segmentPart->inc) >= plsr.segment[currentSegment].pulseFreq)
{
diffValue = currentSpeed + segmentPart->inc - plsr.segment[currentSegment].pulseFreq;
segmentPart->inc = segmentPart->inc - diffValue;
}
incAll += segmentPart->inc;
if (plsr.segment[currentSegment].pulseFreq <= 5000)
{
tim10.setPsc(&tim10, 1680 - 1);
if (currentSpeed != 0)
tim10.setPer(&tim10, 100000 / currentSpeed);
else
tim10.setPer(&tim10, 1000);
tim10.registerIrq(&tim10, TimCallBack, &currentSeg.currentPart);
tim10.open(&tim10);
tim10.openIrq(&tim10);
}
else
{
tim10.setPsc(&tim10, 168 - 1);
tim10.setPer(&tim10, 1000000 / currentSpeed);
tim10.registerIrq(&tim10, TimCallBack, &currentSeg.currentPart);
tim10.open(&tim10);
tim10.openIrq(&tim10);
}
}
}
}


static void SecondSegmentProc(SEGMENT_PART *segmentPart)
{

}


static void ThirdSegmentProc(SEGMENT_PART *segmentPart)
{

}

+ 26
- 1
TrainCamp_zhangcheng_PLSR/bsp/src/gpio.c 查看文件

@@ -187,6 +187,30 @@ static gpio_obj_t g_stm32f103_gpio_g = {
&g_stm32f103_gpio_g_priv
};


/* GPIOH私有数据 */
static gpio_priv_obj_t g_stm32f103_gpio_h_priv = {
GPIOH,
GPIO_Mode_IN,
(GPIOOType_TypeDef)0,
(GPIOPuPd_TypeDef)0,
RCC_AHB1Periph_GPIOH
};
/* GPIOH结构体对象 */
static gpio_obj_t g_stm32f103_gpio_h = {
"gpio_h",
0,
"gpio_mode",
gpio_init,
gpio_deinit,
gpio_set_output,
gpio_read_output,
gpio_read_input,
gpio_open_irq,
gpio_close_irq,
&g_stm32f103_gpio_h_priv
};

/* GPIO外设列表 */
static gpio_obj_t *g_gpio_devs[] = {
&g_stm32f103_gpio_a,
@@ -195,7 +219,8 @@ static gpio_obj_t *g_gpio_devs[] = {
&g_stm32f103_gpio_d,
&g_stm32f103_gpio_e,
&g_stm32f103_gpio_f,
&g_stm32f103_gpio_g
&g_stm32f103_gpio_g,
&g_stm32f103_gpio_h
};

/* GPIO模式私有数据列表 */


+ 32
- 17
TrainCamp_zhangcheng_PLSR/bsp/src/time.c 查看文件

@@ -20,14 +20,14 @@ typedef void (*Func)(void *pArg);
static Func CallBackFuncList[] =
{
NULL, ///< TIM2
NULL ///< TIM13
NULL ///< TIM10
};

/* 中断注册回调参数列表 */
static void *ArgList[] =
{
NULL, ///< TIM2
NULL ///< TIM13
NULL ///< TIM10
};

/* 可用定时器列表 */
@@ -86,7 +86,11 @@ int8_t TimInit(TIM_OBJ *tim, uint16_t psc, uint32_t per)
else
return -1;

TIM_InternalClockConfig(tim->TIM);
if (tim->TIM == TIM2)
//TIM_TIxExternalClockConfig(tim->TIM, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 10);
TIM_InternalClockConfig(tim->TIM);
else
TIM_InternalClockConfig(tim->TIM);

TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
@@ -94,7 +98,8 @@ int8_t TimInit(TIM_OBJ *tim, uint16_t psc, uint32_t per)
TIM_TimeBaseInitStructure.TIM_Prescaler=psc;
TIM_TimeBaseInit(tim->TIM, &TIM_TimeBaseInitStructure);

TIM_GenerateEvent(tim->TIM, TIM_EventSource_Update);
// TIM_GenerateEvent(tim->TIM, TIM_EventSource_Update);
TIM_ClearITPendingBit(tim->TIM, TIM_IT_Update);

return 0;
}
@@ -140,6 +145,7 @@ void TimDeInit(TIM_OBJ *tim)
void TimSetPsc(TIM_OBJ *tim, uint16_t psc)
{
TIM_PrescalerConfig(tim->TIM, psc, TIM_PSCReloadMode_Immediate);
TIM_ClearITPendingBit(tim->TIM, TIM_IT_Update);
}


@@ -203,8 +209,8 @@ void TimOpenIrq(TIM_OBJ *tim)
if (tim->TIM == TIM2)
NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn;
else if(tim->TIM == TIM13)
NVIC_InitStructure.NVIC_IRQChannel=TIM8_UP_TIM13_IRQn;
else if(tim->TIM == TIM10)
NVIC_InitStructure.NVIC_IRQChannel=TIM1_UP_TIM10_IRQn;
else
return;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=7;
@@ -246,7 +252,7 @@ void TimRegisterIrq(TIM_OBJ *tim, void (*registerFunc)(void *pArg), void *pArg)
CallBackFuncList[0] = registerFunc;
ArgList[0] = pArg;
}
else if (tim->TIM == TIM13)
else if (tim->TIM == TIM10)
{
CallBackFuncList[1] = registerFunc;
ArgList[1] = pArg;
@@ -269,13 +275,22 @@ void PwmInit(TIM_OBJ *tim)
{
TIM_OCInitTypeDef TIM_OCInitStructure;

TIM_OCStructInit(&TIM_OCInitStructure);

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OutputState = ENABLE;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC1Init(tim->TIM, &TIM_OCInitStructure);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
GPIO_PinAFConfig(GPIOF, GPIO_PinSource6, GPIO_AF_TIM10);

GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructure);

TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OutputState = ENABLE;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC1Init(tim->TIM, &TIM_OCInitStructure);
}


@@ -339,13 +354,13 @@ void TIM2_IRQHandler(void)
*
* @return 无
*/
void TIM8_UP_TIM13_IRQHandler(void)
void TIM1_UP_TIM10_IRQHandler(void)
{
if (TIM_GetITStatus(TIM13,TIM_IT_Update) == SET)
if (TIM_GetITStatus(TIM10,TIM_IT_Update) == SET)
{
if (ArgList[1] != NULL)
CallBackFuncList[1](ArgList[1]);
TIM_ClearITPendingBit(TIM13, TIM_IT_Update);
TIM_ClearITPendingBit(TIM10, TIM_IT_Update);
}
}



+ 1
- 1
TrainCamp_zhangcheng_PLSR/system/src/system.c 查看文件

@@ -8,5 +8,5 @@ void system_hardware_init(void)
usart1 = get_usart_obj("usart1");
if(NULL == usart1)
while(1);
usart1->usart_init(usart1, 19200, 9, 1, 2);
usart1->usart_init(usart1, 19200, 9, 1, 1);
}

Loading…
取消
儲存