LinuxCNC-RIO - RealtimeIO for LinuxCNC based on FPGA (ICE40 / ECP5)

More
31 Jan 2024 19:06 #292095 by meister
M10x1 on my cnc conversion (HG125 C0 lathe) with 3D printed parts



works :)
The following user(s) said Thank You: phillc54

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

More
31 Jan 2024 19:22 #292097 by meister
Attachments:

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

More
07 Feb 2024 20:52 #292783 by meister
The following user(s) said Thank You: tommylight, MaxEkb77

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

More
17 Mar 2024 19:48 #296150 by meister
Extreme - Jogging

Joypad + Encoder + MPG + Buttons at the same time (build by the hal-generator)

The following user(s) said Thank You: Aciera

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

More
19 May 2024 09:55 #300957 by Zayoo
I have a raspberry pi5 and this is the code of how I started the SPI communication of the RPI5 - TangNano9K. (Not yet machine tested)

OS:  In /boot/broadcom/config.txt check is SPI is enabled (reboot if not)

# uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on

In /dev/
Check do you have listed spidev0.0, should be!

In RIO.h define:

#define TRANSPORT_SPI5


In RIO C add lines:

#ifdef TRANSPORT_SPI5
#include <linux/spi/spidev.h>
#include <sys/ioctl.h>
#endif


/***********************************************************************
*                STRUCTURES AND GLOBAL VARIABLES                       *
************************************************************************/

#ifdef TRANSPORT_SPI5
int spifd;
static uint8_t mode = SPI_MODE_0;
static uint8_t bits = 8;
static uint32_t speed = 1500000;
#endif




/***********************************************************************
*                       INIT AND EXIT CODE                             *
************************************************************************/

#ifdef TRANSPORT_SPI5
    rtapi_print("Info: Initialize SPI5 connection\n");
    spifd = open("/dev/spidev0.0", O_RDWR);
    if (spifd < 0) {
        rtapi_print_msg(RTAPI_MSG_ERR,"Failed to open SPI device\n");
        return -1;
    }

    // Set SPI mode
    if (ioctl(spifd, SPI_IOC_WR_MODE, &mode) == -1) {
        rtapi_print_msg(RTAPI_MSG_ERR,"Failed to set SPI mode\n");
        close(spifd);
        return -1;
    }

    // Set bits per word
    if (ioctl(spifd, SPI_IOC_WR_BITS_PER_WORD, &bits) == -1) {
        rtapi_print_msg(RTAPI_MSG_ERR,"Failed to set bits per word\n");
        close(spifd);
        return -1;
    }

    // Set max speed
    if (ioctl(spifd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) == -1) {
        rtapi_print_msg(RTAPI_MSG_ERR,"Failed to set max speed\n");
        close(spifd);
        return -1;
    }
#endif

//Edit rtapi_app_exit function, add close(spifd)

void rtapi_app_exit(void)
{
    close(spifd);
    hal_exit(comp_id);
}




//In fuction void rio_transfer()  near end of it add: 

#ifdef TRANSPORT_SPI5

    struct spi_ioc_transfer tr = {
        //.tx_buf = (uint64_t)tx_buf,
        //.rx_buf = (uint64_t)rx_buf,
        .tx_buf = (uint64_t)txData.txBuffer,
        .rx_buf = (uint64_t)rxData.rxBuffer, 
        .len = SPIBUFSIZE,
        .speed_hz = speed,
        .delay_usecs = 0,
        .bits_per_word = bits,
    };

    // Perform SPI transfer
    if (ioctl(spifd, SPI_IOC_MESSAGE(1), &tr) == -1) {
rtapi_print_msg(RTAPI_MSG_ERR,"Failed to perform SPI transfer\n");
        //close(spifd);
        //return -1;
    }

#endif


//Save and do hallcompile...
 
The following user(s) said Thank You: meister

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

More
21 May 2024 10:18 #301069 by meister
Thanks,
I think the problem with RPI5 and SPI was that it is not realtime-capable. But I don't know exactly, I don't have an RPI5 yet.

I'm looking forward to the first machine tests
The following user(s) said Thank You: Zayoo

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

More
21 May 2024 10:22 #301070 by cornholio
It's not so much it isn't "realtime capable" but since the SPI interface was moved to the RP1 chip, none of the former Rpi 4 code works.
Going thru /dev/spi doesn't appear to be fast enough, at least for the mesa cards.
The following user(s) said Thank You: meister

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

More
21 May 2024 17:38 #301094 by Zayoo
Here is demo video: 

Since implementing this solution, I haven't experienced any communication issues. I can't say the same for previous tests where I used a laptop and a W5500 chip.

While researching the topic, I came across cases where people use spidev kernel libraries to manage several displays. They even mention 200Mhz clocks what is hard to believe. Official RPi pages stays on maximum 50Mhz. So speed should not be issue and "realtime capable" out of my understanding. :) 

I'm working on 1.5Mhz. I'm still learning and even don't know what is acceptable speeds. from orginal BMC library i extract some data that speed should be around 1.5Mhz.   
The following user(s) said Thank You: tommylight, meister, besriworld

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

More
24 May 2024 19:01 #301349 by meister
The following user(s) said Thank You: tommylight, Zayoo

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

More
27 May 2024 18:58 #301610 by meister
what the hell is wrong with me :)

www.youtube.com/shorts/tQvyrIP7aVc

but i have a serious problem with the kinematic, i need only 4joints, but the melfa stuff have 6 :(
don't know how to setup a 4dof robot the right way :(

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

Time to create page: 0.253 seconds
Powered by Kunena Forum