ODroid as raplacement for Raspberry Pi

More
16 Feb 2023 11:08 #264613 by rodw
I think we can do better than that.
Not sure how yet, but I think you could write a timer interrupt routine to do hardware stepping and control the step frequency... for speed.
I have done this on an arduino to drive a stepper and the ISR (interrupt service routine was only a few lines of code.
But I cheated and just turned the pins on and off as a square wave. It worked, but they ran hot!

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

More
16 Feb 2023 11:24 #264614 by rodw
Hmm ChatGPT came up with this

Certainly! Here is an example of a timer interrupt service routine for an ARM Cortex-A CPU that toggles a GPIO pin at a frequency controlled by a variable that can be changed in real-time:
#include <stdint.h>
#include "arm_gic.h" // Include the appropriate GIC (Generic Interrupt Controller) file for your specific ARM CPU

#define GPIO_PIN_NUM 10 // The number of the GPIO pin to toggle
#define TIMER_INTERRUPT_ID 30 // The ID of the timer interrupt to use
#define CLOCK_FREQ_MHZ 100 // The frequency of the clock in MHz

volatile uint32_t tick_count = 0;
volatile uint32_t frequency_mhz = 1; // The frequency to toggle the GPIO pin in MHz

void timer_interrupt_handler(void) {
    tick_count++; // Increment tick count on every timer interrupt
    // Toggle the GPIO pin based on the frequency setting
    if (tick_count % (CLOCK_FREQ_MHZ / frequency_mhz) == 0) {
        toggle_gpio_pin(GPIO_PIN_NUM);
    }
    // Clear the interrupt flag in the GIC
    arm_gic_clear_interrupt(TIMER_INTERRUPT_ID);
}

void set_frequency_mhz(uint32_t freq_mhz) {
    frequency_mhz = freq_mhz;
}

int main(void) {
    // Initialize system clock and peripherals
    // Note: the exact initialization code will depend on your specific ARM CPU and board
    
    // Configure the GPIO pin as an output
    configure_gpio_pin_output(GPIO_PIN_NUM);
    
    // Configure the timer interrupt
    arm_gic_configure_interrupt(TIMER_INTERRUPT_ID, ARM_GIC_PRIORITY_MEDIUM, timer_interrupt_handler);
    // Enable the timer interrupt
    arm_gic_enable_interrupt(TIMER_INTERRUPT_ID);
    
    while (1) {
        // Your main program code here
        // Call set_frequency_mhz to change the frequency setting in real-time
    }
}
 
In this example, we assume that there are functions toggle_gpio_pin and configure_gpio_pin_output available to toggle the GPIO pin and configure it as an output. The frequency_mhz variable is used to set the frequency of the GPIO pin toggle operation. The timer_interrupt_handler function is called on every timer interrupt and toggles the GPIO pin at the specified frequency. The set_frequency_mhz function can be called from the main program to change the frequency setting in real-time. Note that we assume that CLOCK_FREQ_MHZ is a constant representing the frequency of the clock in MHz.

Note that this is just an example and may need to be modified to work with the specific ARM CPU and peripherals you are using. The exact initialization code and the implementation of the toggle_gpio_pin and configure_gpio_pin_output functions will depend on your specific ARM CPU and board.

Not bad...

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

More
16 Feb 2023 11:31 #264615 by rodw
And I asked it to include a step length which defines the length of a pulse that runs at a specific frequency,
so now I juat need it to scale it by steps per mm/inch so we can set the speed in linuxcnc hal based on the feed rate.
Scary!
But yes hardware stepping should be possible.

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

More
16 Feb 2023 11:42 #264616 by rodw
hmm.
This is now a framework for a driver
Warning: Spoiler!

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

More
16 Feb 2023 11:59 #264617 by rodw
Phew!
we reformatted the code to use a PREEMPT_RT thread!
Not bad so I saved it in drive
docs.google.com/document/d/1OjpibGOAtL11...qpY/edit?usp=sharing

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

More
16 Feb 2023 22:59 #264666 by rodw
So it seems my Netgear router at home has flakey support for NTP in its DHCP service. I changed the router settings to use pool.ntp.org.
It seems Netgear has issues with NTP...
On a bug report I filed,  johnag has pushed a fix to use Debian's NTP server if one is not provided by DHCP. Not sure how long it takes to get to his downloads...

He covers how to extend  the partion in his FAQ's  Tips and Tricks
sd-card-images.johang.se/tips-and-tricks.html
Also covers the missing Dialog error I experienced there too.
 

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

More
19 Feb 2023 12:52 #264804 by rodw
So I went back to Armbian.
I was able to build an Armbian image  from scratch. Using their current branch (kernel 6.1), Bookworm would boot from the eMMC card if it was first booted from pettit boot on flash memory.

But we had a mismatch with the PREEMPT_RT patch and it failed to build so I went to their edge branch which gave me Kernel  6.2 rc3 which worked but only boots from an SD card. But I pressed on and modified the build process to apply the Preempt_rt patch from kernel org (also 6.2 rc3) and output deb files for linux-image-rt and linux-headers. These were copied to the SD card and installed using dpkg -i
After a reboot sucess! We had PREEMPT_RT!

I installed linuxcnc from the debian repos and had failure! The menu opened, but sims would not open and latency test stayed on 0
Out of time tonight but next step is to build linuxcnc from source and see what happens!

If I have a win with linuxcnc, I'll document the process. I have had a lot of guidance from one of the Armbian guys to get this far... 
The following user(s) said Thank You: CarterKraft

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

More
20 Feb 2023 22:00 #264909 by alangibson
So after a solid week of poking around, I've got tobetter's 5.10 realtime kernel running on their Ubuntu 22.04 image. With 7 glxgears running, the latency histogram reports a steady 14 us latency. With stress-ng running a one CPU hog on each of 4 isolated CPUs, latency histogram reports a steady 20 us latency. Not bad!

Here's a rough script for manually executing if you want to try it out:

github.com/alangibson/linuxcnc-realtime

> we reformatted the code to use a PREEMPT_RT thread!

That's awesome. I think you set a record for lowest time from concept to implementation. I'd be very interested to see what numbers you get with the above image. Is LinuxCNC just doing software stepping in a while loop now or something?
The following user(s) said Thank You: Bari

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

More
20 Feb 2023 22:31 #264912 by Bari
The real test for latency has been starting Firefox and then playing a youtube. If the latency stays low after 10-15 minutes it should stay low for just about anything.

Glxgears and stress-ng can actually have low latency results after several minutes of testing that immediately gets annihilated by starting FF and youtubes.

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

More
20 Feb 2023 23:35 #264916 by rodw
Awesome work. My PREEMPT_RT build was a failure. Everything looks right but something goes awry with threading. Do you have an image you can share somewhere?  I can give you write access to my Google Drive if you don't have space or bandwidth.

I can't see anywhere where you get the kernel patches in your script. Has Tobetter's image already got it in there?
If we can migrate the process to Armbian's build system, the process will be  a lot easier.
You have given me a few clues to check on.

Bari, Away form the linuxcnc project, cyclictest is the latency tool that was written by the RT kernel team. I just found out about it and its inclded in the rt-tests package in Debian. When I get there, I wat to play with it too. Just does not have pretty graphics. I see Allan runs it in his scripts.

Allan, It would be good to see the output from cyclictest as it speaks  a language other RT guys understand.

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

Time to create page: 0.146 seconds
Powered by Kunena Forum