Sujet : Re: Grounded grid VHF front-end
De : antispam (at) *nospam* fricas.org (Waldek Hebisch)
Groupes : sci.electronics.designDate : 18. Nov 2024, 22:22:26
Autres entêtes
Organisation : To protect and to server
Message-ID : <vhgb6g$2j4be$2@paganini.bofh.team>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
john larkin <
JL@gct.com> wrote:
On Sun, 17 Nov 2024 14:50:58 -0000 (UTC), antispam@fricas.org (Waldek
Hebisch) wrote:
USB can do milliseconds, ethernet hundreds of microseconds, small
micros can do much better. Theoretically with a micro connected via USB
one can synchronize clocks of the micro and PC with microsecond
accuracy, I plan to try this but do not know how this will work.
We're designing some products around the RP2040, the Pi Pico
processor.
Turns out that in some cases, it's easier to bit-bang an SPI interface
than program an SPI engine. To fine-tune timings in 7 ns increments,
we can use no-op instructions.
I wonder what's a safe c-language NOP single-clock operation that no
compiler is smart enough to optimize out and doesn't add a bunch of
loads and stores.
As JM wrote, with gcc (and I think clang too) you can use imline asm
like:
__asm__ volatile ("nop");
gcc is supposed to keep it. There is potential trouble with reordering,
in general gcc can move statements to a different place when it thinks
that the affect is the same. 'volatile' is supposed to prevent such
movement (gcc still may move "normal" code around it, but access to
GPIO should be volatile too and gcc will not reorder volatile
operations).
We're experimenting with that sort of timing on an oscilloscope. The
GCC or whatever code timing tools don't work in this case.
Oscilloscope is good to see what happens at the pins. For observing
internal time one can read systick register (I did not check RP2040,
but I think it can be configured to change every clock).
Something like
gpio_put(FIRST_GPIO, 1);
gpio_put(FIRST_GPIO, 0);
gpio_put(FIRST_GPIO, 1);
gpio_put(FIRST_GPIO, 0);
Makes the port pin change every 7 ns. That's astounding. So maybe a
dummy port bang is my no-op. Just repeat what we just set it to.
I you want accuracy up to a single clock, then your code is brittle.
RP2040 is a complex device and can do many things simultaneously.
There is large potential for undesired interference. Basically,
if you have code in a single bank of the RAM and your RP2040 is
doing nothing else than bit-banging, then you are resonably safe.
However, if SPI peripherial can do what you need, then IMO it
is better solution, as SPI is dedicated hardware block which can
operate without interference in parallel with other blocks.
-- Waldek Hebisch