As a comparison, and to demonstrate what I hope to achieve with the Raspberry Pi, I also tested using a Windows host.
My Windows computer does not have any GPIO pins for measuring timing on a scope, so I used one of the Pico's GPIO pins instead by adding the following to the `ep1_out_handler`:In Windows I used the following C# code, which still utilizes the same libUSB API.As can be seen in this video, the timing on Windows is much more steady. That is what I'd like to achieve with the Raspberry Pi.
My Windows computer does not have any GPIO pins for measuring timing on a scope, so I used one of the Pico's GPIO pins instead by adding the following to the `ep1_out_handler`:
Code:
gpio_put(TIMING_PIN, 1);busy_wait_us(50);gpio_put(TIMING_PIN, 0);
Code:
using System.Diagnostics;using LibUsbDotNet;using LibUsbDotNet.Main;class Program{ static UsbDevice MyUsbDevice; static void Main(string[] args) { // Elevate this process's priority Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; // Find and open the USB device UsbDeviceFinder finder = new UsbDeviceFinder(0x0000, 0x0001); MyUsbDevice = UsbDevice.OpenUsbDevice(finder); if (MyUsbDevice == null) { Console.WriteLine("Device not found."); return; } // Open the USB device for communication MyUsbDevice.Open(); UsbEndpointWriter writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01); // Start communication loop Stopwatch sw = new(); byte[] writeData = [0]; while (true) { // Reset the clock to keep this loop repeating on regular intervals sw.Restart(); // Send a usb transfer to the Pico ErrorCode ecWrite = writer.Write(writeData, 1000, out int bytesWritten); if (ecWrite != ErrorCode.None) { Console.WriteLine("Failed to write to device: " + ecWrite); break; } // avoid sleeping as it is too imprecise while (sw.Elapsed.TotalMicroseconds < 500) { } } // Release interface and close the USB device MyUsbDevice.Close(); UsbDevice.Exit(); }}
Statistics: Posted by JinShil — Thu Apr 25, 2024 5:28 am