tommag / TMC5160_Arduino

Arduino library for Trinamic TMC5160 stepper motor driver
MIT License
69 stars 24 forks source link

new version v1.1.0 causing some problems over spi #25

Open imBunyip opened 1 year ago

imBunyip commented 1 year ago

hey, seems the new update is causing some problems, using the simple back and forth example. https://github.com/tommag/TMC5160_Arduino/blob/master/examples/TMC5160_SPI/TMC5160_SPI.ino

the motor moves from 0 to 200 sometimes and sometimes doesnt. there is also allot bad data being recieved from get pos and get speed so forth, example output from serial print.

current position : 125.43   current speed : 272.93
current position : 150.35   current speed : 222.91
current position : 170.22   current speed : 172.42
current position : 185.04   current speed : -6000000.00
current position : 194.80   current speed : 71.74
current position : 199.52   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : -8388608.00  current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 0.00 current speed : -6000000.00
current position : 200.00   current speed : 0.00
current position : 100.00   current speed : 0.00
current position : 100.00   current speed : -6000000.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 50.00    current speed : 0.00
current position : -8388608.00  current speed : -6000000.00
current position : 200.00   current speed : 0.00
current position : 2097152.00   current speed : 0.00
current position : -8388608.00  current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 4194304.00   current speed : -22.65
current position : 194.79   current speed : -72.19
current position : 39.13    current speed : -122.45
current position : 0.00 current speed : 0.00
current position : 18.78    current speed : -222.98
current position : -8388608.00  current speed : -273.25
current position : -8388608.00  current speed : -308.73
current position : 66.89    current speed : 23304.21
current position : 1.36 current speed : -208.25
current position : 12.50    current speed : -158.00
current position : 11.64    current speed : -107.76
current position : 3.32 current speed : -6000000.00
current position : 0.06 current speed : -6000000.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : -6000000.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : -8388608.00  current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : -8388608.00  current speed : 0.00
current position : -8388608.00  current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : -8388608.00  current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 2097152.00   current speed : 0.00
current position : 0.00 current speed : -6000000.00
current position : -8388608.00  current speed : 0.00
current position : 0.00 current speed : 0.00
current position : -8388608.00  current speed : 3000000.00
current position : 3.75 current speed : 86.62
current position : 18.74    current speed : 136.89
current position : 12.38    current speed : 187.18
current position : 56.38    current speed : -6000000.00
current position : 82.79    current speed : 17.98
current position : -8388608.00  current speed : 0.00
current position : 140.37   current speed : 244.05
current position : 1048576.00   current speed : 193.81
current position : 179.36   current speed : 143.57

example output from old library working correctly with the exact same setup.

current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.48 current speed : 22.05
current position : 5.21 current speed : 72.32
current position : 15.00    current speed : 122.60
current position : 29.84    current speed : 172.87
current position : 49.73    current speed : 223.13
current position : 74.69    current speed : 273.40
current position : 104.59   current speed : 308.60
current position : 133.11   current speed : 258.34
current position : 156.59   current speed : 208.10
current position : 175.00   current speed : 157.85
current position : 188.37   current speed : 107.61
current position : 196.68   current speed : 57.37
current position : 199.94   current speed : 7.23
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 200.00   current speed : 0.00
current position : 198.68   current speed : -36.49
current position : 192.50   current speed : -86.78
current position : 181.26   current speed : -137.04
current position : 164.96   current speed : -187.30
current position : 143.62   current speed : -237.57
current position : 117.21   current speed : -287.83
current position : 86.70    current speed : -294.15
current position : 59.63    current speed : -243.90
current position : 37.61    current speed : -193.66
current position : 20.64    current speed : -143.42
current position : 8.73 current speed : -93.17
current position : 1.87 current speed : -42.95
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.00
current position : 0.00 current speed : 0.64
current position : 2.58 current speed : 50.91
current position : 10.21    current speed : 101.19
current position : 22.90    current speed : 151.46
current position : 40.64    current speed : 201.72
current position : 63.44    current speed : 251.99
current position : 91.30    current speed : 302.27
current position : 121.58   current speed : 279.75
current position : 147.21   current speed : 229.49
current position : 167.78   current speed : 179.24
current position : 183.29   current speed : 129.00
current position : 193.76   current speed : 78.76
current position : 199.17   current speed : 28.55

testing on the esp32-s3-devkitc-1 or m5stack atom-s3.

tommag commented 1 year ago

Thanks for reporting ! I have tested the lib on an ESP32 with this update so I'm confident that it should work. One of the modifications was to increase the default SPI clock frequency to 4MHz, maybe if your SPI layout is subject to interferences (long wires, etc) this could cause the issue ? Can you try with a lower SPI frequency ? (default was 1MHz).

imBunyip commented 1 year ago

yea thanks,was going to do some testing tonight, changing to 1mhz fixes the issue thanks (_), the distance of the spi lines is only 1cm or so, if its not long lines on the spi what else could it be.

tommag commented 1 year ago

Strange indeed if you have very short SPI wires. I'll add a comment in the SPI example to instruct people to lower the SPI freq if needed.