Post Go back to editing

Homing

Category: Hardware
Product Number: TMC5240

Hello I'm having trouble homing the TMC5240. I have configured the motor to run in ramp mode using the position controller. However, I have been un successful in homing the device. I'm using an active low switch(meaning when the position has reached the switch the signal will be 0V) . I have confirmed that the switch works correctly, meaning when its open I read 5V and when its closed I read 0V. Below is the code, the algorithm is based of the data sheets recommendations. Below is code. The result is the motor keeps moving until the maximum number of steps is reached. The motor does not stop regardless of the state of the switch. 

void homing_procedure(){

set_tmc_5240_default_speed() ; //set the default slow speed.

write_tmc5240_int(TMC5240_RAMPMODE, 0) ; //set to position controller
write_tmc5240datagram(TMC5240_SWMODE,0x00,0x00,0x08,0x24) ; // set bit 11 to 1 enable soft stop, set bit 5 latch_l_active to one(enable postion latching,bit 2 to one set polarity of stop to active_low
write_tmc5240_int(TMC5240_XTARGET,( int32)(0)) ; //start moving towards the switch. position initialized to the maximum amount of steps possible to travel
int32 read_value=1000 ; //set to dummy value
//motoro should be stopped at this point.
while(read_value!=0)
read_value = (signed int32)read_TMC5240_int(TMC5240_VACTUAL) ;
set_tmc_5240_ramp_mode(0x03) ; //set IC to hold mode.

signed int32 x_latch,x_actual ;
x_latch = (signed int32)read_TMC5240_int(TMC5240_XLATCH) ;
x_actual = (signed int32)read_TMC5240_int(TMC5240_XACTUAL) ;
write_tmc5240_int(TMC5240_XACTUAL,(signed int32)(x_latch-x_actual)) ; //per the data sheet position should be initalized to zero.
write_tmc5240_int(TMC5240_RAMPMODE, 0) ; //set mode to ramp mode position not velocity
set_tmc_5240_default_speed() ; //set the default slow speed.
//should be initalized position zero will initalize the switch.
}