Drivers for I2S realtime input/output

More
21 Jul 2016 11:48 #77766 by lhartmann
A little while ago I found a way to use the I2S sound output present on orange pi (raspberry pi too, I believe) to drive a 32bit parallel output at 192kHz, and I successfully used it to drive a few steppers. Since then I have been looking into getting real-time inputs too, I believe they are feasible but have not tested yet.



Code for the output: github.com/lhartmann/orangepi-i2s-steppers
PCB for the output: github.com/lhartmann/Shift-out-32-HC595
PCB for the input (untested, known bad latch logic): github.com/lhartmann/Shift-in-32-HC165
Previous discussion on reprap forums: forums.reprap.org/read.php?2,685993

Then I was looking at 3D printer firmwares but they are mostly based polling code, and therefore not nice for porting to a Linux OS on the *Pi. Then I remembered LinuxCNC. :-) Here I have 2 questions:

1 - How easy would it be to write output drivers for I2S output? All I need is to put future output values in a uin32_t[] buffer so I can feed it to I2S (through ALSA).

2 - How would LinuxCNC handle the transport delay between output and input (audio buffers)? I2S input is real-time (as in predictable and constant rate), but delayed several miliseconds from the output.

It should be possible calculate the exact delay between I2S output and input just by feeding back one "sync" bit. Unfortunately due to the transport delay homing moves would have to be slow, or the endstops would need to forgive some movement after triggered.

P.S.: I am totally LinuxCNC newbie, so please forgive me if I say something stupid. :-)

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

More
21 Jul 2016 12:20 #77768 by jepler
Please read wiki.linuxcnc.org/cgi-bin/wiki.pl?HardwareDesign first :)

A design where step&direction signals are generated in Linux but don't reach the hardware for several ms will clearly not work for operations like threading, where the axis positions have to closely track the spindle position. It also constrains what you can do for homing and probably the accuracy of homing.

On the other hand, if you don't care about stuff like that, then it depends on what style of realtime you're doing (e.g., RTAI vs preempt-rt); if preempt-rt, it depends on whether the ALSA APIs can be called without introducing realtime delays.

Your driver would have to run on LinuxCNC's schedule (1kHz by default), take commanded position in, return a *FAKE* (not shifted by many milliseconds) position feedback, and then take care of preparing the step waveform and piping it over this I2S bus with ALSA API calls.
The following user(s) said Thank You: lhartmann

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

More
21 Jul 2016 12:51 - 21 Jul 2016 12:54 #77770 by lhartmann
Yup, topic "2.2 No Buffering"... That's exactly what I am doing, using ALSA buffers.

I was not considering threading, none of my machines can do that. I agree, it is probably impossible to get feedback fast enough for that on my hardware.

While the feedback is delayed from the outputs, I can also feedback the step pulses. :-) Detection will be delayed so the machine will move a little past the trigger position, but I should be able to retain full accuracy (1 step) while homing to an endstop. Z homing with a touch plate, on the other hand, would not be so forgiving.

Thanks for the reply, I'll see what I can do.
Last edit: 21 Jul 2016 12:54 by lhartmann.

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

Time to create page: 0.084 seconds
Powered by Kunena Forum