This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] DRV8302-HC-C2-KIT:为 DRV8302-HC-C2-KIT 上的模拟脚油门选择正确的引脚连接时出现问题

Guru**** 1125150 points
Other Parts Discussed in Thread: DRV8301, DRV8302, DRV8312
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/674471/drv8302-hc-c2-kit-issue-with-selecting-the-correct-pin-connection-for-analog-foot-throttle-on-drv8302-hc-c2-kit

器件型号:DRV8302-HC-C2-KIT

您好!  

我将 DRV8302-HC-C2-KIT 用于高级设计项目。 我使用它来控制小型汽车的 BLDC 电机。 为了使用电路板上的电机、我还使用模拟脚油门。 我能够使用 code composer studio 将代码刷写到电路板上、使电机正常运行。 尽管我无法准确找到模拟信号脚油门所需的电路板引脚。 对这些类型的应用不是很熟悉、需要有关此问题的建议。   

我已附上我正在使用的代码。  

我的脚油门是三线连接-黑色(接地)红色(电源)绿色(速度信号)  输入信号:5V 输出:0.8-4.2V

感谢您的帮助、  

Blake Fredieu  

/*============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

系统名称:     与 GUI 配合使用的 DRV83xx EVM 集成闪存映像

 

文件名:    BLDC_Int_GUI_DRV83xx.c

 

说明:用于实现 BEMF 集成的主系统文件

                          GUI 控制

                          

发起人:        数字控制系统集团-德州仪器(TI)

====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

历史记录:

----------------------------------------------------

2011年8月 XX 日:Jon Warriner

==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================== *

 

//包含 main 函数中使用的头文件

#include "PeripheralHeaderIninclude.h"

#include "BLDC_Int_GUI_DRV83xx-Settings.h"

#include "IQmathLib.h"

#include "BLDC_Int_GUI_DRV83xx.h"

#include "Graph_Data.h"

#include "Commros_user.h"

 

#include

 

#define REFVOLTS 0.85

//此文件中找到的函数的原型语句。

中断 MainISR ();

void DeviceInit()

void Memcopy()

InitFlash()

void Gui_DBUFF_init ();

 

//状态机函数原型

///----------------------------

// Alpha 状态

void A0 (void);     //state A0

void B0 (void);     //state B0

void C0 (void);     //state C0

 

//分支状态

void A1 (void);     //state A1

void A2 (void);     //state A2

void A3 (void);     //state A3

 

// B 分支状态

void b1 (void);     //state b1

void B2 (void);     //state B2

void B3 (void);     //状态 B3

 

// C 分支状态

void C1 (void);     //state C1

void C2 (void);     //state C2

void C3 (void);     //state C3

 

//变量声明

void (* alpha_State_ptr)(void);  //基态指针

void (* a_Task_ptr)(void);       //状态指针 a 分支

void (* B_Task_ptr)(void);       //状态指针 B 分支

void (* C_Task_ptr)(void);       //状态指针 C 分支

 

//用于在闪存中运行后台,在 RAM 中运行 ISR

extern UINT16 * RamfuncsLoadStart、* RamfuncsLoadEnd、* RamfuncsRunStart;

 

//GUI 变量

//希望将它们放置在不会像那样移动的内存段中

//添加/删除非 GUI 变量。

#pragma DATA_SECTION (GUI、"GUIVARS");

结构 Gui_VARS GUI;

 

//此系统中使用的全局变量(但 GUI 不使用)

//定义电机参数

浮动 RS;         //定子电阻(欧姆)

浮动 RR;  //转子电阻(欧姆)

浮动 LS;  //定子电感(H)

浮动 LR;  //转子电感(H)  

浮动 LM;  //放大电感(H)

 

//定义 PU 系统转换的基本量

float base_voltage;//基峰相电压(伏特)

浮点 BASE_CURRENT;//基峰值相电流(安培)

float32 T;  //采样周期(秒)

 

_IQ BemfA = 0;

_IQ BemfB = 0;

_IQ BemfC = 0;

_IQ IDC_OFFSET =_IQ (0.5);

_iq IA_offset =_IQ (0.5);

_iq Iref=_IQ (0.0);                    // Id 参考(pu)

_IQ SpeedRef=_IQ (0.0);                //速度基准(pu)

_iq cal_filt_gain;

_iq spd_filt_gain;

_iq DfuncRun;

AdcRegs.ADCSOC7CTL.bit.CHSEL = 4;

AdcRegs.ADCSOC7CTL.bit.TRIGSEL = 5;

AdcRegs.ADCSOC7CTL.bit.ACQPS = 6;

uint32 VirtualTimer = 0;

uint32 IsrTicker = 0;

uint32 CmtnPeriodTarget;

uint32 CmtnPeriodSetpt;

 

int32 ram_start_rate;

int32 ram_end_rate;

 

uint16 calibration_flag = 1;

uint16 calibrate_time = 0x07FF;        //为校准滤波器提供大约100ms (~10tc)的稳定时间

UINT16 BackTicker = 0;

uint16 PreviousState;

UINT16 SpeedLoopFlag = false;

uint16 RunBLDC_Int=0;

uint16 isr_frequency = 20;        //定义 ISR 频率(kHz)

uint16 PWM_FREQUENCY = 20;        //定义 ISR 频率(kHz)

uint16 control_mode = 0;

 

Int16 VTimer0[4];               //虚拟定时器从 CPU 定时器0 (A 事件)中退出

Int16 VTimer1[4];       //虚拟定时器从 CPU 定时器1 (B 事件)中退出

Int16 VTimer2[4];       //虚拟定时器从 CPU 定时器2中退出(C 事件)

int16 K_VdcBus = 6632;

int16 i;                                                    //通用递增器

_IQ DlogCh1 = 0;

_IQ LogCh2 = 0;

_IQ DlogCh3 = 0;

int16 LedBlinkCnt=50;

Int16对数电流元件索引=0;

 

Int16 PwmDacCh1 = 0;

Int16 PwmDacCh2 = 0;

Int16 PwmDacCh3 = 0;

#IF 已定义(DRV8301)||已定义(DRV8302)

Int16 PwmDacCh4 = 0;

#endif

 

_iq *dlogptr1;

_iq *dlogptr2;

_iq *dlogptr3;

 

//实例 PID 稳压器以调节直流总线电流和速度

PID_GRANDO_controller pid1_IDC ={PID_TERM_DEFAULTS、PID_PARAM_DEFAULTS、PID_DATA_DEFAULTS};

PID_GRANDO_controller pid1_SPD ={PID_TERM_defaults,PID_PARAM_DEFAULTs,PID_DATA_DEFAULTs};

 

//实例 PWM 驱动程序实例

PWM_CNTL pwmcntl1 = PWM_CNTL_DEFAULTS;

 

//实例 PWM DAC 驱动程序实例

PWMDAC pwmdac1 = PWMDAC_DEFAULTS;

 

//实例一个斜坡控制器以平滑斜升频率

RMPCNTL RC1 = RMPCNTL_DEFAULTS;

 

//实例 RAMP3模块

rmp3 rmp3 = rmp3_defaults;

 

//实例 MOD6模块

MOD6CNTDIR MOD_DIR1 = MOD6CNTDIR_DEFAULTS;

 

//实例一个脉冲模块

IMPULSE INplim1 = PULIN_DEFAULTS;

 

//实例一个 InstaSPIN_BLDC 模块

INSTASPIN_BLDC InstaSPIN_BLDC1 = INSTASPIN_BLDC_DEFAULTS;

 

//实例 A speed_PR 模块

SPED_MEAS_CAP speed1 = SPED_MEAS_CAP_DEFAULTS;

 

//创建数据记录模块的实例

struct graph_data gData;

 

DRV8301

UNION DRV8301_STATUS_REG_1 DRV8301_STAT_reg1;

UNION DRV8301_STATUS_REG_2 DRV8301_STAT_reg2;

UNION DRV8301_CONTRAL_REG_1 DRV8301_CntrL_reg1;

UNION DRV8301_CONTRAL_REG_2 DRV8301_CntrL_reg2;

uint16 read_drv_status = 0;

#endif

 

uint32 BemfTrigCnt = 0;

uint32 BemfLastTrigCnt = 0;

uint16 GoodTrigCnt = 0;

UINT16 ClosedCommutFlag = 0;

UINT16 GoodTrigCntTrip = 20;

 

void main (void)

      

      DeviceInit();//器件寿命支持和 GPIO    

//仅在从闪存运行时使用

//请注意,变量 FLASH 由编译器定义

ifdef 闪存

//将时间关键代码和闪存设置代码复制到 RAM

// RamfuncsLoadStart、RamfuncsLoadEnd 和 RamfuncsRunStart

//符号由链接器创建。 请参阅链接器文件。

      Memcopy (&RamfuncsLoadStart、&RamfuncsLoadEnd、&RamfuncsRunStart);

 

//调用闪存初始化以设置闪存等待状态

//此函数必须驻留在 RAM 中

      InitFlash();//调用闪存包装程序初始化函数

#endif //(闪存)

 

//任务状态机初始化

      alpha_State_ptr =&A0;

      A_Task_ptr =&a1;

      B_Task_ptr =&b1;

//    C_Task_ptr =&c1;

 

//将 CPU 定时器2配置为每个 ISR 周期中断:

// 60MHz CPU 频率、ISR 周期(以 μ 秒为单位)

//此函数位于 DSP280x_CpuTimer.c 中

//jpw InitCpuTimer();

//jpw ConfigCpuTimer (&CpuTimer0、60、system_frequency * 10/ISR_FREQUENCY);

//jpw  StartCpuTimer0();

 

DRV8301

//初始化 SPI 以与 DRV8301通信

      DRV8301_SPI_Init (SpibRegs);

#endif

      

//后台循环的定时同步

//器件特定 PeripheralHeaderIncludes.h 中的定时器周期定义

//    CpuTimer0Regs.PRD.All = mSec1;        //

      CpuTimer1Regs.PRD.All = mSec1;        //任务

      CpuTimer2Regs.PRD.All = mSec5;        // B 任务

 

      Gui.Ref =_IQ (0.0);//f起初 为0.3                                                         //由 GUI 中的基准旋钮写入

      Gui.CurrentDisplay =_IQ (0.0);                                           //由 GUI 读取以显示电机电流

      GUI.DfuncStartup =_IQ (0.1);                                             //由 GUI 编写以设置启动占空比

定义#IF (DRV8312)

      Gui.CurrentStartup =_IQ (0.1);                                           //由 GUI 写入以设置启动占空比

#endif

#IF 已定义(DRV8301)||已定义(DRV8302)

      Gui.CurrentStartup =_IQ (0.02);                                          //由 GUI 写入以设置启动占空比

#endif

      Gui.Threshold =_IQ (2);  //f起初.4                                            //由 GUI 写入以设置集成阈值

定义#IF (DRV8312)

      Gui.Current_KP =_IQ (0.1);

#endif

#IF 已定义(DRV8301)||已定义(DRV8302)

      Gui.Current_KP =_IQ (1.0);

#endif

      Gui.Velocity Kp =_IQ (0.5);

      

      GUI.I_max =_IQ (0.95);

 

      GUI.RampUpTime = 25;

      Gui.CommErrorMax = 1.0;

      GUI.TripCnt = 3;

      GUI.AdvancedStartup = 0;

 

      GUI.SpeedRPM = 0;                                                               //由 GUI 读取以显示 RPM 为单位的电机转速

      GUI.Begin_start_RPM = 50;                                                //由 GUI 写入以设置斜升控制器的启动速度

      GUI.end_start_RPM = 100;                                                 //由 GUI 写入以设置斜升控制器的结束速度

 

      GUI.Current_MODE = 0;

      GUI.Veloce_mode = 0;

      GUI.ResetFault = 0;

      Gui.p支 架= 48;  //最初极数为8

      Gui.Current_Ki = 20;

      GUI.Velocity Ki = 3;

      GUI.Prescaler = 1;

 

      GUI.overval=0;

      GUI.DRVFaultFlag=0;

      GUI.DRVOTWFlag = 0;

      Gui.EnableFlag = true;//最初为 false

      GUI.VdcBus = 0;

定义#IF (DRV8312)

      GUI.Max_VDC = 2880;

      GUI.min_VDC = 1920;

#endif

#IF 已定义(DRV8301)||已定义(DRV8302)

      GUI.Max_VDC = 6000;

      GUI.min_VDC = 800;

#endif

 

//重新分配 ISR。

      EALLOW;     //这是写入 EALLOW 受保护寄存器所必需的

      PieVectTable.ADCINT1 = MainISR;

      EDIS;  //这是禁止写入 EALLOW 受保护寄存器所必需的

 

//为 ADCINT1启用 PIE 组1中断1

  PieCtrlRegs.PIEIER1.ALL = M_INT1;

 

      InitCommros ();

      

      //定义 PU 系统转换的基本量

      base_voltage = 66.32;           //基峰值相电压(伏特)、最大可测量直流总线

定义#IF (DRV8312)

      base_current = 8.6;             //基峰值相电流(安培)

#endif

#IF 已定义(DRV8301)||已定义(DRV8302)

base_current 的//选项、基于 DRV830x 电流感应放大器增益设置

//注意:DRV8302只能设置为增益10或40

      base_current = 82.5;            //基峰值相电流(安培),最大可测量峰值电流(DRV830x 增益设置为10)

//    base_current = 41.25;           //基峰值相电流(安培),最大可测量峰值电流(DRV830x 增益设置为20)

//    base_current = 20.625;          //基峰相电流(安培),最大可测量峰值电流(DRV830x 增益设置为40)

//    base_current = 10.3125;         //基峰值相电流(安培),最大可测量峰值电流(DRV830x 增益设置为80)

#endif

      GUI.base_FREQ = 200;                  //基本电气频率(Hz)

 

      //定义 ISR 频率(kHz)

      ISR_FREQUENCY = 20;

      PWM_FREQUENCY = ISR_FREQUENCY;

      t = 0.001/ISR_FREQUENCY;  //采样周期(秒)、请参阅 parameter.h

                          

//初始化 PWM 控制模块

      pwmcntl1.PWMprd = system_frequency *1000000*T/2;                         //为此示例设置 PWM 周期

  PWM_CNTL_init_macro (pwmcntl1)

  PWM_CNTL_MACRO (pwmcntl1)

 

//初始化 PWMDAC 模块

      pwmdac1.PeriodMax = 500;  // 3000->10kHz、1500->20kHz、1000->30kHz、500->60kHz

  pwmdac1.pwmDacInPointer0 =&PwmDacCh1;

  pwmdac1.pwmDacInPointer1 =&PwmDacCh2;

  pwmdac1.pwmDacInPointer2 =&PwmDacCh3;

#IF 已定义(DRV8301)||已定义(DRV8302)

  pwmdac1.pwmDacInPointer3 =&PwmDacCh4;

#endif

      PWMDAC_init_macro (pwmdac1)

 

      RAMP_START_RATE =(PWM_FREQUENCY * 1000)* 60.0/GUI.Begin_START_RPM/COMMUTATES_PER_E_REV/(GUI.RART/2.0);

      RAMP_END_RATE =(PWM_FREQUENCY * 1000)* 60.0/GUI.END_START_RPM/COMMUTATES_PER_E_REV/(GUI.RART/2.0);

      CmtnPeriodTarget = RAMP_END_RATE;

      CmtnPeriodSetpt = RAMP_START_RATE;

 

//初始化数据记录模块

  gdata.ch1_ptr = DlogCh1;

  gdata.ch2_ptr = DlogCh2;

  gdata.ch3_ptr = DlogCh3;

  gData.trig_value = 1;

  gData.size = 0x100;

  gData.prescalar = GUI.Prescaler;

  gData.holdoff = 10000;

  graph_Data_Init (&gData);

      dlogptr1=DLOG_4ch_buff1;

      dlogptr2=DLOG_4ch_buff2;

      dlogptr3=DLOG_4ch_buff3;

 

//初始化 ADC 模块(F2803XIDC_VEMF.H)

      adc_macro_init ()

 

//初始化 SPED_PR 模块

     speed1.InputSelect = 0;

     speed1.BaseRpm = 120*(gui.base_FREQ/GUI.p杆);

     speed1.SpeedScal=(uint32)(ISR_FREESD/(1*(float32) GUI.base_FREQ*0.001);

 

//初始化 RMPCNTL 模块

  RC1.RampDelayMax = 1;

  RC1.RampLowLimit=_IQ (-1.0);

  RC1.RampHighLimit=_IQ (1.0);

 

//初始化 RMP3模块

      rmp3.DesiredInput = CmtnPeriodTarget;

      rmp3.Ramp3Delay =(uint32)(((float32) GUI.RampUpTime * 0.001)/((float32)(CmtnPeriodSetpt - CmtnPeriodTarget)* T));

  rmp3.out = CmtnPeriodSetpt;

  rmp3.Ramp3Min = CmtnPeriodTarget;

 

//初始化 INSTASPIN_BLDC 模块

      InstaSPIN_BLDC1.VaOffset = 0;

      InstaSPIN_BLDC1.VbOffset = 0;

      InstaSPIN_BLDC1.VcOffset = 0;

      InstaSPIN_BLDC1.Int_Threshold = GUI.Threshold;

 

//初始化 PID_GRANDO_controller 模块以获得直流总线电流

  pid1_IDC.param.kp = GUI.Current_Kp;

  pid1_idc.param.kr =_IQ (1.0);

      pid1_IDC.param.ki =_IQ (T *(float32) GUI.Current_Ki);

      pid1_idc.param.kd =_IQ (0/T);

  pid1_idc.param.km =_IQ (1.0);

  pid1_idc.param.Umax =_IQ (0.95);

  pid1_idc.param.umin =_IQ (-0.95);

 

//初始化速度的 PID_GRANDO_controller 模块

  pid1_spd.param.kp = GUI.Velocity Kp;

  pid1_spd.param.kr =_IQ (1.0);

      pid1_spd.param.ki =_IQ (T *(float32) GUI.Velocity Ki);

      pid1_spd.param.kd =_IQ (0/T);

  pid1_spd.param.km =_IQ (1.0);

  pid1_spd.param.Umax = GUI.I_max;

  pid1_spd.param.umin =-gui.i_max;

  

//初始化电流偏移校准滤波器

      CAL_filt_GAIN =_IQ (T/(T+TC_CAL));

 

//初始化电流偏移校准滤波器

      SPD_filt_GAIN =_IQ (T/(T+TC_SPD));

 

//为 ADCINT1启用 CPU INT1:

      IER |= M_INT1;

 

//启用全局中断和更高优先级的实时调试事件:

      EINT;  //启用全局中断 INTM

      ERTM; //启用全局实时中断 DBGM

 

//空闲循环。 只需坐下来循环:      

      for (;;)//infinite loop

      {

             //状态机入口和出口点

             //========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

             (* alpha_State_ptr)();    //跳转至 Alpha 状态(A0、B0、...)

             //========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

             ServiceRoutine (&commros);

             

             //尝试检测并重置任何 SCI 错误

             //具体地从中断检测中恢复

             插入 USB 电缆时的//结果。

             //FTDI 芯片会在其上产生一些长脉冲

             加电时为//Tx 引脚。 如果 C2000在何时运行

             //这种情况会触发 SCI 中断检测。

             if (SciaRegs.SCIRXST.bit.RXERROR)

             {

                    GpioDataRegs.GPACLEAR.bit.GPIO31 = 1;

                    SciaRegs.SCICTL1.bit.SWRESET = 0;

                    SciaRegs.SCICTL1.bit.SWRESET = 1;

             }

             其他

             {

                    GpioDataRegs.GPASET.bit.GPIO31 = 1;

             }

 

             //通过 GUI 更新电流和速度环路 PI 增益

    pid1_IDC.param.kp = GUI.Current_Kp;

             pid1_IDC.param.ki =_IQ (T *(float32) GUI.Current_Ki);

    pid1_spd.param.kp = GUI.Velocity Kp;

             pid1_spd.param.ki =_IQ (T *(float32) GUI.Velocity Ki);

 

             gData.prescalar = GUI.Prescaler;

             GoodTrigCntTrip =(UINT16)(((Gui.CommErrorMax / T)* 0.001)+ 0.5);

             

DRV8301

             //从 DRV8301读取状态寄存器

             if (read_drv_status)

             {

                    DRV8301_STAT_reg1.all = DRV8301_SPI_Read (SpibRegs、STAT_REG_1_ADDR);

                    DRV8301_STAT_reg2.all = DRV8301_SPI_Read (SpibRegs、STAT_REG_2_ADDR);

                    READ_DRV_STATUS = 0;

             }

#endif       

      }

}//结束主代码

 

 

 

//============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

//    状态机定序和同步,用于缓慢的后台任务

//============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

 

///---------------------- 框架------------------------------------

A0 ()

      // A 任务的循环速率同步器

      if (CpuTimer1Regs.tcr.bit.TIF = 1)

      {

             CpuTimer1Regs.TCR.bit.TIF = 1;  //清除标志

 

             //----------------------------------------------

             (*a_Task_ptr)();          //跳转至任务(A1、A2、A3、...)

             //----------------------------------------------

 

             VTimer0[0]++;             //虚拟计时器0,实例0 (备用)

      }

 

      alpha_State_ptr =&B0;          //注释出以仅允许任务

 

B0 ()

      //针对 B 任务的环路速率同步器

      if (CpuTimer2Regs.tcr.bit.TIF = 1)

      {

             CpuTimer2Regs.TCR.bit.TIF = 1;                      //清除标志

 

             //----------------------------------------------

             (* B_Task_ptr)();          //跳转至 B 任务(B1、B2、B3、...)

             //----------------------------------------------

             VTimer1[0]++;             //虚拟计时器1,实例0 (备用)

      }

 

      alpha_State_ptr =&A0;          //允许 C 状态任务

 

//============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

//    A -任务(每1毫秒执行一次)

//============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

//----------------------------------------

void A1 (void)//用于为逆变器启用禁用 PWM

//----------------------------------------

      if (GUI.EnableFlag=false)

      {

             RunBLDC_Int=0;

 

             //关闭所有 PWM

定义#IF (DRV8312)

             PHASE_A_OFF;

             PHASE_B_OFF;

             PHASE_C_OFF;

#endif

#IF 已定义(DRV8301)||已定义(DRV8302)

             //deassert DRV830x EN_GATE 引脚

             GpioDataRegs.GPBCLEAR.bit.GPIO39 = 1;

#endif

             EPwm1Regs.CMPA.Halt.CMPA=0;     // PWM 1A - PhaseA

             EPwm2Regs.CMPA.Halt.CMPA=0;     // PWM 2A - PhaseB

             EPwm3Regs.CMPA.Halt.CMPA=0;     // PWM 3A -相量

 

             if (GUI.ResetFault = 1)

             {

定义#IF (DRV8312)

                    //复位 DRV 芯片

                    GpioDataRegs.GPACLEAR.bit.GPIO1=1;

                    GpioDataRegs.GPACLEAR.bit.GPIO3=1;

                    GpioDataRegs.GPACLEAR.bit.GPIO5=1;

#endif

#IF 已定义(DRV8301)||已定义(DRV8302)

                    //deassert DRV830x EN_GATE 引脚

                   GpioDataRegs.GPBCLEAR.bit.GPIO39 = 1;

#endif

                 GUI.ResetFault = 2;

             }

             否则、如果(Gui.ResetFault = 2)

             {

                 //重置跳闸区域

                 EALLOW;

                    EPwm1Regs.TZCLR.bit.OST=1;

                    EPwm2Regs.TZCLR.bit.OST=1;

                    EPwm3Regs.TZCLR.bit.OST=1;

                    EDIS;

                 

                   GUI.ResetFault = 0;

                    GUI.DRVFaultFlag = 0;

             }

             

             //禁用时将所有显示的变量置零

             GUI.SpeedRPM = 0;

             speed1.SpeedRpm = 0;

             speed1.Speed = 0;

             Gui.CurrentDisplay = 0;

             CALIBRATE_FLAG = 1;

             InstaSPIN_BLDC1.VaOffset = 0;

             InstaSPIN_BLDC1.VbOffset = 0;

             InstaSPIN_BLDC1.VcOffset = 0;

             IDC_OFFSET =_IQ (0.5);

             SpeedLoopFlag=false;

 

             

      }      

      //如果未定义电机类型

      if ((GUI.EnableFlag = true)&&(RunBLDC_Int = false)

      {

             //仅当您启用了电机时读取 Gui_SpeedRef

             SpeedRef = GUI.Ref;

 

             if ((RunBLDC_Int =0)&&(GUI.DRVFaultFlag =0))

             {

#IF 已定义(DRV8301)||已定义(DRV8302)

                    //将 DRV830x EN_GATE 引脚置为有效

                    GpioDataRegs.GPBSET.BIO39 = 1;

 

                    DELAY_US (50000);          //延迟以允许 DRV830x 电源斜升

                    

DRV8301

                    DRV8301_Cntrl_reg1.bit.gate_current = 0;            //最大电流1.7A

//                 DRV8301_Cntrl_reg1.bit.gate_current = 1;            // med current 0.7A

//                 DRV8301_Cntrl_reg1.bit.gate_current = 2;            //最小电流0.25A

                    DRV8301_Cntrl_reg1.bit.gate_reset = 0;              //正常模式

                    DRV8301_CntrL_reg1.bit.PWM_MODE = 0;                //六个独立 PWM

//                 DRV8301_Cntrl_reg1.bit.OC_MODE = 0;                        //检测到 OC 时的电流限制

                    DRV8301_CntrL_reg1.bit.OC_MODE = 1;                        //已锁存 OC 关断

//                 DRV8301_Cntrl_reg1.bit.OC_MODE = 2;                        //仅报告 OCTWn 引脚和 SPI 寄存器、无关断

//                 DRV8301_Cntrl_reg1.bit.OC_MODE = 3;                        // OC 保护被禁用

//                 DRV8301_Cntrl_reg1.bit.OC_ADJ_SET = 0;              // OC @ VDS=0.060V

//                 DRV8301_Cntrl_reg1.bit.OC_ADJ_SET = 4;              // OC @ VDS=0.097V

//                 DRV8301_Cntrl_reg1.bit.OC_ADJ_SET = 6;              // OC @ VDS=0.123V

//                 DRV8301_Cntrl_reg1.bit.OC_ADJ_SET = 9;              // OC @ VDS=0.175V

                    DRV8301_CntrL_reg1.bit.OC_ADJ_SET = 15;             // OC @ VDS=0.358V

//                 DRV8301_Cntrl_reg1.bit.OC_ADJ_SET = 16;             // OC @ VDS=0.403V

//                 DRV8301_Cntrl_reg1.bit.OC_ADJ_SET = 17;             // OC @ VDS=0.454V

//                 DRV8301_Cntrl_reg1.bit.OC_ADJ_SET = 18;             // OC @ VDS=0.511V

                    DRV8301_CntrL_reg1.bit.Reserved = 0;

                    

//                 DRV8301_Cntrl_reg2.bit.OCTW_SET = 0;                //报告 OT 和 OC

                    DRV8301_Cntrl_reg2.bit.OCTW_SET = 1;                //仅报告 OT

                    DRV8301_CntrL_reg2.bit.gain = 0;                    // CS 放大器增益= 10

//                 DRV8301_Cntrl_reg2.bit.gain = 1;                    // CS 放大器增益= 20

//                 DRV8301_Cntrl_reg2.bit.gain = 2;                    // CS 放大器增益= 40

//                 DRV8301_Cntrl_reg2.bit.gain = 3;                    // CS 放大器增益= 80

                    DRV8301_Cntrl_reg2.bit.DC_CAL_CH1 = 0;              //未处于 CS 校准模式

                    DRV8301_Cntrl_reg2.bit.DC_CAL_CH2 = 0;              //未处于 CS 校准模式

                    DRV8301_CntrL_reg2.bit.OC_toff = 0;                        //正常模式

                    DRV8301_CntrL_reg2.bit.Reserved = 0;

                    

                    //写入 DRV8301控制寄存器1、返回状态寄存器1

                    DRV8301_STAT_reg1.all = DRV8301_SPI_Write (&SpibRegs、CNTRL_REG_1_ADDR、DRV8301_CntrL_reg1.all);

                    //写入 DRV8301控制寄存器2、返回状态寄存器1

                    DRV8301_STAT_reg1.all = DRV8301_SPI_Write (&SpibRegs、CNTRL_REG_2_ADDR、DRV8301_CntrL_reg2.all);

 

#endif

#endif

                    //定义 PU 系统转换的基本量

                    base_voltage = 66.32;           //基峰值相电压(伏特)、最大可测量直流总线

定义#IF (DRV8312)

                    base_current = 8.6;             //基峰值相电流(安培)

#endif

#IF 已定义(DRV8301)||已定义(DRV8302)

base_current 的//选项、基于 DRV830x 电流感应放大器增益设置

//注意:DRV8302只能设置为增益10或40

                    base_current = 82.5;            //基峰值相电流(安培),最大可测量峰值电流(DRV830x 增益设置为10)

//                 base_current = 41.25;           //基峰值相电流(安培),最大可测量峰值电流(DRV830x 增益设置为20)

//                 base_current = 20.625;          //基峰相电流(安培),最大可测量峰值电流(DRV830x 增益设置为40)

//                 base_current = 10.3125;         //基峰值相电流(安培),最大可测量峰值电流(DRV830x 增益设置为80)

#endif

 

                    //定义 ISR 频率(kHz)

                    ISR_FREQUENCY = 20;

                    t = 0.001/ISR_FREQUENCY;  //采样周期(秒)、请参阅 parameter.h

 

                   speed1.InputSelect = 0;

                   speed1.BaseRpm = 120*(gui.base_FREQ/GUI.p杆);

                   speed1.SpeedScal=(uint32)(ISR_FREESD/(1*(float32) GUI.base_FREQ*0.001);

                    speed1.InputSelect = 0;

                    speed1.NewTimeStamp = 0;

                    speed1.OldTimeStamp = 0;

                    speed1.EventPeriod = 0;

                    speed1.Speed = 0;

                    VirtualTimer = 0;

             

                    RC1.EqualFlag = 0;

                    RC1.RampDelayCount = 0;

                    RC1.targetValue = 0;

                                 

                    //斜坡结束时的速度应始终大于斜坡开始时的速度

                    //如果 GUI 条目违反此用法

                    //BEGIN_START_RPM = 50

                    //Begin_end_RPM = 100

                    if (gui.end_start_RPM > gui.begin_start_RPM)

                    {

                          RAMP_START_RATE =(PWM_FREQUENCY * 1000)* 60.0/GUI.Begin_START_RPM/COMMUTATES_PER_E_REV/(GUI.RART/2.0);

                          RAMP_END_RATE =(PWM_FREQUENCY * 1000)* 60.0/GUI.END_START_RPM/COMMUTATES_PER_E_REV/(GUI.RART/2.0);

                    }

                    其他

                    {

                          RAMP_START_RATE =(PWM_FREQUENCY * 1000)* 60.0/50/COMMUTATES_PER_E_REV/(GUI.RART/2.0);

                          RAMP_END_RATE =(PWM_FREQUENCY * 1000)* 60.0/100/COMMUTATES_PER_E_REV/(GUI.RART/2.0);

                    }

                    

                    CmtnPeriodTarget = RAMP_END_RATE;

                    CmtnPeriodSetpt = RAMP_START_RATE;

                    rmp3.Ramp3Delay =(uint32)(((float32) GUI.RampUpTime * 0.001)/((float32)(CmtnPeriodSetpt - CmtnPeriodTarget)* T));

                    rmp3.DesiredInput = CmtnPeriodTarget;

           rmp3.out = CmtnPeriodSetpt;

                    rmp3.Ramp3Min = CmtnPeriodTarget;

                    rmp3.Ramp3DelayCount = 0;

                    rmp3.Ramp3DoneFlag = 0;

 

                    impl1.Counter = 0;

                    impl1.out = 0;

             

                    mod_dir1.Counter = 0;

             

                    SpeedLoopFlag = false;

             

                    pid1_IDC.data.d1 = 0;

                    pid1_IDC.data.d2 = 0;

                    pid1_idc.data.i1 = 0;

                    pid1_idc.data.ud = 0;

                    pid1_IDC.data.ui = 0;

                    pid1_IDC.data.up = 0;

                    pid1_IDC.data.v1 = 0;

                    pid1_IDC.data.w1 = 0;

                    pid1_IDC.term.out = 0;

 

                    pid1_spd.data.d1 = 0;

                    pid1_spd.data.d2 = 0;

                    pid1_spd.data.i1 = 0;

                    pid1_spd.data.ud = 0;

                    pid1_spd.data.ui = 0;

                    pid1_spd.data.up = 0;

                    pid1_spd.data.v1 = 0;

                    pid1_spd.data.w1 = 0;

                    pid1_spd.term.out = 0;

           pid1_spd.param.Umax = GUI.I_max;

           pid1_spd.param.umin =-gui.i_max;

 

                    DfuncRun = GUI.DfuncStartup;

                    BemfTrigCnt = 0;

                    BemfLastTrigCnt = 0;

                    GoodTrigCnt = 0;

                    ClosedCommutFlag = 0;

                    InstaSPIN_BLDC1.V_int = 0;

                    

                    //根据 GUI 中的复选框设置设置 control_mode

                   ///voltage          0                   //开环电压模式

                    //电流          1//                   闭环电流控制

                    //velocity         2//                   闭环速度控制

                    //cascade3                             //级 联闭环速度->电流控制

                    //速度环路复选框写入0 (禁用)或2 (启用)

                    //当前循环复选框写入0 (禁用)或1 (启用)

                    control_mode = GUI.Velocity_mode + GUI.Current_mode;

                    

                    RunBLDC_Int=1;

 

                    EALLOW;

                          EPwm1Regs.TZCLR.bit.OST=1;

                          EPwm2Regs.TZCLR.bit.OST=1;

                          EPwm3Regs.TZCLR.bit.OST=1;

                    EDIS;

             }

      }

      

      //--------

      //下次 CpuTimer0 'counter'达到周期值时转到 A2

      A_Task_ptr =&A2;

      //--------

 

//----------------------------------------------------

void A2 (void)//备件(未使用)

//----------------------------------------------------

{      

      //--------

      // CpuTimer0 'counter'下一次达到周期值时转到 A3

      A_Task_ptr =&a1;

      //--------

 

///--------------------------------

void A3 (void)//备件(未使用)

///--------------------------------

 

      //------

      //下次 CpuTimer0 'counter'达到周期值时,转到 A1

      A_Task_ptr =&a1;

      //------

 

//============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

//    B -任务(每5毫秒执行一次)

//============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

 

///---------------------------- 用户-------------------------------------------------------

 

///--------------------------------

void B1 (void)//切换 GPIO-34

///--------------------------------

      if (RunBLDC_Int=1)

      {             

             if (LedBlinkCnt=0)

             {

                    GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;//打开/关闭 controlCARD 上的 LD3

                    LedBlinkCnt=50;

             }

             其他

                    LedBlinkCnt--;

      }

      其他

      {

             if (LedBlinkCnt=0)

             {

                    GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;//打开/关闭 controlCARD 上的 LD3

                    LedBlinkCnt=100;

             }

             其他

                    LedBlinkCnt--;

      }

      

      GUI.VdcBus =((long) AdcResult.ADCRESULT6 *() K_VdcBus )>>12;

 

      if (GUI.VdcBus < GUI.min_VDC)

      {

             GUI.overval= 0;

      }

      否则、如果(GUI.VdcBus > GUI.Max_VDC)

      {

             GUI.overval= 2;

      }

      其他

      {

             GUI.overval= 1;

      }

      

      if (GUI.overvage!= 1)

      {

             EPwm1Regs.TZFRC.bit.OST = 1;

             EPwm2Regs.TZFRC.bit.OST = 1;            

             EPwm3Regs.TZFRC.bit.OST = 1;            

      }

      

      //禁用 FAULTn 时忽略 FAULTn

      //当 DRV8301使能失效时,该引脚上会出现一个尖头

      if (((GpioDataRegs.GPADD.bit.GPIO14 = 0)&& RunBLDC_Int)

      {

             GUI.DRVFaultFlag=1;

      }

 

      if (GpioDataRegs.GPADAT.bit.GPIO13 ==1)

      {

             GUI.DRVOTWFlag = 0;

      }

      其他

      {

             GUI.DRVOTWFlag = 1;

      }

      //------

      //下次 CpuTimer1 'counter'达到周期值时,转到 B2

      B_Task_ptr =&b2;   

      //------

 

///--------------------------------

void b2 (void)//备件

///--------------------------------

      

      //------

      //下次 CpuTimer1 'counter'达到周期值时转到 B3

      B_Task_ptr =&b1;

      //------

 

///--------------------------------

void B3 (void)//备件

///--------------------------------

 

      //------

      // CpuTimer1的下一次计数器到达周期值时转到 B1

      B_Task_ptr =&b1;   

      //------

 

// MainISR

中断 MainISR ()

      _iq idcfdbk;

      _iq iqVaIn;

      _iq iqVbIn;

      _iq iqVcIn;

      _iq iqiia;

      油门上浮动 ADCValue;//ADC 信号值

      浮点 NORM/convert speed 介于0和.89之间

 

      GpioDataRegs.GPASET.bit.GPIO22 = 1;

      

//验证 ISR

  IsrTicker++;

 

if (RunBLDC_Int=0)

  Gui_DBUF_init ();      

// PMSM 电机

if <Gui.Max_VDC) (RunBLDC_Int=1 && GUI.VdcBus>GUI.min && GUI.VdcvdcVDC

      if (calibrate_flag)

      {

//----------------------------------

//  ADC 转换和偏移调整

//----------------------------------

             iqVaIn =_IQ15toIQ ((AdcResult.ADCRESULT1<<3))-InstaSPIN_BLDC1.VaOffset;

             iqVbIn =_IQ15toIq ((AdcResult.ADCRESULT2<3)-InstaSPIN_BLDC1.VbOffset;

             iqVcIn =_IQ15toIq ((AdcResult.ADCRESULT3<3)-InstaSPIN_BLDC1.VcOffset;

    iqIA=(_IQ15toIQ (AdcResult.ADCRESULT4<<3)-IA_OFFSET)<<1;

    IDCfdbk=(_IQ15toIq (AdcResult.ADCRESULT5<<3)-IDC_OFFSET)<<1;

//----------------------------------

// LPF 对校准偏移求平均值

//使用此处计算的偏移来初始化 BemfA_offset、BemfB_offset

//和 BemfC_offset、以便它们用于剩余的构建级别

//----------------------------------

    InstaSPIN_BLDC1.VaOffset =_IQmpy (cal_filt_gain、iqVaIn)+ InstaSPIN_BLDC1.VaOffset;

    InstaSPIN_BLDC1.VbOffset =_IQmpy (cal_filt_gain、iqVbIn)+ InstaSPIN_BLDC1.VbOffset;

    InstaSPIN_BLDC1.VcOffset =_IQmpy (cal_filt_gain、iqVcIn)+ InstaSPIN_BLDC1.VcOffset;

    IA_OFFSET =_IQmpy (cal_filt_gain、iqIA)+ IA_OFFSET;

    IDC_OFFSET =_IQmpy (cal_filt_gain、IDCfdbk)+ IDC_OFFSET;

 

//----------------------------------

//强制所有 PWM 占空比为0%

//----------------------------------

             PHASE_A_ON;

             PHASE_B_ON;

             PHASE_C_ON;

 

             EPwm1Regs.CMPA.Halt.CMPA=0;     // PWM 1A - PhaseA

             EPwm2Regs.CMPA.Halt.CMPA=0;     // PWM 2A - PhaseB

             EPwm3Regs.CMPA.Halt.CMPA=0;     // PWM 3A -相量

     

            calibrate_flag++;

            calibrate_flag &= calibrate_time;

      }

      其他

      {

//----------------------------------

//  ADC 转换和偏移调整

//----------------------------------

      iqVaIn =_IQ15toIq ((AdcResult.ADCRESULT1<<3));

      iqVbIn =_IQ15toIq ((AdcResult.ADCRESULT2<3));

      iqVcIn =_IQ15toIq ((AdcResult.ADCRESULT3<3));

     iqIA=(_IQ15toIQ (AdcResult.ADCRESULT4<<3)-IA_OFFSET)<<1;

定义#IF (DRV8312)

  IDCfdbk=(_IQ15toIq (AdcResult.ADCRESULT5<<3)-IDC_OFFSET)<<1;

#endif   

#IF 已定义(DRV8301)||已定义(DRV8302)

  IDCfdbk=-((_IQ15toIQ (AdcResult.ADCRESULT5<<3)-IDC_OFFSET)<<1);

#endif

 

//----------------------------------

//  连接 MOD6模块的输入并调用 Modulo 6计数器宏。

//----------------------------------   

      if (gui.Ref >_IQ (0.0))

      {

             mod_dir1.CntDirection =_IQ (1.0);

      }

      其他

      {

             mod_dir1.CntDirection =_IQ (-1.0);

      }

      PreviousState = mod_dir1.Counter;

      MOD6CNTDIR_MACRO (mod_dir1)

 

//----------------------------------

//  连接 SPED_PR 模块的输入并调用速度计算宏。

//----------------------------------

      //在递增计数时,我们需要正速度

      if (((mod_dir1.Counter=5)&&(PreviousState==4)&&(mod_dir1.TrigInput))

      {

             speed1.timestamp =虚拟计时器;

             SPED_PR_MACRO (speed1);

             SpeedLoopFlag = true;

      }

      //在递减计数时,我们需要负速度

      否则、如果(((mod_dir1.Counter=0)&&(PreviousState=1)&&(mod_dir1.TrigInput))

      {

             speed1.timestamp =虚拟计时器;

             SPED_PR_MACRO (speed1);

             speed1.Speed =_IQmpy (speed1.Speed、_IQ (-1.0));

             speed1.SpeedRpm =_IQmpy (speed1.SpeedRpm、_IQ (-1.0));

             SpeedLoopFlag = true;

      }

 

//----------------------------------

//  连接 INSTASPIN_BLDC 模块的输入并调用 INSTASPIN_BLDC 函数。

//----------------------------------

      InstaSPIN_BLDC1.Vag = iqVaIn - InstaSPIN_BLDC1.VaOffset;         //调整 VA_IN 的偏移

      InstaSPIN_BLDC1.VBG = iqVbIn - InstaSPIN_BLDC1.VbOffset;         //调整 Vb_IN 的偏移

      InstaSPIN_BLDC1.VCG = iqVcIn - InstaSPIN_BLDC1.VcOffset;         //调整 VC_IN 的偏移

      InstaSPIN_BLDC1.State = mod_dir1.Counter;                                      //更新状态

      InstaSPIN_BLDC (&InstaSPIN_BLDC1);

      mod_dir1.TrigInput = InstaSPIN_BLDC1.Comm_Trig;

      

      if ((ClosedCommutationFlag = 0)||(SpeedLoopFlag = false))

      {

             //----------------------------------

             //  连接 RMP3模块的输入并调用 Ramp control 3宏。

             //----------------------------------

//           rmp3.DesiredInput = CmtnPeriodTarget;

             rc3_macro (rmp3)     

 

             //----------------------------------

             //  连接脉冲模块的输入并调用脉冲宏。

             //----------------------------------     

             impl1.period = rmp3.out;

             Impulation_macro (植入1)      

 

             //----------------------------------

             //  连接 MOD6模块的输入并调用 Modulo 6计数器宏。

             //----------------------------------   

             mod_dir1.TrigInput = impl1.out;

                                 

             //使用高级启动来计算换向匹配项?

             if (GUI.AdvancedStartup)

             {

                    //当 BEMF 发出信号时、是时候进行换向、比较了

                    //相对于强制换向周期

                    if (InstaSPIN_BLDC1.Comm_Trig)

                    {

                          BemfLastTrigCnt = BemfTrigCnt;

                          BemfTrigCnt = 0;

                          //检查强制换向周期和 BEMF 换向周期

                          //在允许的错误窗口中

                          if (labs (BemfLastTrigCnt - impl1.period)< GoodTrigCntTrip)

                          {

                                 GoodTrigCnt++;

                          }

                          其他

                          {

                                 GoodTrigCnt = 0;

                          }

                          BemfLastTrigCnt = 0;

                    }

                    其他

                    {

                          BemfTrigCnt++;

                    }

                    //检查是否有足够的换向匹配以切换至闭合换向模式

                    if (GoodTrigCnt > GUI.TripCnt)

                    {

                          ClosedCommutFlag = 1;

                    }                                                      

             }

             //如果我们不使用高级启动,只需切换到“关闭”即可

             //换向模式。

             否则 if (rmp3.Ramp3DoneFlag!= 0)

             {

                    ClosedCommutFlag = 1;

             }

      }

 

      开关(CONTRAL_MODE)

             {

                    管壳电压:

                          if (ClosedCommutFlag = 0)

                          {

                                 SpeedLoopFlag = 1;        //在这个模式中无需等待速度反馈更新。

                                 RC1.SetpointValue =_IQmpy (GUI.DfuncStartup、mod_dir1.CntDirection);

                          }

                          其他

                          {

                                 //----------------------------------

                                 //  连接 RMP 模块的输入并调用斜坡控制宏。

                                 //----------------------------------

                        RC1.targetValue = GUI.Ref;

                              RC_MACRO (RC1)

                          }

                          //----------------------------------

                          //  连接 PWM_DRV 模块的输入并调用 PWM 信号生成

                          //  更新宏。

                          //----------------------------------

                          pwmcntl1.State =(Int16) mod_dir1.Counter;

                          pwmcntl1.Duty = RC1.SetpointValue;

                          PWM_CNTL_MACRO (pwmcntl1)

             

                          中断;

             

                    管壳电流:

                          IREF = GUI.Ref;

                          if (ClosedCommutFlag = 0)

                          {

                                 SpeedLoopFlag = 1;        //在这个模式中无需等待速度反馈更新。

                                 IREF =_IQmpy (gui.CurrentStartup、mod_dir1.CntDirection);//在初始斜坡期间使用启动电流

                          }

                          //----------------------------------

                          //  连接 PID_REG3模块的输入并调用 PID 电流控制器

                          //    宏。

                          //----------------------------------

                 pid1_IDC.term.Ref = Iref;

                         pid1_IDC.term.FBK =_IQmpy (IDCfdbk、mod_dir1.CntDirection);

                 PID_GR_MACRO (pid1_IDC)

 

                          //----------------------------------

                          //  连接 PWM_DRV 模块的输入并调用 PWM 信号生成

                          //  更新宏。

                          //----------------------------------

                          pwmcntl1.State =(Int16) mod_dir1.Counter;

                          pwmcntl1.Duty = pid1_IDC.term.out;

                          PWM_CNTL_MACRO (pwmcntl1)         

                          中断;

 

                    管壳速度:

                  SpeedRef = GUI.Ref;

 

                          //----------------------------------

                          //  连接 PID_REG3模块的输入并调用 PID 电流控制器

                          //    宏。

                          //----------------------------------

                          pwmcntl1.State =(Int16) mod_dir1.Counter;

                          //从固定占空比或由 SpeedLoopFlag 变量控制的速度占空比切换

                 if ((ClosedCommutationFlag = 0)||(SpeedLoopFlag = false))

                 {

                        pwmcntl1.Duty =_IQmpy (gui.dfuncStartup、mod_dir1.CntDirection);                //固定占空比

                 }

                 其他

                 {

                                 //----------------------------------

                                 //  连接 PID_REG3模块的输入并调用 PID 速度控制器

                                 //    宏。

                                 //----------------------------------

                        pid1_spd.term.Ref = SpeedRef;

                        pid1_spd.term.fbk = speed1.Speed;

                        PID_GR_MACRO (pid1_SPD)

                        

                        pwmcntl1.Duty = pid1_spd.term.out;  //受控速度占空比

                 }

                          PWM_CNTL_MACRO (pwmcntl1)         

                          中断;

             

                    外壳级联:

                  SpeedRef = GUI.Ref;

                          //----------------------------------

                          //  连接 PID_REG3模块的输入并调用 PID 电流控制器

                          //    宏。

                          //----------------------------------

                 if ((ClosedCommutationFlag = 0)||(SpeedLoopFlag = false))

                          {

                        pid1_IDC.term.Ref =_IQmpy (gui.CurrentStartup、mod_dir1.CntDirection);

                          }

                          其他

                          {

                                 //----------------------------------

                                 //  连接 PID_REG3模块的输入并调用 PID 速度控制器

                                 //    宏。

                                 //----------------------------------

                        pid1_spd.term.Ref = SpeedRef;

                        pid1_spd.term.fbk = speed1.Speed;

                        PID_GR_MACRO (pid1_SPD)

                        

                        pid1_idc.term.Ref = pid1_spd.term.out;

                          }

                          pid1_IDC.term.FBK =_IQmpy (IDCfdbk、mod_dir1.CntDirection);

                          PID_GR_MACRO (pid1_IDC)

                          //----------------------------------

                          //  连接 PWM_DRV 模块的输入并调用 PWM 信号生成

                          //  更新宏。

                          //----------------------------------

                          pwmcntl1.State =(Int16) mod_dir1.Counter;

                 pwmcntl1.Duty = pid1_IDC.term.out;

                          PWM_CNTL_MACRO (pwmcntl1)

                          中断;

             

                    默认值:

                          //----------------------------------

                          //  连接 PWM_DRV 模块的输入并调用 PWM 信号生成

                          //  更新宏。

                          //----------------------------------

                          pwmcntl1.State = 0;

                          pwmcntl1.Duty = 0;

                          PWM_CNTL_MACRO (pwmcntl1)

                          中断;

             

 

             }

 

      //过滤显示的速度

      GUI.Speed =_IQmpy (SPD_filt_gain、speed1.Speed - GUI.Speed)+ GUI.Speed;

      GUI.SpeedRPM =_IQmpy (speed1.BaseRpm、GUI.Speed);

      

//----------------------------------

//  连接 PWMDAC 模块的输入

//----------------------------------    

/*    PwmDacCh1 =_IQtoQ15 (InstaSPIN_BLDC1.V_int);

      PwmDacCh2 =_IQtoQ15 (InstaSPIN_BLDC1.Vag);

      PwmDacCh3 =_IQtoQ15 (IQIA);

#IF 已定义(DRV8301)||已定义(DRV8302)

      PwmDacCh4 =_IQtoQ15 (InstaSPIN_BLDC1.V_int);

#endif*/

      PwmDacCh1 =_IQtoQ15 (InstaSPIN_BLDC1.V_int);

      PwmDacCh2 =(Int16)(mod_dir1.Counter * 4096.0L);

      PwmDacCh3 =(Int16)(GoodTrigCnt * 4096.0L);

