赞
踩
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。
提示:以下是本篇文章正文内容,下面案例可供参考
步进电机驱动芯片,里面包含加减速算法等
底层硬件SPI驱动文件:
- /****************************************************************
- *文件名:SPI.c
- *版本:v1.0
- *作者:JOHN.FENG
- *描述:使用的是STM32内部SPI资源,为了避免多个使用,采用为面向对象编程的方式
- ****************************************************************/
- #include "mcu_spi.h"
-
- SPI_InitTypeDef SPI_InitStructure;
-
-
- /**
- * @brief SPI引脚初始化
- * @param MCU_SPIx 结构体配置相对应的SPI引脚通道 目前只支持SPI1,SPI2
- * @retval None
- */
- void MCU_SPI_Init(MCU_SPIx *pScr)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- switch(pScr->MCU_SPI_ClockCmd )
- {
- //根据相对应的SPI通道初始化相对应的时钟
- case MCU_SPI1_ClockCmd:
- RCC_SPI1_PeriphClockCmd;
- break;
- case MCU_SPI2_ClockCmd:
- {
- RCC_GPIO_PeriphClockCmd;
- RCC_SPI2_PeriphClockCmd;
- }
- break;
- }
- // RCC_SPI1_PeriphClockCmd;
-
- //PA4 --- SPI1_NSS PA5 ----- SPI1_SCK PA6 ----- SPI1_MISO
- //PA7 --- SPI1_MISI
- GPIO_InitStructure.GPIO_Pin = pScr->MCU_SPI_CLK | pScr->MCU_SPI_MISI | pScr->MCU_SPI_MISO;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(pScr->MCU_SPI_GPIOx, &GPIO_InitStructure);
-
- GPIO_SetBits(pScr->MCU_SPI_GPIOx, pScr->MCU_SPI_CLK | pScr->MCU_SPI_MISI | pScr->MCU_SPI_MISO);
-
- GPIO_InitStructure.GPIO_Pin = pScr->MCU_SPI_CSN ;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(pScr->MCU_SPI_GPIOx, &GPIO_InitStructure);//初始化GPIOB
-
- SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //设置SPI单向或者双向的数据模式:SPI设置为双线双向全双工
- SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //设置SPI工作模式:设置为主SPI
- SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //设置SPI的数据大小:SPI发送接收8位帧结构
- SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //选择了串行时钟的稳态:时钟悬空高
- SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //数据捕获于第二个时钟沿
- SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //NSS信号由硬件(NSS管脚)还是软件(使用SSI位)管理:内部NSS信号有SSI位控制
- SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128; //定义波特率预分频的值:波特率预分频值为256
- SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //指定数据传输从MSB位还是LSB位开始:数据传输从MSB位开始
- SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC值计算的多项式
- SPI_Init(pScr->SPIx, &SPI_InitStructure); //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
-
- SPI_Cmd(pScr->SPIx, ENABLE); //使能SPI外设
-
-
- }
- //SPI 速度设置函数
- //SpeedSet:
- //SPI_BaudRatePrescaler_2 2分频 (SPI 36M@sys 72M)
- //SPI_BaudRatePrescaler_8 8分频 (SPI 9M@sys 72M)
- //SPI_BaudRatePrescaler_16 16分频 (SPI 4.5M@sys 72M)
- //SPI_BaudRatePrescaler_256 256分频 (SPI 281.25K@sys 72M)
-
- void SPI_SetSpeed(MCU_SPIx *pScr,uint8_t SpeedSet)
- {
- SPI_InitStructure.SPI_BaudRatePrescaler = SpeedSet ;
- SPI_Init(pScr->SPIx, &SPI_InitStructure);
- SPI_Cmd(pScr->SPIx, ENABLE);
- }
-
-
-
-
- uint8_t spi_read_write(MCU_SPIx *pScr,uint8_t byte)
- {
- /* Loop while DR register in not emplty */
- while (SPI_I2S_GetFlagStatus(pScr->SPIx, SPI_I2S_FLAG_TXE) == RESET);
-
- /* Send byte through the SPI2 peripheral */
- SPI_I2S_SendData(pScr->SPIx, byte);
-
- /* Wait to receive a byte */
- while (SPI_I2S_GetFlagStatus(pScr->SPIx, SPI_I2S_FLAG_RXNE) == RESET);
-
- /* Return the byte read from the SPI bus */
- return SPI_I2S_ReceiveData(pScr->SPIx);
- }
mcu_spi.h
-
- /****************************************************************
- *文件名:SPI.h
- *版本:v1.0
- *作者:JOHN.FENG
- *描述:使用的是STM32内部SPI资源,为了避免多个使用,采用为面向对象编程的方式
- ****************************************************************/
- #ifndef __MCU_SPI_H
- #define __MCU_SPI_H
- #include "sys.h"
-
- //STM32 内部资源SPI1引脚外设
- #define RCC_SPI1_PeriphClockCmd RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE)
- #define MCU_SPI1_GPIOx GPIOA
- #define MCU_SPI1_CSN_PIN GPIO_Pin_4
- #define MCU_SPI1_CLK_PIN GPIO_Pin_5
- #define MCU_SPI1_MISO_PIN GPIO_Pin_6
- #define MCU_SPI1_MISI_PIN GPIO_Pin_7
-
- //STM32 内部资源SPI2引脚外设
- //https://it.cha138.com/javascript/show-62584.html
- #define RCC_SPI2_PeriphClockCmd RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE)
- #define RCC_GPIO_PeriphClockCmd RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE)
- #define MCU_SPI2_GPIOx GPIOB
- #define MCU_SPI2_CSN_PIN GPIO_Pin_12
- #define MCU_SPI2_CLK_PIN GPIO_Pin_13
- #define MCU_SPI2_MISO_PIN GPIO_Pin_14
- #define MCU_SPI2_MISI_PIN GPIO_Pin_15
- typedef enum
- {
- MCU_SPI1_ClockCmd,
- MCU_SPI2_ClockCmd
-
- }MCU_SPIx_clock;
-
- typedef struct MCU_SPIx_Type
- {
- SPI_TypeDef* SPIx;
- MCU_SPIx_clock MCU_SPI_ClockCmd;
- GPIO_TypeDef *MCU_SPI_GPIOx;
- uint16_t MCU_SPI_CSN;
- uint16_t MCU_SPI_CLK;
- uint16_t MCU_SPI_MISO;
- uint16_t MCU_SPI_MISI;
-
- }MCU_SPIx;
-
- //MCU_SPIx spi1={
- // .SPIx = SPI1,
- // .MCU_SPI_ClockCmd = MCU_SPI1_ClockCmd,
- // .MCU_SPI_GPIOx = MCU_SPI1_GPIOx,
- // .MCU_SPI_CSN = MCU_SPI1_CSN_PIN,
- // .MCU_SPI_CLK = MCU_SPI1_CLK_PIN,
- // .MCU_SPI_MISO = MCU_SPI1_MISO_PIN,
- // .MCU_SPI_MISI = MCU_SPI1_MISI_PIN
- //};
-
- //MCU_SPIx spi2={
- // .SPIx = SPI2,
- // .MCU_SPI_ClockCmd = MCU_SPI2_ClockCmd,
- // .MCU_SPI_GPIOx = MCU_SPI2_GPIOx,
- // .MCU_SPI_CSN = MCU_SPI2_CSN_PIN,
- // .MCU_SPI_CLK = MCU_SPI2_CLK_PIN,
- // .MCU_SPI_MISO = MCU_SPI2_MISO_PIN,
- // .MCU_SPI_MISI = MCU_SPI2_MISI_PIN
- //};
-
- //#define pTMC_MISO PAout(6) //33
- //#define pTMC_MOSI PAout(7) //32
- //#define pTMC_CLK PAout(5) //31
- //#define pTMC_CSN0 PAout(4) //30
-
- //#define pTMC_MOSI GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_7);
- //#define pTMC_MISO GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_6);
- //#define pTMC_CLK GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5);
-
-
-
- void MCU_SPI_Init(MCU_SPIx *pScr);
-
- void SPI_SetSpeed(MCU_SPIx *pScr,uint8_t SpeedSet);
- uint8_t spi_read_write(MCU_SPIx *pScr,uint8_t byte);
-
-
- #endif
tm4c5130_edv:
- #include "tmc5130_dev.h"
-
-
- //MCU_SPIx spi1={
- // .SPIx = SPI1,
- // .MCU_SPI_ClockCmd = MCU_SPI1_ClockCmd,
- // .MCU_SPI_GPIOx = MCU_SPI1_GPIOx,
- // .MCU_SPI_CSN = MCU_SPI1_CSN_PIN,
- // .MCU_SPI_CLK = MCU_SPI1_CLK_PIN,
- // .MCU_SPI_MISO = MCU_SPI1_MISO_PIN,
- // .MCU_SPI_MISI = MCU_SPI1_MISI_PIN
- //};
- //配置电机引脚
- MCU_SPIx spi2={
- .SPIx = SPI2,
- .MCU_SPI_ClockCmd = MCU_SPI2_ClockCmd,
- .MCU_SPI_GPIOx = MCU_SPI2_GPIOx,
- .MCU_SPI_CSN = MCU_SPI2_CSN_PIN,
- .MCU_SPI_CLK = MCU_SPI2_CLK_PIN,
- .MCU_SPI_MISO = MCU_SPI2_MISO_PIN,
- .MCU_SPI_MISI = MCU_SPI2_MISI_PIN
- };
-
- //配置电机驱动使能引脚
- MCU_GPIO_t TMC5130_EN =
- {
- .cb.mode_set = OutPut_model,
- .cb.GPIOx_MCU_GPIO = GPIOA,
- .cb.MCU_GPIO_PIN = GPIO_Pin_11,
- .cb.GPIO_MODE = GPIO_Mode_Out_PP,
- //.prop_cb->GPIO_Init = MCU_GPIO_Init_t,
-
- };
- //配置电机驱动使能模式:输入or输出
- GPIO_PROP_cb_TypeDef TMC5130_EN_pro =
- {
- .GPIO_Init = MCU_GPIO_Init_t,
- .GPIO_OutputData = MCU_GPIO_OutputData
-
- };
-
- //配置电机驱动供电电源引脚号
- MCU_GPIO_t TMC5130_POWER =
- {
- .cb.mode_set = OutPut_model,
- .cb.GPIOx_MCU_GPIO = GPIOC,
- .cb.MCU_GPIO_PIN = GPIO_Pin_0,
- .cb.GPIO_MODE = GPIO_Mode_Out_PP,
- //.prop_cb->GPIO_Init = MCU_GPIO_Init_t,
-
- };
- //配置电机驱动供电电源使能模式:输入or输出
- GPIO_PROP_cb_TypeDef TMC5130_POWER_pro =
- {
- .GPIO_Init = MCU_GPIO_Init_t,
- .GPIO_OutputData = MCU_GPIO_OutputData
-
- };
-
-
- void TMC_SPI1_CS(uint8_t motor,uint8_t onoff)
- {
- if(onoff)
- {
- if(motor == 0)
- {
- // pTMC_CSN0 = 1;
- pTMC_CSN0(1);
- }
- else if(motor == 1)
- {
- // pTMC_CSN0 = 1;
- pTMC_CSN0(1);
- }
- }
- else
- {
- if(motor == 0)
- {
- // pTMC_CSN0 = 0;
- pTMC_CSN0(0);
- }
- else if(motor == 1)
- {
- // pTMC_CSN0 = 0;
- pTMC_CSN0(0);
- }
- }
- }
-
-
- uint8_t gTMC_SPI1_Status;
- //------------------------------------------------------
- //motor: 电机号片选
- //reg: 寄存器地址
- //返回值: 写入32位数值
- //------------------------------------------------------
- uint32_t TMC_SPI1_WriteInt(uint8_t motor, uint8_t reg, s32 dat)
- {
- uint8_t dat1,dat2,dat3,dat4;
-
- dat1 = dat;
- dat2 = dat>>8;
- dat3 = dat>>16;
- dat4 = dat>>24;
-
- TMC_SPI1_CS(motor,0);
- gTMC_SPI1_Status = spi_read_write(&spi2,reg|0x80);
- dat4 = spi_read_write(&spi2,dat4);
- dat3 = spi_read_write(&spi2,dat3);
- dat2 = spi_read_write(&spi2,dat2);
- dat1 = spi_read_write(&spi2,dat1);
-
- TMC_SPI1_CS(motor,1);
-
- dat = (dat4 << 24) + (dat3 << 16) + (dat2 << 8) + dat1;
- return dat;
- }
- //------------------------------------------------------
- //motor: 电机号片选
- //reg: 寄存器地址
- //返回值: 读32位数值
- //------------------------------------------------------
- uint32_t TMC_SPI1_ReadInt(uint8_t motor, uint8_t reg)
- {
- uint8_t dat1,dat2,dat3,dat4;
- uint8_t i;
-
- s32 dat=0;
-
- TMC_SPI1_CS(motor,0);
- spi_read_write(&spi2,reg);
- spi_read_write(&spi2,0X00);
- spi_read_write(&spi2,0X00);
- spi_read_write(&spi2,0X00);
- spi_read_write(&spi2,0X00);
- TMC_SPI1_CS(motor,1);
-
- for(i=0;i<5;i++)
- { }
-
- TMC_SPI1_CS(motor,0);
- gTMC_SPI1_Status = spi_read_write(&spi2,reg);
- dat4 = spi_read_write(&spi2,0X00);
- dat3 = spi_read_write(&spi2,0X00);
- dat2 = spi_read_write(&spi2,0X00);
- dat1 = spi_read_write(&spi2,0X00);
- TMC_SPI1_CS(motor,1);
-
- dat = (dat4 << 24) + (dat3 << 16) + (dat2 << 8) + dat1;
- return dat;
- }
-
- //配置控制TMC5130芯片的初始化
- void TMC5130_GPIO_Init(void)
- {
-
- MCU_SPI_Init(&spi2);
- TMC5130_EN_pro.GPIO_Init(&TMC5130_EN.cb);
- TMC5130_POWER_pro.GPIO_Init(&TMC5130_POWER.cb);
- //
- TMC5130_POWER_pro.GPIO_OutputData(&TMC5130_POWER.cb, 1);
- TMC5130_EN_pro.GPIO_OutputData(&TMC5130_EN.cb, 1); //TMC5130初始状态设置失能 0:开启 1:关闭
-
- }
-
- void TMC5130_EN_VolSetting(char vol)
- {
- // TMC5130_POWER_pro.GPIO_OutputData(&TMC5130_POWER.cb, vol);
- TMC5130_EN_pro.GPIO_OutputData(&TMC5130_EN.cb, vol);
- }
-
- #ifndef TMC5130_DEV_H_
- #define TMC5130_DEV_H_
- #include "mcu_spi.h"
- #include <stdio.h>
- #include <stdint.h>
- #include "mcu_gpio.h"
-
- #define spi1 0 //是不是spi1信号
-
- #if spi1
- #define pTMC_CSN0(vol) GPIO_WriteBit(MCU_SPI1_GPIOx, MCU_SPI1_CSN_PIN,(vol & (1<<0 )) ? Bit_SET : Bit_RESET);
- #else
- #define pTMC_CSN0(vol) GPIO_WriteBit(MCU_SPI2_GPIOx, MCU_SPI2_CSN_PIN,(vol & (1<<0 )) ? Bit_SET : Bit_RESET);
- #endif
-
- uint32_t TMC_SPI1_WriteInt(uint8_t motor, uint8_t reg, s32 dat);
- uint32_t TMC_SPI1_ReadInt(uint8_t motor, uint8_t reg);
- void TMC5130_GPIO_Init(void);
- void TMC5130_EN_VolSetting(char vol);
- #endif
/****************************************************************
*文件名:TMC5130_EVAL.c
*版本:v1.0
*作者:JOHN.FENG
*描述:步进电机TMC5130驱动程序
****************************************************************/
//#include "IncludeAll.h"
#include "mcu_spi.h"
#include "math.h"
#include "TMC5130_EVAL.h"
#include "delay.h"#define TMC5130_EVAL_GLOBALS
/***************************************
//计算配置TMC5130驱动芯片寄存器参数
*输入:转速rpm/分
*输出:VMAX寄存器值ppt
***************************************/
uint32_t TMC5130_speed_Vmax(uint16_t rpm)
{
uint32_t uSteps_s = 0; //微步速度μsteps/s
float VMAX = 0.0; //VMAX寄存器值ppt
uSteps_s = M0TOR_SETP * MICRO_STEP * ((float)rpm / 60);
VMAX = (uSteps_s * 2 * pow(2, 23) / TMC5130_CLK);
return (uint32_t)VMAX;
}void TMC5130_init(u8 motor)
{TMC5130_GPIO_Init();
delay_ms(500);
TMC_SPI1_WriteInt(motor, TMC5130_GSTAT, 0x00000007);
TMC_SPI1_WriteInt(motor, TMC5130_GCONF, 0x00000000); //启用了静态芯片电压PWM模式(取决于速度阈值)。“开关
TMC_SPI1_WriteInt(motor, TMC5130_CHOPCONF, 0x000100c3);
TMC5130_move_IHOLD_IRUN(9); //调节电流
TMC_SPI1_WriteInt(motor, TMC5130_PWMCONF, 0xC40C261E);
TMC_SPI1_WriteInt(motor, TMC5130_TPWMTHRS, 0); //Stealthchop 模式设定TMC_SPI1_WriteInt(motor, TMC5130_RAMPMODE, 2);
TMC_SPI1_WriteInt(motor, TMC5130_VMAX, 0);
}
/****************************************************
*函数名:TMC5130_move_run
*作者:john.feng
*输入:电机启动
*输出:无
*返回值:无
****************************************************/
void TMC5130_move_run(uint32_t speed)
{
uint8_t motor = 0;
TMC5130_EN_VolSetting(0); //开启TMC5130使能TMC_SPI1_WriteInt(motor, TMC5130_XTARGET, 0);
TMC_SPI1_WriteInt(motor, TMC5130_VSTART, 0); //加速开始速度
TMC_SPI1_WriteInt(motor, TMC5130_A1, 1000); //VSTART和V1之间的首次加速
TMC_SPI1_WriteInt(motor, TMC5130_V1, 0); //只用AMAX,DMAX
TMC_SPI1_WriteInt(motor, TMC5130_VMAX, speed);
TMC_SPI1_WriteInt(motor, TMC5130_DMAX, 1000); //TMC5130_VMAX 到 TMC5130_V1的减速
TMC_SPI1_WriteInt(motor, TMC5130_D1, 1000); //V1和VSTOP之间的减速
TMC_SPI1_WriteInt(motor, TMC5130_VSTOP, 10); //加速停止速度
TMC_SPI1_WriteInt(motor, TMC5130_TZEROWAIT, 100); //设置的静止后的延迟时间
TMC_SPI1_WriteInt(motor, TMC5130_AMAX, speed); //V1和VMAX之间的秒加速度TMC_SPI1_WriteInt(motor, TMC5130_VMAX, speed);
}
/****************************************************
*函数名:TMC5130_move_stop
*作者:john.feng
*输入:电机停止
*输出:无
*返回值:无
****************************************************/
void TMC5130_move_stop()
{
u8 motor = 0;
TMC_SPI1_WriteInt(motor, TMC5130_VMAX, 0); //减速到零
TMC5130_EN_VolSetting(1); //关闭TMC5130的使能}
/****************************************************
*函数名:TMC5130_move_dir
*作者:john.feng
*输入:电机状态,0:电机停止; 1:电机正转; 2:电机反转; 3:
*输出:无
*返回值:无
****************************************************/
void TMC5130_move_dir(TMC5130_MODE_STU status)
{
TMC_SPI1_WriteInt(0, TMC5130_RAMPMODE, status);
}
/****************************************************
*函数名:TMC5130_move_chopconf
*作者:john.feng
*输入:电机的细分数
*输出:无
*返回值:无
****************************************************/
//void TMC5130_move_chopconf()
//{
// TMC_SPI1_WriteInt(0,TMC5130_CHOPCONF, 0x000100c3);
//}
/****************************************************
*函数名:TMC5130_move_chopconf
*作者:john.feng
*输入:电机驱动电流调节 0-31
*输出:无
*返回值:无
****************************************************/
void TMC5130_move_IHOLD_IRUN(uint32_t curr_num)
{curr_num = (curr_num << 8) | 0x00070001;
TMC_SPI1_WriteInt(0, TMC5130_IHOLD_IRUN, curr_num);
}
/****************************************************************
*文件名:TMC5130_EVAL.h
*版本:v1.0
*作者:JOHN.FENG
*描述:步进电机TMC5130驱动程序
****************************************************************/
#ifndef TMC5130_EVAL_H_
#define TMC5130_EVAL_H_#include "tmc5130_dev.h"
#define MICRO_RPM 600 //电机转速(单位:一分钟多少圈)/*电机单圈参数*/
#define STEP_ANGLE 1.8 //步进电机的步距角 单位:度
#define FSPR (360.0f/1.8f) //步进电机的一圈所需脉冲数#define MICRO_STEP 256 //细分数
#define M0TOR_SETP 200 //电机步数#define TMC5130_CLK 16000000 //步进电机外部时钟
#define TMC5130_speed_reg(MICRO_RPM) (((M0TOR_SETP*MICRO_STEP) *2*pow(2,23)*(MICRO_RPM/60))/TMC5130_CLK) //对tmc5130驱动芯片寄存器的赋值参数
// ===== TMC5130 register set =====#define TMC5130_GCONF 0x00 //描述/位名
#define TMC5130_GSTAT 0x01 //全局状态标志
#define TMC5130_IFCNT 0x02 //接口传输计数器(用于串口)
#define TMC5130_SLAVECONF 0x03 //参数设置
#define TMC5130_INP_OUT 0x04 //输入,输出设置
#define TMC5130_X_COMPARE 0x05 //运动控制器位置的位置比较寄存器
#define TMC5130_IHOLD_IRUN 0x10 //驱动电流
#define TMC5130_TZEROWAIT 0x11 //设置电机静止(stst)后到电机电流断电的延迟时间
#define TMC5130_TSTEP 0x12 //两个1/256微步之间的实际测量时间
#define TMC5130_TPWMTHRS 0x13 //PWM模式的最高速度
#define TMC5130_TCOOLTHRS 0x14 //开启智能能源
#define TMC5130_THIGH 0x15 //设置允许速度依赖切换到不同的斩波模式和全步进,以最大限度地提高扭矩。#define TMC5130_RAMPMODE 0x20 //方向:1为正向,2为反向
#define TMC5130_XACTUAL 0x21 //目标位置寄存器
#define TMC5130_VACTUAL 0x22 //实际电机速度
#define TMC5130_VSTART 0x23 //电机启动速度
#define TMC5130_A1 0x24 //VSTART和V1之间的首次加速
#define TMC5130_V1 0x25 //第一加/减速相阈值速度
#define TMC5130_AMAX 0x26 //V1和VMAX之间的第二加速度
#define TMC5130_VMAX 0x27 //运动坡道目标速度
#define TMC5130_DMAX 0x28 //VMAX和V1之间的减速
#define TMC5130_D1 0x2A //V1和VSTOP之间的减速
#define TMC5130_VSTOP 0x2B //电机停止速度
#define TMC5130_TZEROCROSS 0x2C //定义减速到零速度后的等待时间
#define TMC5130_XTARGET 0x2D //目标位置为斜坡模式
#define TMC5130_VDCMIN 0x33 //速度VDCMIN
#define TMC5130_SWMODE 0x34 //交换模式配置
#define TMC5130_RAMPSTAT 0x35 //匝道状态和交换机事件状态
#define TMC5130_XLATCH 0x36 //斜坡发生器锁存位置
#define TMC5130_ENCMODE 0x38 //停止模式选择
#define TMC5130_XENC 0x39 //使用stallGuard2停止
#define TMC5130_ENC_CONST 0x3A //锁存编码器位置到ENC_LATCH参考开关事件
#define TMC5130_ENC_STATUS 0x3B //编码器的配置
#define TMC5130_ENC_LATCH 0x3C //实际编码器位置#define TMC5130_MSLUT0 0x60
#define TMC5130_MSLUT1 0x61
#define TMC5130_MSLUT2 0x62
#define TMC5130_MSLUT3 0x63
#define TMC5130_MSLUT4 0x64
#define TMC5130_MSLUT5 0x65
#define TMC5130_MSLUT6 0x66
#define TMC5130_MSLUT7 0x67
#define TMC5130_MSLUTSEL 0x68
#define TMC5130_MSLUTSTART 0x69
#define TMC5130_MSCNT 0x6A //微步计数器
#define TMC5130_MSCURACT 0x6B
#define TMC5130_CHOPCONF 0x6C //Chopper和driver配置,
#define TMC5130_COOLCONF 0x6D //coolStep智能电流控制寄存器和stallGuard2配置
#define TMC5130_DCCTRL 0x6E //自动换相配置寄存器
#define TMC5130_DRVSTATUS 0x6F //stallGuard2值和驱动程序错误标志
#define TMC5130_PWMCONF 0x70 //电压PWM模式斩波器配置
#define TMC5130_PWMSTATUS 0x71 //实际的PWM振幅标量
#define TMC5130_EN_CTRL 0x72 //编码器模式配置为特殊模式
#define TMC5130_LOST_STEPS 0x73//Rampenmodi (Register TMC5130_RAMPMODE)
//#define TMC5130_MODE_POSITION 0 //电机停止
//#define TMC5130_MODE_VELPOS 1 //电机正转
//#define TMC5130_MODE_VELNEG 2 //电机反转
//#define TMC5130_MODE_HOLD 3
//Endschaltermodusbits (Register TMC5130_SWMODE)
#define TMC5130_SW_STOPL_ENABLE 0x0001
#define TMC5130_SW_STOPR_ENABLE 0x0002
#define TMC5130_SW STOPL_POLARITY 0x0004
#define TMC5130_SW_STOPR_POLARITY 0x0008
#define TMC5130_SW_SWAP_LR 0x0010
#define TMC5130_SW_LATCH_L_ACT 0x0020
#define TMC5130_SW_LATCH_L_INACT 0x0040
#define TMC5130_SW_LATCH_R_ACT 0x0080
#define TMC5130_SW_LATCH_R_INACT 0x0100
#define TMC5130_SW_LATCH_ENC 0x0200
#define TMC5130_SW_SG_STOP 0x0400
#define TMC5130_SW_SOFTSTOP 0x0800
//Statusbitss (Register TMC5130_RAMPSTAT)
#define TMC5130_RS_STOPL 0x0001
#define TMC5130_RS_STOPR 0x0002
#define TMC5130_RS_LATCHL 0x0004
#define TMC5130_RS_LATCHR 0x0008
#define TMC5130_RS_EV_STOPL 0x0010
#define TMC5130_RS_EV_STOPR 0x0020
#define TMC5130_RS_EV_STOP_SG 0x0040
#define TMC5130_RS_EV_POSREACHED 0x0080
#define TMC5130_RS_VELREACHED 0x0100
#define TMC5130_RS_POSREACHED 0x0200
#define TMC5130_RS_VZERO 0x0400
#define TMC5130_RS_ZEROWAIT 0x0800
#define TMC5130_RS_SECONDMOVE 0x1000
#define TMC5130_RS_SG 0x2000typedef enum
{
TMC5130_MODE_POSITION = 0, //停止
TMC5130_MODE_VELPOS = 1, //正向
TMC5130_MODE_VELNEG = 2, //反向
TMC5130_MODE_HOLD = 3
}TMC5130_MODE_STU;uint32_t TMC5130_speed_Vmax(uint16_t rpm);
void TMC5130_init(uint8_t motor);
void TMC_Init(void);
void TMC5130_move_run(uint32_t speed);void TMC5130_move_stop(void);
void TMC5130_move_IHOLD_IRUN(uint32_t curr_num);
void TMC5130_move_dir(TMC5130_MODE_STU status);
//s32 TMC_SPI1_WriteInt(u8 motor, u8 reg, s32 dat);
//s32 TMC_SPI1_ReadInt(u8 motor, u8 reg);#endif
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。