Firmware/FFBoard/UserExtensions/Src/TMC4671.cpp
/*
 * Sets all parameters of the driver at startup
 */
Sets all parameters of the driver at startup
Sets all parameters of the driver at startup
bool TMC4671::initialize(){
	if(!pingDriver()){
		ErrorHandler::addError(Error(ErrorCode::tmcCommunicationError, ErrorType::warning, std::string(this->getInfo().name) + " " + this->getInfo().unique + " not responding"));
		return false;
	}
	writeReg(1, 1);
	if(readReg(0) == 0x00010000 && allowSlowSPI){
		pulseClipLed();
		this->spiConfig.peripheral.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
		spiPort.configurePort(&this->spiConfig.peripheral);
		oldTMCdetected = true;
	}
	if(!oldTMCdetected){
		this->setPidPrecision(pidPrecision);
	}
	writeReg(0x64, 0); 
	setPwm(0,conf.pwmcnt,conf.bbmL,conf.bbmH); 
	setMotorType(conf.motconf.motor_type,conf.motconf.pole_pairs);
	setPhiEtype(conf.motconf.phiEsource);
	setup_HALL(hallconf); 
	initAdc(conf.mdecA,conf.mdecB,conf.mclkA,conf.mclkB);
	setAdcOffset(conf.adc_I0_offset, conf.adc_I1_offset);
	setAdcScale(conf.adc_I0_scale, conf.adc_I1_scale);
	if(!calibrateAdcOffset(150)){
		changeState(TMC_ControlState::HardError); 
		enablePin.reset();
		return false;
	}
	if(oldTMCdetected){
		setBrakeLimits(52400,52800);
	}else{
		setBrakeLimits(50700,50900); 
	}
	setStatusMask(0); 
	setPids(curPids); 
	if(hasPower()){
		enablePin.set();
		setPwm(7);
		calibrateAdcOffset(400); 
		active = true;
	}
	setEncoderType(conf.motconf.enctype);
	initialized = true;
	initTime = HAL_GetTick();
	return initialized;
}
bool TMC4671 :: initialize ( ) { if ( ! pingDriver ( ) ) { ErrorHandler :: addError ( Error ( ErrorCode :: tmcCommunicationError , ErrorType :: warning , std :: string ( this -> getInfo ( ) . name ) + " " + this -> getInfo ( ) . unique + " " ) ) ; return false ; } writeReg ( 1 , 1 ) ; if ( readReg ( 0 ) == 0x00010000 && allowSlowSPI ) { pulseClipLed ( ) ; this -> spiConfig . peripheral . BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64 ; spiPort . configurePort ( & this -> spiConfig . peripheral ) ; oldTMCdetected = true ; } if ( ! oldTMCdetected ) { this -> setPidPrecision ( pidPrecision ) ; } writeReg ( 0x64 , 0 ) ; setPwm ( 0 , conf . pwmcnt , conf . bbmL , conf . bbmH ) ; setMotorType ( conf . motconf . motor_type , conf . motconf . pole_pairs ) ; setPhiEtype ( conf . motconf . phiEsource ) ; setup_HALL ( hallconf ) ; initAdc ( conf . mdecA , conf . mdecB , conf . mclkA , conf . mclkB ) ; setAdcOffset ( conf . adc_I0_offset , conf . adc_I1_offset ) ; setAdcScale ( conf . adc_I0_scale , conf . adc_I1_scale ) ; if ( ! calibrateAdcOffset ( 150 ) ) { changeState ( TMC_ControlState :: HardError ) ; enablePin . reset ( ) ; return false ; } if ( oldTMCdetected ) { setBrakeLimits ( 52400 , 52800 ) ; } else { setBrakeLimits ( 50700 , 50900 ) ; } setStatusMask ( 0 ) ; setPids ( curPids ) ; if ( hasPower ( ) ) { enablePin . set ( ) ; setPwm ( 7 ) ; calibrateAdcOffset ( 400 ) ; active = true ; } setEncoderType ( conf . motconf . enctype ) ; initialized = true ; initTime = HAL_GetTick ( ) ; return initialized ; }
Sets all parameters of the driver at startup
Sets all parameters of the driver at startup
//	active = true; //	if(state == TMC_ControlState::uninitialized){ //		state = TMC_ControlState::Init_wait; //	} // Check if a TMC4671 is active and replies correctly /* Slow down SPI if old TMC engineering sample is detected
		 * The first version has a high chance of glitches of the MSB
		 * when high spi speeds are used.
		 * This can cause problems for some operations.
		 */ // Write main constants // No flux/torque // Set FOC @ 25khz but turn off pwm for now // Enables hall filter and masking // Initial adc calibration // ADC or shunt amp is broken! // brake res failsafe. /*
	 * Single ended input raw value
	 * 0V = 0x7fff
	 * 4.7k / (360k+4.7k) Divider on old board.
	 * 1.5k / (71.5k+1.5k) 16.121 counts 60V new. 100V VM => 2V
	 * 13106 counts/V input.
	 */ // Activates around 60V as last resort failsave. Check offsets from tmc leakage // Disable status output by default. // Write basic pids // Calibrate ADC again with power // Home? // Run in direction of N pulse. Enable flag/interrupt //runOpenLoop(3000, 0, 5, 100);