在上一篇博文中,我們能夠確定級聯(lián)控制器回路的穩(wěn)定P-I參數(shù)。有了這些知識,我們想向您展示我們是如何創(chuàng)建一個小的示例程序的,并放入Landungsrbücke的固件中。
此代碼的基本功能是初始化步進(jìn)電機(jī)控制的TMC4671。這是在init_Basics(…)中通過編寫幾個配置寄存器來完成的,而reset_Basics(…)將此工作中使用的所有寄存器重置為定義的0狀態(tài)。這將取代IDE配置向?qū)е惺褂媚J(rèn)按鈕的第一步。
配置ABN(…)-功能將在功率因數(shù)調(diào)整轉(zhuǎn)子至0后將ABN計數(shù)設(shè)置為0。要做到這一點(diǎn),我們還需要對磁通施加電壓。
init_PosMode(…)設(shè)置TMC4671進(jìn)入位置模式的正確寄存器。
使用TMC4671_setAbsolutTargetPosition(…)將控制器的目標(biāo)位置設(shè)置為所需值,使電機(jī)轉(zhuǎn)動,直到達(dá)到目標(biāo)位置。這里的絕對位置總是指我們在configure_ABN(…)函數(shù)中配置的零位置。
注:如果您希望相對于實際位置移動,可以使用函數(shù)TMC4671_setRelativeTargetPosition(…)。
為了找到我的設(shè)置的最小和最大位置,我在“查找目標(biāo)位置”(…)中選擇了兩個無法到達(dá)的目標(biāo)位置。對我來說,這是500000和-500000??刂破鞯却欢〞r間以確保它到達(dá)結(jié)束位置。然后用函數(shù)TMC4671_getActualPosition(…)保存實際位置。另一個方向也進(jìn)行同樣的設(shè)置。兩個端點(diǎn)的值現(xiàn)在可以用于新的目標(biāo)位置,可以再次使用TMC4671_setAbsolutTargetPosition(…)來設(shè)置。
運(yùn)行時也可以使用線性坡道加速和減速, 使用函數(shù)TMC_ramp_linear_compute(…)和類型為TMC_LinearRamp的結(jié)構(gòu)來實現(xiàn)這個功能(您可以在文件LinearRamp1.h和LinearRamp1.c中的API中找到更多信息)。這將在軟件中創(chuàng)建一個包含我們的軌跡信息的斜坡。我還使用上述文件中的相應(yīng)函數(shù)設(shè)置了結(jié)構(gòu)的一些參數(shù)。我可以使用結(jié)構(gòu)中的TMC_ramp_linear_set_target position(…)設(shè)置漸變的目標(biāo)位置。之后,我使用TMC4671_setAbsolutTargetPosition(calculated_ramp)中計算出的斜坡位置, 循環(huán)工作直到達(dá)到實際目標(biāo)位置,。
斜坡有什么作用?我們不是設(shè)定一條指令可以到達(dá)的絕對目標(biāo)位置,而是將軌跡劃分為多個子目標(biāo)位置。在循環(huán)的每次迭代中,我們增加目標(biāo)位置,控制器將調(diào)整到新的目標(biāo)。然而,Landungsbrücke增加目標(biāo)位置的速度比我們控制器的自適應(yīng)速度高,因此隨著時間的推移,目標(biāo)位置和實際電機(jī)位置之間的差異增大。當(dāng)實際位置和目標(biāo)位置之間的偏移量增加時,這會導(dǎo)致電機(jī)加速。
減速則相反。Landungsbrücke將降低設(shè)定目標(biāo)位置的速度,控制器將慢慢跟上,直到到達(dá)終點(diǎn)位置。
為了提高馬達(dá)的速度,我把實際的斜坡位置乘以1024倍。這必須通過將軟件斜坡的目標(biāo)位置除以1024來補(bǔ)償。這樣我們就可以根據(jù)我們的應(yīng)用來調(diào)整斜坡,并增加馬達(dá)的加速度和速度。
為什么要使用(軟件)漸變?基本上,它給了我們一個更穩(wěn)定的方法來達(dá)到我們的目標(biāo)位置,因為我們有一個確定的加速和減速的方法,它大大減少了超過目標(biāo)的可能性。
Landungsbrücke在TMC4671寄存器中交替這些目標(biāo)位置,因此電機(jī)將交替滑動的位置。
使用完成的代碼,我為Landungsrbücke的引導(dǎo)加載程序生成一個十六進(jìn)制文件,并使用TMCL-IDE更新它。
希望你能利用一些顯示的例子,以便你轉(zhuǎn)換數(shù)字信息為你的項目的物理運(yùn)動!
使用以下代碼,將初始化我的驅(qū)動器,執(zhí)行編碼器初始化,并在兩個末端停止上執(zhí)行重設(shè)原點(diǎn)。然后,執(zhí)行來回運(yùn)動。
我可以用TMCL-IDE將固件上傳到Landungsbrücke,開機(jī)后它會自動啟動。我可以通過RTMI監(jiān)控系統(tǒng)行為。
代碼示例:
#include "boards/Board.h" #include "hal/derivative.h" #include "hal/HAL.h" #include "tmc/IdDetection.h" #include "tmc/TMCL.h" #include "tmc/VitalSignsMonitor.h" #include "tmc/BoardAssignment.h" #include "tmc/ramp/LinearRamp1.h" #include "TMC-API/tmc/ic/TMC4671/TMC4671.h" #include "TMC-API/tmc/ic/TMC4671/TMC4671_Register.h" //As I use the names of its registers this needs to be included //mydefines #define STATE_START_INIT 1 #define STATE_RUN_1 2 #define STATE_RUN_2 3 #define UD_EXT 3202 //Torque-Flux Limits 15000 #define TORQUE_FLUX_LIMIT 10000 //Velocity Limit 10000 #define VELOCITY_LIMIT 10000 //P-I-defines #define TORQUE_FLUX_P 4952 #define TORQUE_FLUX_I 10939 #define VELOCITY_P 2200 #define VELOCITY_I 2000 #define POSITION_P 45 #define POSITION_I 0 //for checking motor supply voltage #define VM_FACTOR 713 #define ADC_VM_RES 65535 //Landungsbruecke define -- change for Startrampe //Software-Ramp defines #define STEPDIR_FREQUENCY (1 << 17) #define STEPDIR_MAX_VELOCITY (1 << 20) #define STEPDIR_MAX_ACCELERATION 2147418111 #define STEPDIR_DEFAULT_ACCELERATION 100000 #define STEPDIR_DEFAULT_VELOCITY STEPDIR_MAX_VELOCITY #define RAMP_SPEED_FACTOR 1024 //end mydefines void init_PosMode(uint8_t motor) { //Set registers needed for position mode //tmc4671_writeInt(motor, TMC4671_VELOCITY_SELECTION, TMC4671_VELOCITY_PHI_M_ABN); tmc4671_writeInt(motor, TMC4671_PID_TORQUE_FLUX_TARGET_DDT_LIMITS, 32767); //max tmc4671_writeInt(motor, TMC4671_PIDOUT_UQ_UD_LIMITS, 32767); //max tmc4671_writeInt(motor, TMC4671_PID_TORQUE_FLUX_LIMITS, TORQUE_FLUX_LIMIT); tmc4671_writeInt(motor, TMC4671_PID_ACCELERATION_LIMIT, 2147483647); tmc4671_writeInt(motor, TMC4671_PID_VELOCITY_LIMIT, VELOCITY_LIMIT); tmc4671_writeInt(motor, TMC4671_PID_POSITION_LIMIT_LOW, 0x80000001); tmc4671_writeInt(motor, TMC4671_PID_POSITION_LIMIT_HIGH, 0x7FFFFFFF); tmc4671_writeInt(motor, TMC4671_PHI_E_SELECTION, 0x00000003); //phi_e_abn tmc4671_writeInt(motor, TMC4671_VELOCITY_SELECTION, TMC4671_VELOCITY_PHI_M_ABN); tmc4671_writeInt(motor, TMC4671_POSITION_SELECTION, TMC4671_POSITION_PHI_M_ABN); //phi_m_abn tmc4671_writeInt(motor, TMC4671_MODE_RAMP_MODE_MOTION, 0x00000003); //position mode //The following gain-values were determined using the USB-2-RTMI and following the PI-tuning guide tmc4671_setTorqueFluxPI(motor, TORQUE_FLUX_P, TORQUE_FLUX_I); //(motor, P, I) tmc4671_setVelocityPI(motor, VELOCITY_P, VELOCITY_I); tmc4671_setPositionPI(motor, POSITION_P, POSITION_I); } //Check VM uint32_t current_VM() { uint32_t VM; VM = *HAL.ADCs->VM; // read ADC value for motor supply VM VM = (VM*VM_FACTOR)/ADC_VM_RES; // calculate voltage from ADC value return VM; } //End Check VM void init_Basics(uint8_t motor) { //Configure basic registers like motor type, adc-offset tmc4671_writeInt(motor, TMC4671_MOTOR_TYPE_N_POLE_PAIRS, 0x00020032); //x0002 - Stepper, x0032 = 50 polepairs tmc4671_writeInt(motor, TMC4671_PWM_POLARITIES, 0x00000000); tmc4671_writeInt(motor, TMC4671_PWM_MAXCNT, 0x00000F9F); //Maxcount of PWM-counter tmc4671_writeInt(motor, TMC4671_PWM_BBM_H_BBM_L, 0x00001919); //Break before make times tmc4671_writeInt(motor, TMC4671_PWM_SV_CHOP, 0x00000007); //turn on PWM //Configure ADC -- Values were taken from the ide after the set offset option was used tmc4671_writeInt(motor, TMC4671_ADC_I_SELECT, 0x18000100); // configure ADC-Inputs tmc4671_writeInt(motor, TMC4671_dsADC_MCFG_B_MCFG_A, 0x00100010); // configure ADCs tmc4671_writeInt(motor, TMC4671_dsADC_MCLK_A, 0x20000000); // turn on clock-signal for group-A ADCs tmc4671_writeInt(motor, TMC4671_dsADC_MCLK_B, 0x00000000); // turn off clock-signal for group-B ADCs tmc4671_writeInt(motor, TMC4671_dsADC_MDEC_B_MDEC_A, 0x014E014E); // Constants for filter tmc4671_writeInt(motor, TMC4671_ADC_I0_SCALE_OFFSET, 0x01005D80); // Fill in the offsets determined in the IDE tmc4671_writeInt(motor, TMC4671_ADC_I1_SCALE_OFFSET, 0x01005CEF); // Fill in the offsets determined in the IDE // Open loop settings tmc4671_writeInt(motor, TMC4671_OPENLOOP_MODE, 0x00000000); tmc4671_writeInt(motor, TMC4671_OPENLOOP_ACCELERATION, 0x0000003C); tmc4671_writeInt(motor, TMC4671_OPENLOOP_VELOCITY_TARGET, 0x00000000); tmc4671_writeInt(motor, TMC4671_OPENLOOP_PHI, 0x00000000); // Feedback selection tmc4671_writeInt(motor, TMC4671_PHI_E_SELECTION, 0x00000000); tmc4671_writeInt(motor, TMC4671_MODE_RAMP_MODE_MOTION, 0x00000008); //tmc4671_writeInt(motor, TMC4671_UQ_UD_EXT, 0x00000F9F); tmc4671_writeInt(motor, TMC4671_ABN_DECODER_PPR, 0x00009C40); //Set Limits tmc4671_writeInt(motor, TMC4671_PID_TORQUE_FLUX_TARGET_DDT_LIMITS, 0x7FFF); //max tmc4671_writeInt(motor, TMC4671_PIDOUT_UQ_UD_LIMITS, 32767); //max tmc4671_writeInt(motor, TMC4671_PID_TORQUE_FLUX_LIMITS, TORQUE_FLUX_LIMIT); tmc4671_writeInt(motor, TMC4671_PID_ACCELERATION_LIMIT, 2147483647); tmc4671_writeInt(motor, TMC4671_PID_VELOCITY_LIMIT, VELOCITY_LIMIT); tmc4671_writeInt(motor, TMC4671_PID_POSITION_LIMIT_LOW, 0x80000001); tmc4671_writeInt(motor, TMC4671_PID_POSITION_LIMIT_HIGH, 0x7FFFFFFF); } void reset_Basics(uint8_t motor) { //reset registers of TMC4671 that will later be used to 0 wait(1500); tmc4671_writeInt(motor, TMC4671_PWM_SV_CHOP, 0); tmc4671_writeInt(motor, TMC4671_MOTOR_TYPE_N_POLE_PAIRS, 0); tmc4671_writeInt(motor, TMC4671_PWM_POLARITIES, 0); tmc4671_writeInt(motor, TMC4671_PWM_MAXCNT, 0); tmc4671_writeInt(motor, TMC4671_PWM_BBM_H_BBM_L, 0); tmc4671_writeInt(motor, TMC4671_ADC_I_SELECT, 0); tmc4671_writeInt(motor, TMC4671_dsADC_MCFG_B_MCFG_A, 0); tmc4671_writeInt(motor, TMC4671_dsADC_MCLK_A, 0); tmc4671_writeInt(motor, TMC4671_dsADC_MCLK_B, 0); tmc4671_writeInt(motor, TMC4671_dsADC_MDEC_B_MDEC_A, 0); tmc4671_writeInt(motor, TMC4671_ADC_I0_SCALE_OFFSET, 0); tmc4671_writeInt(motor, TMC4671_ADC_I1_SCALE_OFFSET, 0); tmc4671_writeInt(motor, TMC4671_OPENLOOP_MODE, 0); tmc4671_writeInt(motor, TMC4671_OPENLOOP_ACCELERATION, 0); tmc4671_writeInt(motor, TMC4671_OPENLOOP_VELOCITY_TARGET, 0); tmc4671_writeInt(motor, TMC4671_PHI_E_SELECTION, 0); tmc4671_writeInt(motor, TMC4671_MODE_RAMP_MODE_MOTION, 0); tmc4671_writeInt(motor, TMC4671_UQ_UD_EXT, 0); tmc4671_writeInt(motor, TMC4671_ABN_DECODER_PPR, 0); tmc4671_writeInt(motor, TMC4671_PID_TORQUE_FLUX_TARGET_DDT_LIMITS, 0); tmc4671_writeInt(motor, TMC4671_PIDOUT_UQ_UD_LIMITS, 0); tmc4671_writeInt(motor, TMC4671_PID_TORQUE_FLUX_LIMITS, 0); tmc4671_writeInt(motor, TMC4671_PID_ACCELERATION_LIMIT, 0); tmc4671_writeInt(motor, TMC4671_PID_VELOCITY_LIMIT, 0); tmc4671_writeInt(motor, TMC4671_PID_POSITION_LIMIT_LOW, 0); tmc4671_writeInt(motor, TMC4671_PID_POSITION_LIMIT_HIGH, 0); tmc4671_writeInt(motor, TMC4671_PHI_E_SELECTION, 0); tmc4671_writeInt(motor, TMC4671_VELOCITY_SELECTION, 0); tmc4671_writeInt(motor, TMC4671_POSITION_SELECTION, 0); tmc4671_writeInt(motor, TMC4671_MODE_RAMP_MODE_MOTION, 0); tmc4671_writeInt(motor, TMC4671_PID_POSITION_TARGET, 0); tmc4671_writeInt(motor, TMC4671_PID_POSITION_ACTUAL, 0); tmc4671_setTorqueFluxPI(motor, 0, 0); //(motor, P, I) tmc4671_setVelocityPI(motor, 0, 0); // (motor, P, I) tmc4671_setPositionPI(motor, 0, 0); // (motor, P, I) } void init_softwareRamp(TMC_LinearRamp *linearRamp) { tmc_ramp_linear_init(linearRamp); tmc_ramp_linear_set_mode(linearRamp, TMC_RAMP_LINEAR_MODE_POSITION); tmc_ramp_linear_set_maxVelocity(linearRamp, STEPDIR_DEFAULT_VELOCITY); tmc_ramp_linear_set_acceleration(linearRamp, STEPDIR_DEFAULT_ACCELERATION); } void find_targetPositions(uint8_t motor, int32_t *lower_End, int32_t*upper_End) { tmc4671_setAbsolutTargetPosition(motor, 500000); // ~ 7.5 motor turns wait(1500); /* After slide reached one end of the setup the absolute position is stored in memory For convenience I reduce the value of the target position to be saved a little, * as driving into the endposition with full force is annoyingly loud :) * if this is your goal just remove the +/- 1000 */ *lower_End = (tmc4671_getActualPosition(motor)-1000); tmc4671_setAbsolutTargetPosition(motor, 0); //return to the starting position wait(1000); // Assumed an unreachable position so the slide reaches the other side of the setup tmc4671_setAbsolutTargetPosition(motor, -500000); // ~ -7.5 motor turns wait(1500); // After slide reached the other end of the setup the absolute position is stored in memory *upper_End = (tmc4671_getActualPosition(motor)+1000); tmc4671_setAbsolutTargetPosition(motor, 0); wait(1500); } void configure_ABN(uint8_t motor, uint16_t startVoltage) { // set ABN_DECODER_PHI_E_OFFSET to zero tmc4671_writeRegister16BitValue(motor, TMC4671_ABN_DECODER_PHI_E_PHI_M_OFFSET, BIT_16_TO_31, 0); // select phi_e_ext tmc4671_writeRegister16BitValue(motor, TMC4671_PHI_E_SELECTION, BIT_0_TO_15, 1); // set an initialization voltage on UD_EXT (to the flux, not the torque!) tmc4671_writeRegister16BitValue(motor, TMC4671_UQ_UD_EXT, BIT_16_TO_31, 0); tmc4671_writeRegister16BitValue(motor, TMC4671_UQ_UD_EXT, BIT_0_TO_15, startVoltage); // set the "zero" angle tmc4671_writeRegister16BitValue(motor, TMC4671_PHI_E_EXT, BIT_0_TO_15, 0); tmc4671_writeInt(motor, TMC4671_ABN_DECODER_MODE, 0x00001000); //Set PHI_E to 0?° angle so the rotor alignes itself with it tmc4671_writeInt(motor, TMC4671_PHI_E_SELECTION, 0x00000000); wait(4000); tmc4671_readRegister16BitValue(motor, TMC4671_ABN_DECODER_PHI_E_PHI_M, BIT_16_TO_31); //After the rotor has aligned this will set the ABN_DECODER_COUNT to 0 so there is a defined 0-position tmc4671_writeInt(motor, TMC4671_ABN_DECODER_COUNT, 0); } void tmc4671setPositionModeAndRun(uint8_t motor, uint8_t *initState, uint16_t startVoltage, int32_t *upper_End, int32_t *lower_End, TMC_LinearRamp *linearRamp) { /*State Machine with state-pointer *initState and 3 states * STATE_START_INIT: Sets TMC4671-registers for my application and configures the ABN-Encoder * Drives to the ends of the track to get the actual min/max position values * Drives to the first end position * * STATE_RUN_1: Drives to one end and changes direction when the *lower_End is reached * * STATE_RUN_2: Drives to the other end and changes direction when *upper_End is reached */ switch (*initState) { case STATE_START_INIT: //reset TMC4671 registers reset_Basics(motor); //set TMC4671 registers with basic data like motortype, number of polepairs and so on init_Basics(motor); //initialize the software ramp init_softwareRamp(linearRamp); //configure ABN configure_ABN(motor, startVoltage); //Enter position-Mode init_PosMode(motor); //configure the end positions and store them in *lower_End and *upper_End find_targetPositions(motor, lower_End, upper_End); *initState = STATE_RUN_1; //set the first target position using the software ramp tmc_ramp_linear_set_targetPosition(linearRamp, (*lower_End/RAMP_SPEED_FACTOR)); break; case STATE_RUN_1: //drive from one end to the other: positive direction tmc_ramp_linear_compute(linearRamp); tmc4671_setAbsolutTargetPosition(motor, (RAMP_SPEED_FACTOR*tmc_ramp_linear_get_rampPosition(linearRamp))); //When the target position is reached we will change direction if(tmc4671_getActualPosition(motor) >= (*lower_End-RAMP_SPEED_FACTOR)) { wait(50); *initState = STATE_RUN_2; tmc_ramp_linear_set_targetPosition(linearRamp, (*upper_End/RAMP_SPEED_FACTOR)); break; } *initState = STATE_RUN_1; break; case STATE_RUN_2: //drive from one end to the other: negative direction tmc_ramp_linear_compute(linearRamp); tmc4671_setAbsolutTargetPosition(motor, (RAMP_SPEED_FACTOR*tmc_ramp_linear_get_rampPosition(linearRamp))); //When the target position is reached we will change direction if(tmc4671_getActualPosition(motor) <= (*upper_End + RAMP_SPEED_FACTOR)) { wait(50); *initState = STATE_RUN_1; tmc_ramp_linear_set_targetPosition(linearRamp, (*lower_End/RAMP_SPEED_FACTOR)); break; } *initState = STATE_RUN_2; break; default: *initState = 0; break; } } const char *VersionString = MODULE_ID"V308"; // module id and version of the firmware shown in the TMCL-IDE /* Keep as is! These lines are important for the update functionality. */ #if defined(Landungsbruecke) const uint8_t Protection[] __attribute__ ((section(".cfmconfig")))= { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //Backdoor key 0xFF, 0xFF, 0xFF, 0xFF, //Flash protection (FPPROT) 0x7E, //Flash security (FSEC) 0xF9, //Flash option (FOPT) 0xFF, //reserved 0xFF //reserved }; struct BootloaderConfig { uint32_t BLMagic; uint32_t drvEnableResetValue; }; // This struct gets placed at a specific address by the linker struct BootloaderConfig __attribute__ ((section(".bldata"))) BLConfig; #endif /* Check if jumping into bootloader is forced */ /* */ /* In order to jump to bootloader e.g. because of an accidental infinite loop */ /* in a modified firmware you may short ID_CLK and ID_CH0 pins on start up. */ /* This will force the entrance into bootloader mode and allow to replace bad firmware. */ void shallForceBoot() { // toggle each pin and see if you can read the state on the other // leave if not, because this means that the pins are not tied together HAL.IOs->config->toOutput(&HAL.IOs->pins->ID_CLK); HAL.IOs->config->toInput(&HAL.IOs->pins->ID_CH0); HAL.IOs->config->setHigh(&HAL.IOs->pins->ID_CLK); if(!HAL.IOs->config->isHigh(&HAL.IOs->pins->ID_CH0)) return; HAL.IOs->config->setLow(&HAL.IOs->pins->ID_CLK); if(HAL.IOs->config->isHigh(&HAL.IOs->pins->ID_CH0)) return; HAL.IOs->config->toOutput(&HAL.IOs->pins->ID_CH0); HAL.IOs->config->toInput(&HAL.IOs->pins->ID_CLK); HAL.IOs->config->setHigh(&HAL.IOs->pins->ID_CH0); if(!HAL.IOs->config->isHigh(&HAL.IOs->pins->ID_CLK)) return; HAL.IOs->config->setLow(&HAL.IOs->pins->ID_CH0); if(HAL.IOs->config->isHigh(&HAL.IOs->pins->ID_CLK)) return; // not returned, this means pins are tied together tmcl_boot(); } /* Call all standard initialization routines. */ static void init() { #if defined(Landungsbruecke) // Default value: Driver enable gets set high by the bootloader BLConfig.drvEnableResetValue = 1; #endif HAL.init(); // Initialize Hardware Abstraction Layer IDDetection_init(); // Initialize board detection tmcl_init(); // Initialize TMCL communication tmcdriver_init(); // Initialize dummy driver board --> preset EvalBoards.ch2 tmcmotioncontroller_init(); // Initialize dummy motion controller board --> preset EvalBoards.ch1 VitalSignsMonitor.busy = 1; // Put state to busy Evalboards.driverEnable = DRIVER_ENABLE; Evalboards.ch1.id = 0; // preset id for driver board to 0 --> error/not found Evalboards.ch2.id = 0; // preset id for driver board to 0 --> error/not found // We disable the drivers before configurating anything HAL.IOs->config->toOutput(&HAL.IOs->pins->DIO0); HAL.IOs->config->setHigh(&HAL.IOs->pins->DIO0); IdAssignmentTypeDef ids = { 0 }; IDDetection_initialScan(&ids); // start initial board detection IDDetection_initialScan(&ids); // start second time, first time not 100% reliable, not sure why - too fast after startup? if(!ids.ch1.id && !ids.ch2.id) { shallForceBoot(); // only checking to force jump into bootloader if there are no boards attached HAL.IOs->config->toOutput(&HAL.IOs->pins->ID_CLK); HAL.IOs->config->toInput(&HAL.IOs->pins->ID_CH0); } Board_assign(&ids); // assign boards with detected id VitalSignsMonitor.busy = 0; // not busy any more! } /* main function */ int main(void) { //initialise some pointers //state pointer for fsm uint8_t init_State = STATE_START_INIT; uint8_t *initState; initState = &init_State; //store one end of the track int32_t upper_end = 0; int32_t *upper_End; upper_End= &upper_end; //store the other end int32_t lower_end = 0; int32_t *lower_End; lower_End= &lower_end; //convenience uint8_t motor = 0; //"flipflop" uint8_t block = 0; //struct used for the software ramp - see \TMC-API\tmc\ramp\LinearRamp1.h for typedef etc. TMC_LinearRamp adressRamp; TMC_LinearRamp *aRamp; aRamp = &adressRamp; init(); // Main loop while(1) { // Check all parameters and life signs and mark errors vitalsignsmonitor_checkVitalSigns(); // Perodic jobs of Motion controller/Driver boards Evalboards.ch1.periodicJob(systick_getTick()); Evalboards.ch2.periodicJob(systick_getTick()); // Process TMCL communication tmcl_process(); if (Evalboards.ch1.id != ID_TMC4671) continue; if(current_VM()<20){ tmc4671_writeInt(motor, TMC4671_PWM_SV_CHOP, 0); // Turn off PWM after unexpected reset reset_Basics(motor); // Set the registers needed in this example to a defined default state continue; } if(block == 0) { tmc4671_writeInt(motor, TMC4671_PWM_SV_CHOP, 0); //Turn of PWM-Register after SPI was initialized reset_Basics(motor); block = 1; } tmc4671setPositionModeAndRun(motor, initState, UD_EXT, lower_End, upper_End, aRamp); } return 0; }
評論前必須登錄!
注冊