Trinamic TMC4671 - use "canned" angle offset to save initialization time? - Page 1
Forum section: electronics / general

author: TinkeringSteve
author_rank: Frequent Contributor
timestamp: August 19, 2022, 05:55:50 pm
content: Since that chip is programmed via SPI, I guess this is the best sub forum...?So, I have that motor driver IC, using it with a BLDC with digital hall sensor output and a ABN rotary encoder, and current measurement resistors in 2 of the phases.Produced initialization C code with their IDE.It basically works.(The motor has a little free-floating load, i.e. a weight not connected to anything, on its axis + bearing on other side, too)On initialization, the motor moves a little in one direction, then swings a little back and forth like a damped pendulum, and when it rests, the init phase is over and the code switches the IC to velocity mode and the motor spins nicely.This init phase is done in open loop mode.The velocity mode uses ABN encoder as a source for the angle.Now, I'm not quite a motor expert.I did read their datasheet, which has a nice intro at the beginning, explaining how FOC works.So, this initial pendulum movement would be the forcing of the rotor to a position of a known electrical angle phi_e, so that the offset between electrical angle and encoder are known, such that the encoder can be used for precise FOC - did I get that right?I wonder now: if I have a system which is mounted in a stable, repeatable way - can I let the thing determine phi_e once, store it, and for all next powerups, use the stored value instead of wasting time doing the initial pendulum thing every time?The datasheethttps://www.mouser.de/datasheet/2/256/TMC4671-LA_datasheet_Rev2.00-1880648.pdfhas a section that kinda sounds like it:4.6.10.3 Encoder Initialization by N Pulse DetectionAfter determination of a correct offset, the value can be used again after power cycle. The encoder’s Npulse can be used as reference for this. For starters the user can drive the motor in open-loop mode or byusing digital Hall sensor signals. After passing the encoder’s N pulse, the ABN encoder is initialized andcan be used for operation.Alas, they don't tell exactly how to do that (or I don't see it).I experimented with letting the thing do the initial open loop initialization, then, query the register ABN_DECODER_PHI_E_PHI_M_OFFSET, store the value, and at next powerup, instead of doing the pendulum open loop thing, I wrote the stored value back to the register.Then it spun to crazy speeds - I realized I forgot the part about letting the ABN go over the index position in open loop first, i.e. not just straight jumping into the code that sets up velocity mode using ABN.But... am I on the right track generally? How I would know when that ABN went over the index, so that I can stop open-loop-driving, I haven't found yet.If I got it right, I would end up with the device starting, moving in open loop until the ABN indexed, switch to ABN-based velocity mode, and the whole thing would look pretty seamless, as if the motor just started spinning after powerup (maybe a bit slowly) - well that would be ideal. (later, I may also use position mode)Would it work like that?Has anyone done this before and/or knows this?

author: thm_w
author_rank: Super Contributor
timestamp: August 19, 2022, 10:58:34 pm
content: Yes, since the encoder is rigidly held to the shaft that should work.QuoteThe encoder will have an index output pin, labeled N or I. You'd interrupt on that.If there is no obvious way for the chip to do this in their documentation, what they might be saying in the quote is that YOU have to initialize the ABN encoder registers and set appropriate calibration values determined previously.edit: I didn't realize this thing runs its own code? Maybe there are some libraries or demos you can search through.

author: TinkeringSteve
author_rank: Frequent Contributor
timestamp: August 20, 2022, 08:48:33 am
content: Quote from: thm_w on August 19, 2022, 10:58:34 pmOoook, all encoder pins are connected to the encoder inputs on the TMC chip, nothing else, on my custom board. Dang.It would seem that the makers of the chip would think "if our IC takes the encoder outputs, we should provide some info about that indexing".Maybe they did, I haven't seen it in the datasheet yet.QuoteIDK how this would run own code. They have some sort of own language, I saw that somewhere in the IDE some time, but I haven't done anything with that.I exported C code, which interfaces with their C library.It is a pretty thin library that does every basic functionality, but what I'd like, well there is nothing prepared in the init routines to support that, so I need to do it by hand.

author: thm_w
author_rank: Super Contributor
timestamp: August 22, 2022, 10:50:10 pm
content: OK for some reason I thought the C code it produced was for the TMC IC and not your micro.If you have your micro then yeah, you can bodge another wire to that index pin, or constantly poll the IC to read the index pin status and see when it changes."N of ABN_RAW" maybe.