Teensy 4.1 + LinuxCNC

More
04 Sep 2020 19:28 - 05 Sep 2020 00:28 #180741 by jakap
Replied by jakap on topic Teensy 4.1 + LinuxCNC
Thank you rmu and PCW for your inputs. Over the last few days, I wrote simple C++ routines to communicate with teensy using custom message packets and a system call interface (sys/socket.h). Currently, I am testing it with 12 byte messages sent from PC ((three 32bit integers) and 8 bytes return messages (two 32 bit encoder values) sent from Teensy. Running 10000 such communication packets is completed within 1250ms, meaning that on average, sending one command and receiving the answer takes 125 us.
So far I am pretty satisfied with the result. Next, I am looking forward to modify the code into a hal component, integrate it with linuxcnc and test it on the machine.

Edit:I added a third encoder, so now the 12 byte messages are sent in both ways. After I stripped the code on the microcontroller side and removed all serial communication between the udp transmit/receive cycles, one send/receive cycle is <80us only!
Last edit: 05 Sep 2020 00:28 by jakap.

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

More
04 Sep 2020 21:08 #180758 by BeagleBrainz
Replied by BeagleBrainz on topic Teensy 4.1 + LinuxCNC
Liking the project and will keep watching. Good work and a tip o the hat to you.

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

More
04 Sep 2020 21:42 #180766 by jakap
Replied by jakap on topic Teensy 4.1 + LinuxCNC
I would like to organize the hal component into four functions:

int init_sendsocket();
int init_recvsocket();
int send_data();
int recv_data();

Is there a way to divide the hal component into two parts: one, that is executed only once at the startup (for init functions) and second, that is running in servo loop? I reckon there is no need to initialize a new socket in each iteration of the servo loop...

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

More
05 Sep 2020 02:57 #180775 by rodw
Replied by rodw on topic Teensy 4.1 + LinuxCNC
yes, you can do setup and cleanup functions. there is an example in the docs.
linuxcnc.org/docs/devel/html/hal/comp.html#_out8

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

More
05 Sep 2020 07:57 #180789 by rmu
Replied by rmu on topic Teensy 4.1 + LinuxCNC

I would like to organize the hal component into four functions:
I reckon there is no need to initialize a new socket in each iteration of the servo loop...


That would definitely take too long. Just initialize a socket once. That is the part you could take some inspiration from the hm2_eth mesa driver code.

BTW, the size of the packet shouldn't matter that much, you will find that with ethernet the difference between 12 byte payload and 100 byte payload will be negligible.

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

More
16 Sep 2020 15:40 #182446 by Roiki
Replied by Roiki on topic Teensy 4.1 + LinuxCNC
Are you working with the teensys hardware quadrature decoders?(Or what do you mean by encoder?) I'm hooking up a teensy to ethetcat and trying to use them that way but this also seems interesting and opens all kinds of possibilities.

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

More
19 Sep 2020 19:03 #182776 by blazini36
Replied by blazini36 on topic Teensy 4.1 + LinuxCNC
Is this project on git or anything? This is something that I wanted to look into with a teensy 4.0/4.1 but was thinking more along the lines of SPI since the 4.0 doesn't have ethernet.

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

More
22 Sep 2020 19:28 - 23 Sep 2020 08:05 #183336 by jakap
Replied by jakap on topic Teensy 4.1 + LinuxCNC
Hello,

I have more or less finished the alpha version of the firmware and software.

So far, I have supported the following features on Teensy4.1:
- UDP communication with custom message protocol
- 4 stepgen generators (for steppers) with fixed / controllable pulse widths and frequencies up to several MHz, or alternatively
- 4 PWMs with fixed and controllable frequency and 12 bit PWM resolutions
- 4 H/W high speed quadrature encoders ( A/B )
- 14 GPIO: 7 inputs, 7 outputs (hardcoded)

Since signal generation and encoder readout are done in hardware, Teensy does not have much to do and is mostly waiting in the main loop for a new command to come - plenty of room for future expansions!

I wrote realtime HAL component for communication with Teensy from LinuxCNC. Run from LinuxCNC, I am able to achieve 60us roundtrips with 40byte payload. I have written a simple HAL example for a simple servo loop, and have tested the servo loop on a single axis kinematic stage, equipped with high-precision encoder and a DC motor run by a small H-bridge driver.
I did some serious testing at 1ms servo-threads over several hours with no problems whatsoever.
I was also able to run servo-thread with 150us (6600Hz) without any problems, but I haven't spent much time testing it and don't know how stable it really is at this speeds.

Once I reach the beta-state of the software my goal is to publish the code on GitHub, if there would be enough interest.
There is of course still a lot of stuff left behind. Currently, I am fixing some bugs and adding support for the following:
- 8 channel 16-bit DAC (SPI)
- 4 channel 12-bit internal Teensy's ADCs with DMA.
- counting stepgen cycles for position feedback

In the future, I would like to implement synchronized/distributed clock using PTP (IEEE1588) as supported by Teensy4.1.
Since I am by no means an expert on the topic, any help or advice on PTP and its implementation would be much appreciated.

Regards,
Jaka
Last edit: 23 Sep 2020 08:05 by jakap.

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

More
22 Sep 2020 21:04 #183346 by Roiki
Replied by Roiki on topic Teensy 4.1 + LinuxCNC
As a side note. The teensy only supports 4 encoders with A+B. Due to internal crossbaring it drops to 3 for ABZ encoders. It also works on specific pins.
Read more here: github.com/mjs513/Teensy-4.x-Quad-Encoder-Library

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

More
23 Sep 2020 07:44 #183424 by jakap
Replied by jakap on topic Teensy 4.1 + LinuxCNC
Good point. I only implemented AB encoders, as I donĀ“t need index signals.

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

Time to create page: 0.113 seconds
Powered by Kunena Forum