TMC5160 with SPI and external common clock

More
04 Mar 2021 10:41 #201012 by petter0007
HI,
I have been using the Trinamic drivers in several micro controller bases systems for years and would like to use them in my LinuxCNC setup as well just becose i think they are lovely:lol: :lol: .

To be specific very spesific i would like to have a Raspberry PI 4 controlling 4 steppers in XYZ axis(double motors on one axis) with TMC5160-BOB modules.

I would like to tie them together with a common clocksource using the CLK IN leg
and run them on 10MHz or 16MHz syncronized, If possible by PWM from the RPI, if not by an external clock source.
I also want to use their encoder feedback option so that it will function more like a servomotor than a stepper and never miss a step, (but this is not really important yet).

It has been a long time since i first took a look at building my own router and back then STEP and DIR was the obvious choice back then.
Now i'm not that shure i want to use STEP and DIR and not SPI to run my motors.
MESA boards look fine but in my mind are an unnecessary hardware layer when all we need is synchronized Tranamic controllers(And wont deliver the performance built in to the Trinamic steppers anyway).
I know i sound like a salespersion for Trinamic but i'm not...i just think they are far better at what they do than most others around.

I want to try to run mine over SPI instead of STEP/DIR....and...
I find it hard to believe that no one has done this before since it's an so obvious choice in my head,
I was half believing it would be a drop-down choice in the HAL config gui for LinuxCNC.
Instead i have googled and googled with no real findings on how to do it.

Can anyone help me to get started.
I am a hardware designer that is fairly good at understanding software, but no programmer by living.
I look for anyone out there with some experience that can end up beeing a guide for others on how to do it.
Has anyone done a full trinamic featured stepper connection over SPI to LinuxCNC from RPI4?
In my head all we need is stepper modules like the TMC5160-BOB and a stable clock to be able to run at speeds up to 16MHz...
I might be wrong and that's the reason for no one has done it, but i suspect i'm right.

Please Log in or Create an account to join the conversation.

More
04 Mar 2021 14:03 #201022 by andypugh
I would start by looking at the hm2_rpspi code to get a feel for what realtime access to the SPI looks like inside a HAL module.
github.com/LinuxCNC/linuxcnc/blob/master...hostmot2/hm2_rpspi.c
It's reasonably well commented.
You might be able to use most of it as-is.

When driving a Mesa card the driver assigns pointers to two functions {hostmot2_structure}.llio_read and {}.llio_write.
In the spi driver these are the functions hm2_rpspi_read_spi0() and hm2_rpspi_write_spi0()
If you pull out all the bits of the hm2_rpspi driver which fault-out when no Mesa card is found then your own driver should be able to call those functions instead.
You will see that, for example, the read function
static int hm2_rpspi_read_spi0(hm2_lowlevel_io_t *llio, uint32_t addr, void *buffer, int size)
Takes a pointer to a hm2_llio struct, but then completely ignores it, an address to write to, a pointer to a source buffer and a transfer size. I think you just need to assemble the data for the drives and use that function.

In fact, you could #include hostmot2.h in your own driver and use that low level driver directly. That saves you any code-maintenance worries.

Then you just need to create some HAL pins for the position inputs.

The rest is left as an exercise :-)
The following user(s) said Thank You: petter0007

Please Log in or Create an account to join the conversation.

Time to create page: 0.072 seconds
Powered by Kunena Forum