bigtreetech / BIGTREETECH-S42B-V1.0

The closed-loop drive is to feedback the rotation angle of the stepping motor to the control panel, compare the distance that needs to be rotated with the distance of the actual rotation, calculate the error value, and then compensate, so as to prevent the problem of multi-step and lost step. The closed-loop drive can completely overcome the lost step of the open-loop stepping motor, and can also significantly improve the performance of the motor at high speed
108 stars 53 forks source link

Added sensorless homing functionality to S42B #27

Open Quas7 opened 3 years ago

Quas7 commented 3 years ago

Use SWDO pin (silkscreen on PCB) of S42B communication pin header as active low signal to trigger endstop based on angular deviation.

Mind that connecting SWDIO to an endstop pin on the mainboard is a non-buffered direct connection to the STM32 controller on the S42B Adjust the sensitivty for sensorless homing with #define sensorless_sensitivty. And generally do not home too fast during testing.

Also note that the repurposing of the SWDIO Pin (PA13) as sensorless homing endstop output might break the on-the-fly SWD programming. Pressing RES(ET) on the S42B once and retry programming normally works fine. The triggering of the sensorless homing sensitivty threshold kills the on-the-fly SWD interface!). If it does not, you will have to hold the RES(ET) button manually until "hla_swd" is shown during openOCD programming. Releasing RES directly at this point will start the normal programming. Holding RES too long will result in a timeout.

Quas7 commented 3 years ago

I had to add a LL_GPIO_Init call into the TIM6_IRQHandler(void) interrupt function to keep SWD programming fully functional. It would be more appropriate to set only a varialbe as a flag and do the GPIO handling in the main loop afterwards, if the timing penalty is too high in this handler.

Quas7 commented 3 years ago

After testing a bit, the sensitivity needs to be rather high (~1.8deg) to not falsely trigger on starting of rotation.

Quas7 commented 3 years ago

Offloaded the pin handling from the interrupt routine to main. Decreased sensitivity to prevent triggering during regular movement. Added noise filter functionality on top: deviation treshold has to be hit multiple times in a row.