teemuatlut / TMC2130Stepper

Arduino library for Trinamic TMC2130 Stepper driver
MIT License
159 stars 50 forks source link

Microstepping LookUpTable #51

Closed frech-tech closed 6 years ago

frech-tech commented 6 years ago

Hey, I'm using a modified MSLUT on my TMC2130 for smoother running choppers. Therefore I had to modify the tmc2130stepper code. Would it be possible to implement this in the further updates? I assume tuning the MSLUT will be more popular since prusa put this to their firmware.

teemuatlut commented 6 years ago

Looks good. Let me know when you're finished and I can merge this in. And then port it to TMCStepper.

I assume tuning the MSLUT will be more popular since prusa put this to their firmware.

Prusa has the advantage that they know exactly the type of motors they use and the parameters they require. Unfortunately upstream Marlin doesn't have this luxury. For getting quiet stepping, you should first look at tuning the spreadCycle chopping frequency with off time and blank time. I've already added a way for users to easily tune the settings according to an example output delivered with the library. Target somewhere above 20-22kHz or just above your personal audible range.

frech-tech commented 6 years ago

Hey, actually I'm done. I'm using the MSLUT options since two weeks. Unfortunately changing the sine to a power(sin,x) doesn't give the best results (according to prusa). Next step is to calibrate the MSLUT table with a laserpointer according to the datasheet. I used some new GCode to change toff, tbl, hstrt and hend. Your way looks more comfortable.

PS: Ignore the SPI.beginTransaction changes. I just tested a SPI SpeedUp.

teemuatlut commented 6 years ago

Could you share some background information on this comment: https://github.com/teemuatlut/TMC2130Stepper/blob/66954eab9cfd627d8ee4a6cedfaf4c50f34a3834/src/source/TMC2130Stepper.cpp#L101 Every now and then we have people reporting communication issues but they tend to be very difficult to diagnose remotely.

frech-tech commented 6 years ago

Hey, that's a good point: So here's the Story: I had issues to get the MAX31685 running (Pt100 Temp Sensor). The solution was, that all SPI devices should run with the same Settings. So first I put the TMC's and MAX3165 on the same Settings: SPI.beginTransaction(SPISettings(16000000/8, MSBFIRST, SPI_MODE3)); (default by TMC library) Afterwards I tested how much I can increase the SCLK SPEED: 16000000/4 = 400kHz was my limit. On 16000000/2 = 800kHz I had communication issues. Yesterday I also put the SDCard on the same SPEED: In my config I use #define SPI_SPEED SPI_SIXTEENTH_SPEED For my DUE having F_CPU =84MHz this translates into: SPI.beginTransaction(SPISettings(84000000/pow(2,1+4), MSBFIRST, SPI_MODE3)); ... so ~2.6 MHz and this is not the limit. My previous Limit was 400kHz! So using the same clock for all devices seems beneficial. So using the sam CLK on all devices allows me to push the frequency much higher.

EDIT: So it would be great if we can use F_CPU and SPI_SPEED directly in the TMC2130Stepper.cpp. Can this be done?

teemuatlut commented 6 years ago

The TMCStepper library does support a setSPISpeed method that aims to provide the flexibility you're looking for.

teemuatlut commented 6 years ago

Btw, this doesn't make sense: 16000000/4 = 400kHz 16 000 000 / 4 is 4 000 000 is 4MHz.

The TMC2130 using the internal clock has a max CLK f of around 4MHz (datasheet 4.3).

frech-tech commented 6 years ago

Ups. In put the value 1 600 000 in my excel calc sheet... So yes... this doen't make sense.