Coder Social home page Coder Social logo

terjeio / trinamic-library Goto Github PK

View Code? Open in Web Editor NEW
48.0 3.0 20.0 103 KB

Plain C library for Trinamic TMC2130 stepper drivers

License: Other

C 99.73% CMake 0.27%
trinamic tmc2130 library stepper-motor-driver tmc2209 tmc5160 trinamic-library

trinamic-library's Introduction

Trinamic driver library

21-08-10: Refactored to support ganged motors, some API changes.

Supports TMC2130, TMC2209 and TMC5160 drivers.

Written in plain C, processor agnostic. Processor specific low-level communications layer has to be added by user.

This library is used by some grblHAL drivers and examples of low-level communications layers and a higher level configuration/reporting layer implementation can be found there.

A SPI <> I2C bridge implemented on a TI MSP430G2553 processor that may be used for systems with limited IO capabilities.


2021-08-10

trinamic-library's People

Contributors

noahwilliamsson avatar terjeio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

trinamic-library's Issues

TMC2209 - $14x setting is being affected by VREF pot

I am trying out grblHAL on an STM32F4Discovery board with a BigTreeTech TMC2209 v1.3 driver board. I noticed a significant discrepancy in the current measurements I was getting from running motors when I used it in pure STEP/DIR mode with no UART control and setting current via potentiometer, versus using UART control and setting the current digitally using $140. The UART control mode was reading something like half of the current of the STEP/DIR mode.

After some investigating I discovered that changing the potentiometer still affects the current even when using $14x to configure the current. In other words, I actually played with the potentiometer while the motor was running and could see the current changing.

Looking at the source code, I can see in tmc2209.c in TMC2209_Init:

// Use default settings (from OTP) for these:
//  driver->gconf.reg.I_scale_analog = 1;
//  driver->gconf.reg.internal_Rsense = 0;
//  driver->gconf.reg.en_spreadcycle = 0;
//  driver->gconf.reg.multistep_filt = 1;

I admit it is not ultra clear in the datasheet, but it appears that when I_SCALE_ANALOG is left at 1, then the value on the TMC2209 VREF pin still modulates the actual output current, whereas if you set it to zero it uses an internal reference. After doing some digging it seems like Marlin explicitly sets this setting to 0 as does the Arduino TMC2209 library ( https://github.com/janelia-arduino/TMC2209 ).

I changed my TMC2209_Init setup to set I_SCALE_ANALOG to 0 in TMC2209_Init and it then made my readings insensitive to changing the VREF potentiometer, and gave me values about what I expect.

I do have some concerns that the straightforward fix could drastically change the current values people with existing machines will get after a firmware update. If they set their current limits based off of motor datasheets, I would guess they would mostly be OK, but if it they set this value empirically based on how hot the motors got or something it could be a nasty surprise.

Library uses unaligned access to structure members

This results in inability to execute the code with PIC32MZ series.
Removing the #pragma pack() directives enables the execution, however, the results are incorrect.
Reordering all the members in all structures may be required to avoid the need to use packing

Traces of merge conflicts in the code

The current master branch has a ton of traces from merge conflicts checked in.

% egrep '<<<<<<<|=======|>>>>>>>' * |head -n20
common.c:<<<<<<< HEAD
common.c:=======
common.c:>>>>>>> b687cda0f174c908cc9421b42af9b442f3fa6112
common.h:<<<<<<< HEAD
common.h:=======
common.h:>>>>>>> b687cda0f174c908cc9421b42af9b442f3fa6112
common.h:<<<<<<< HEAD
common.h:=======
common.h:>>>>>>> b687cda0f174c908cc9421b42af9b442f3fa6112
common.h:<<<<<<< HEAD
common.h:=======
common.h:>>>>>>> b687cda0f174c908cc9421b42af9b442f3fa6112
tmc2130.c:<<<<<<< HEAD
tmc2130.c:=======
tmc2130.c:>>>>>>> b687cda0f174c908cc9421b42af9b442f3fa6112
tmc2130.c:<<<<<<< HEAD
tmc2130.c:=======
tmc2130.c:>>>>>>> b687cda0f174c908cc9421b42af9b442f3fa6112
tmc2130.c:<<<<<<< HEAD
tmc2130.c:=======

This makes it impossible to compile the code.

% gcc common.c 
In file included from common.c:39:
./common.h:44:1: error: version control conflict marker in file
<<<<<<< HEAD
^
./common.h:54:1: error: version control conflict marker in file
<<<<<<< HEAD
^
./common.h:139:1: error: version control conflict marker in file
<<<<<<< HEAD
^
common.c:78:1: error: version control conflict marker in file
<<<<<<< HEAD
^
4 errors generated.

At least some of them were introduced with commit cdc4fda.

Possible bug. Stallguard not functioning without pwm_autoscale on tmc2209

Stallguard does not function properly (or as expected?) on a 2209 driver. The following line is relevant, and setting autoscale to true recovers proper stallguard behaviour on my system:

driver->pwmconf.reg.pwm_autoscale = false;

I'm not sure how this works in other driver modules, but I can't find any reference on stallguard requiring disabling pwm_autoscaling. Just tcoolthrs < tstep < tpwmthres

Found a typo in trinamic.c

Hi
I was struggling to get the XYZA to show up in ioSender as the screenshot shows
I know I could just set it via the interface but I will be offering the firmware as a free download to the CNC foam-cutting community and I'm sure I would get some users who would struggle. So the aim is to make all the defaults in the eeprom.
image
and after a few hours of head scratching and searching the code I found at line 424 in trinamic.c
trinamic.driver_enable.z = TMC_A_ENABLE;
changed it to
trinamic.driver_enable.a = TMC_A_ENABLE;
image
All working fine now, thanks for a great library. This going to power a 4-axis foam cutter using the SKR Pico. I had great success with the grbl Mega 5X but it is time to move on now. Should have some videos out soon.
Keith

TMC2209 support for ganged axis

Currently the library is unaware of ganged X/Y/Z axis so tinkering with them and changing their settings is not possible. I think that due to this the initialization fails too due to the amount of successful writes that happen which are checked here

grblhal expects axis X2/Y2/Z2 but this lib sets up A, B and C

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.