Beware of cheap underperforming clones

As of 2023 there are many badly performing clones on the market. V2/3GHz NanoVNA uses parts like ADF4350 and AD8342 which are costly and clones have been cutting costs by using salvaged or reject parts.

See official store and look for V2 Plus4/V2 Plus4 Pro versions only to avoid getting a bad clone. We have stopped selling V2.2 versions since October 2020, so all V2 hardware that are not Plus or Plus4 are not made by us and we can not guarantee performance.

NanoVNA V2 Forum

Note: this page is a mirror of https://groups.io/g/NanoVNAV2.
Click here to join and see most recent posts.

Question about writing to FIFO in Matlab


shlomi.bouscher 2023/12/14 08:33

Hi all,

I'm currently writing a Matlab function library to interact with the NanoVNA V2 Plus4. I'm trying to implement the function which reads data from the FIFO. During tests I noticed that the frequency bytes I read from the FIFO are highly inconsistent. Sometimes I see proper sequences like 24,25,26,... and sometimes it's just a constant number for all measurements.
Is there a decent guide with examples for interacting with the FIFO?

Thanks in advance!

nanov2support 2023/12/14 23:13

Hi, the FIFO is constantly being filled, so if it isn't read for a while it will become full and data will be dropped while the sweep continues. It is necessary to clear the FIFO before performing a measurement.

Here is our example program for communicating with the VNA:
https://gist.github.com/nanovna/af6d7c93221a5673451e6f6e64f210e7
The relevant code is in the readValues function here:
https://gist.github.com/nanovna/af6d7c93221a5673451e6f6e64f210e7#file-read_points-py-L65

Thanks

shlomi.bouscher 2023/12/16 08:22

Hi!

Thank you very much for the quick response. I indeed clear the FIFO by writing to it. Just to make sure I'm not wrong, let me understand the command pipeline:

1. Set up the 4 sweep parameters (start freq/freq step/step num/points per measurement). This inserts the nanoVNA into usb mode and a continuous measurement loop commences (say I want 1000 unique frequency points, the device will start filling up the buffer with measurements which I can sort by the frequency index inside each measurement).

2. I can read at most 255 datapoints per read command from the FIFO. So I perform a loop in which I clear the FIFO by sending a write command with some value (say 0x00), then send the read command to the FIFO (which includes the number of points I wish to measure, then read the output (number of points X 32 bytes), then repeat the loop until all 1000 unique points have been read. I assume that I need to manually confirm all frequency indices have been accounted for (for 1000 points this means 0-999).

My problem is that while this seems to work for the first run of the nanoVNA, I get three weird problems:

1. The number of frequency indices is unrelated to the number of points I asked for. Say for 10 points I get indices of 46,47,48,... instead of 0,1,2,3,... all the way up to 10.

2. At some point the output is stuck on a specific frequency index, say 30 or 44 (both of which are out of range for this specific test measurements).

3. After a while I do get different frequency indices but some are repeating themselves.

I went over the python codes you provided, but I see nothing considerably different from my Matlab code.
Is my reasoning regarding how to read the FIFO correct or am I missing something?

nanov2support 2023/12/16 23:08

Hi, this is correct. If the frequency indices returned are out of range, most likely the correct sweepPoints was not configured, make sure there isn't another program writing to the serial port. You can try writing 8 bytes of value 0 to the serial port first to reset the command state.
If the frequency index is not continuous, it is possible that the FIFO is filling up because the data isn't being read fast enough, or valuesPerFrequency is not 1 ( https://nanorfe.com/nanovna-v2-user-manual.html#__RefHeading___Toc2543_2953165397 ). If valuesPerFrequency is greater than 1, you will see repeated frequency indices, for example for valuesPerFrequency of 3, the returned index will be 0, 0, 0, 1, 1, 1, 2, 2, 2 and so on.
Thanks

shlomi.bouscher 2023/12/17 08:56

Thank you very much for the reply. I was curious regarding how "valuesPerFrequency" work. I also found a bug in my code where the different variables weren't cast to the suitable datatypes, and now everything runs fine.

Thank you very much for the assistance!

To reply to this topic, join https://groups.io/g/NanoVNAV2

View this thread on groups.io