#IF 已定义(DRV8301)||已定义(DRV8302)

      PwmDacCh4 =(Int16) impl1.out;

#endif

 

//----------------------------------

//  连接数据记录模块的输入

//----------------------------------

      DlogCh1 = InstaSPIN_BLDC1.V_int;

      DlogCh2 = InstaSPIN_BLDC1.Vag;

      DlogCh3 = iqIA;

 

//----------------------------------

//  增加虚拟计时器并强制15位绕回

//----------------------------------

      VirtualTimer++;

      VirtualTimer &= 0x00007FFF;

      

//    GUI.SpeedRPM = speed1.SpeedRpm;

      GUI.CurrentDisplay = IDCfdbk;

  InstaSPIN_BLDC1.Int_Threshold = GUI.Threshold;

      }

 

 

 

//----------------------------------

//  调用 PWMDAC 更新宏。

//----------------------------------

      PWMDAC_MACRO (pwmdac1)

 

//----------------------------------

//  调用数据记录更新功能。

//----------------------------------

      graph_Data_Update (&gData);

 

      GpioDataRegs.GPACLEAR.bit.GPIO22 = 1;

 

#if (DSP2803x_DEVICE_H=1)||(DSP280x_DEVICE_H==1)||(F2806x_DEVICE_H==1)

      AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;        //清除 ADCINT1标志为下一个 SOC 重新初始化    

 

