wxs
Posts: 31
Joined: Wed Dec 04, 2019 9:01 am

bit banging at high frequency

Fri Jan 10, 2020 12:58 pm

Hi, I've been playing with the PRi 4 for a couple of days and am still frustrated.
My goal is to 'make' 4 signals like the following at about 10-50MHz:
data to send.png
data to send.png (28.86 KiB) Viewed 728 times
I have an Arduino but it can't do such high frequency, then I bought the RPi 4. Started as a beginner, I installed Raspbian. I used the GPIO and SPI functions in wiringPi and bcm2835 libraries. But either the frequency is not enough, or the signal is very ugly and erratic. Then I read that Raspbian is not a real time OS and can't deal with accurate timing issues. Then I switched to bare metal. I followed some old RPi bare metal tutorials (can't find any tutorial specially made for RPi 4) but haven't made anything happen so far.
Can anyone point me a direction on how to generate those signals at frequency around 20 MHz? Thanks so much.

User avatar
procount
Posts: 2309
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: bit banging at high frequency

Fri Jan 10, 2020 1:17 pm

Search for posts by Joan on this forum.
Also look at their pigpio library http://abyz.me.uk/rpi/pigpio/index.html
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

wxs
Posts: 31
Joined: Wed Dec 04, 2019 9:01 am

Re: bit banging at high frequency

Fri Jan 10, 2020 1:38 pm

procount wrote: Search for posts by Joan on this forum.
Also look at their pigpio library http://abyz.me.uk/rpi/pigpio/index.html
I also noticed this page. But since it mentioned 'every few us', are you sure it can meet my 10-50 MHz requirement?

User avatar
procount
Posts: 2309
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: bit banging at high frequency

Fri Jan 10, 2020 1:45 pm

No idea I'm afraid, which is why I pointed you at someone who might. I'm sure the max switching speeds of GPIO has been mentioned in their previous posts. Fancy DMA techniques have been used for the fastest frequencies.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

Heater
Posts: 16832
Joined: Tue Jul 17, 2012 3:02 pm

Re: bit banging at high frequency

Fri Jan 10, 2020 3:13 pm

You can bit bang GPIO at up to 50MHZ on a P3B

In this thread you can find discussion about it and a description of how I achieved it. https://www.raspberrypi.org/forums/view ... 5#p1252388

The trick is to isolate one of your cores from having work scheduled on it by the Linux kernel, using the 'isolspu' parameter of it's boot command line.

Then run your code on that isolated core by using 'taskset'

It's like having your own private 'bare metal' core whilst the other three cores get on with Linuxy things and don't bother you.

Except, there was some interrupt that hit even the isolated core every 5ms or so and caused a few micro seconds of jitter. But given you are generating a clock to go with your data signal that is likely not a problem, every thing should be synchronized at the receiving end.

Somebody here did find a sneaky way to write to some ARM register or interrupt table to kill off that interrupt. Sadly I don't recall who it was or which thread that was in. Hope they turn up again here.

You might want to take steps to ensure your CPU does not get throttled whilst you do this.
Memory in C++ is a leaky abstraction .

rhildinger
Posts: 39
Joined: Thu Jun 09, 2016 6:07 pm

Re: bit banging at high frequency

Fri Jan 10, 2020 3:29 pm

Take a look at the following libraries for examples of using DMA to perform accurate high-speed bitbanging:

https://github.com/jgarff/rpi_ws281x

https://github.com/hzeller/rpi-rgb-led-matrix

-Robert

Return to “General discussion”