//确认中断以接收来自 PIE 组1的更多中断

      PieCtrlRegs.PIEACX.ALL = PIEACK_Group1;

#endif

 

 

void Gui_DBUFF_init ()

      if (DlogCurrent 元素索引!=gData.size)

      {

             *dlogptr1=0;

            dlogptr1++;

             *dlogptr2=0;

             dlogptr2++;

             *dlogptr3=0;

             dlogptr3++;

             DlogCurrent 元件索引++;

      }

      其他

      {

             dlogptr1=DLOG_4ch_buff1;

             dlogptr2=DLOG_4ch_buff2;

             dlogptr3=DLOG_4ch_buff3;

             DlogCurrent 元素索引=0;

      }

 

//============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

//不再需要。

//============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

 

 

 

 

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您可以将模拟信号脚油门连接到 C2000控制器的 REST ADC 引脚、然后配置 ADC 通道以采样油门的输入、将模拟输入转换为目标扭矩电流或速度。
    请注意、您需要添加一个分压器来将0~5V 至0~3.3V 的输入范围转换为与 C2000 ADC 的输入范围相匹配。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    好的、这些 ADC 引脚是否位于"J5"(外部控制访问)上? 我看到引脚。 29"ADC-Vhb1"、#31"ADC-Vhb2"、#32"ADC-Vhb3"。 这些是否适用于模拟速度输入? 此外、我不确定如何在代码中配置 ADC 通道、您认为是否可以提供样片? 我认为这可能是我最大的问题。

    在我解决此问题后、我的系统将100%正常工作。 非常感谢您的帮助和反馈。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您可以参考 DRV8301-HC-KIT 的原理图来选择可用于外部模拟信号的引脚、只有 TSI (J5的引脚38)可用于模拟输入、您需要移除/断开可变电阻器(R28)。

    有关此 ADC 通道的详细配置,您可以参阅项目和技术参考手册中的 ADC 初始化配置函数。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    好的、非常感谢您的帮助。 如果我有任何问题、我会尝试此方法并与您联系。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!  

    我已经尝试在 J5外部控制器上使用引脚#38 (TSI)、并且能够移除可变电阻器(R28)。 我的电机仍然能够使用代码和 GUI 运行、但油门仍然无法控制电机。 我还尝试重写一些代码、但什么也不起作用。 如果我能够获得帮助、为这个特定应用编写代码、我将不胜感激。 否则、我将不再使用此控制器、而必须为我的项目制定另一个计划。  

    感谢您的帮助、  

    Blake Fredieu  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您可能会尝试根据自己的要求设计自己的代码、如果您想使用油门输入、并且需要更改 BLDC_Int_GUI_DRV83xx.c 中的某些设置、则可能无法使用 GUI 来控制电机 我们很难为您提供完整的示例代码、因为我们不知道有关您的最终要求的更多详细信息。 以下步骤可能是您的参考、如果您有更多问题、请告诉我。

    在 f2803xidc_vemf.h 中添加 ADC 通道配置、如下所示
    /* 7 */\
    AdcRegs.ADCSOC7CTL.bit.CHSEL= 8;/*选择:ADC B0->TSI (用于速度调节)*/\
    AdcRegs.ADCSOC7CTL.bit.TRIGSEL= 6;\
    AdcRegs.ADCSOC7CTL.bit.ACQPS= 6;\
    \
    AdcRegs.INTSEL1N2.bit.INT1E = 1;//启用 ADCINT1 */\

    2.在 BLDC_Int_GUI_DRV83xx.c 中添加一些变量
    _IQ AdcThrottle =_IQ (0.0);
    _IQ 偏移节气门=_IQ (0.0);
    _IQ SfThrottle =_IQ (1.0);
    _IQ SpeedThrottle =_IQ (0.0);

    3.读取 ADC 结果并将其转换为 BLDC_Int_GUI_DRV83xx.c 中 MainISR()中的速度基准

    IDC_OFFSET =_IQmpy (cal_filt_gain、IDCfdbk)+ IDC_OFFSET;

    //将油门转换为速度设置
    AdcThrottle =_IQ15toIQ (AdcResult.ADCRESULT7<<3);
    SpeedThrottle =_IQmpy ((AdcThrottle - OffsetThrottle)、SfThrottle);

    4.将油门的速度设置连接到速度参考
    //连接 RMP 模块的输入并调用斜坡控制宏。
    //----------------------------------
    //RC1.targetValue = GUI.Ref;
    RC1.targetValue = SpeedThrottle;

    您可能需要更改一些其他代码以禁用 GUI 控制。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    [引用 user="Yanming">您可能会尝试根据自己的要求设计代码、如果您想使用油门输入、并且需要更改 BLDC_Int_GUI_DRV83xx.c 中的某些设置、则可能无法使用 GUI 来控制电机 我们很难为您提供完整的示例代码、因为我们不知道有关您的最终要求的更多详细信息。 以下步骤可能是您的参考、如果您有更多问题、请告诉我。

    在 f2803xidc_vemf.h 中添加 ADC 通道配置、如下所示
    /* 7 */\
    AdcRegs.ADCSOC7CTL.bit.CHSEL = 8;/*选择:ADC B0->TSI 转速调节*/\
    AdcRegs.ADCSOC7CTL.bit.TRIGSEL = 6;\
    AdcRegs.ADCSOC7CTL.bit.ACQPS = 6;\
    \
    AdcRegs.INTSEL1N2.bit.INT1E = 1;//启用 ADCINT1 */\

    2.在 BLDC_Int_GUI_DRV83xx.c 中添加一些变量
    _IQ AdcThrottle =_IQ (0.0);
    _IQ 偏移节气门=_IQ (0.0);
    _IQ SfThrottle =_IQ (1.0);
    _IQ SpeedThrottle =_IQ (0.0);

    3.读取 ADC 结果并将其转换为 BLDC_Int_GUI_DRV83xx.c 中 MainISR()中的速度基准

    IDC_OFFSET =_IQmpy (cal_filt_gain、IDCfdbk)+ IDC_OFFSET;

    //将油门转换为速度设置
    AdcThrottle =_IQ15toIQ (AdcResult.ADCRESULT7<<3);
    SpeedThrottle =_IQmpy ((AdcThrottle - OffsetThrottle)、SfThrottle);

    4.将油门的速度设置连接到速度参考
    //连接 RMP 模块的输入并调用斜坡控制宏。
    //----------------------------------
    // RC1.targetValue = GUI.Ref;
    RC1.targetValue = SpeedThrottle;

    您可能需要更改一些其他代码以禁用 GUI 控制。

    [/报价]

    所以、我进入并将程序更改为您在上面提到的内容。 我不断收到下面列出的错误消息。

    我有一个具有编程经验的人来帮助我、但仍然无法使用控制器。   

    以了解有关我的应用的一些详细信息。 我使用模拟信号踏板来运行具有霍尔传感器的48V 1600W BLDC 电机。 正如我之前提到过的、我可以让电机通过 GUI 正常运行、但无法使踏板工作。 我有一些关于如何连接它的图片。

    我希望我的电机在踩下踏板后立即启动、并以0%的速度启动、但在我踩下踏板的距离越远、速度就会逐渐增加、一旦我完全踩下踏板、速度/功率就会达到100%。 与变速变阻器类似、也类似于车辆中的正常加速度。

    我使用的踏板。  

    如何进行布线。 将引脚38用于绿色速度控制线。  

    连接电机和踏板。  

    这就是我要为它供电的东西