Moving Average on Red Pitaya example

dedicated to the FPGA topics for all Red Pitaya programmers
TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Moving Average on Red Pitaya example

Post by TheGeri » Mon Aug 05, 2024 9:21 am

Good morning,

I am working on the Red Pitaya FPGA Moving Average example (from: [https://redpitaya-knowledge-base.readth ... arage.html#][/url]). I have followed all the tutorial and when I read monitor 0x40600050 I get FEEDBACC.

Just when I open the oscilloscope from the web browser I get 0x00000000 from this command. After doing the monitor 0x40600008 3 I read 0s from the 0x40600008 as well. So, I am not being able to make the example work by connecting OUT1 to IN2. What do you think is going on? How can I fix it?

I would appreciate it if someone could help me with this. Thank you all in advance! :)

TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Re: Moving Average on Red Pitaya example

Post by TheGeri » Tue Aug 06, 2024 8:57 am

I tried this example using OS version 2.00 and 1.04 and neither version worked (I also tried to change the path of the fpga.conf (ScopeGenPro) in case this was related...) The example provided here [url][/https://lniv.fe.uni-lj.si/redpitaya/redpitaya-proc.htm] did work but only when using version 1.04.

User avatar
redpitaya
Site Admin
Posts: 967
Joined: Wed Mar 26, 2014 7:04 pm

Re: Moving Average on Red Pitaya example

Post by redpitaya » Wed Aug 21, 2024 2:23 pm

Hello TheGeri,

Thank you for reporting this and sorry for the late reply.
I will test it out on the 2.00 OS and make sure to update the tutorial. I'll let you know when it is fixed.

Modifying the fpga.conf only works on 1.04 OS or older, the same goes for the example at https://lniv.fe.uni-lj.si/redpitaya/redpitaya-proc.htm. As the way the FPGA is loaded has changed in 2.00, where you have to replace the existing fpga.bit.bin file with your own FPGA version (and make a back-up of the original).

Since the programmed FPGA register is working fine (you get the FEEDBACK), then it is most likely a mistake in the FPGA logic controlling the fast analog inputs/outputs.

TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Re: Moving Average on Red Pitaya example

Post by TheGeri » Thu Aug 22, 2024 8:05 am

Good morning,

Don't worry and thank you very much, I will be very grateful if you can let me know when the example is updated.

On the other hand, I would like to use the oscilloscope's web browser adding my own functionalities. For example, clicking a button (that is now implemented) and calling my own functionality (instead of the one designed, for example). Or adding another button on the screen itself... Do you have a tutorial or could you give me clues or advice on how to continue with this path?

Thank you in advance,

Kind regards :D

User avatar
redpitaya
Site Admin
Posts: 967
Joined: Wed Mar 26, 2014 7:04 pm

Re: Moving Average on Red Pitaya example

Post by redpitaya » Fri Aug 23, 2024 12:45 pm

Good day to you too,

We have a short tutorial on web applications here:
https://redpitaya.readthedocs.io/en/lat ... plications

You can then use the examples to get you started and then modify the existing oscilloscope application code that is available here:
https://github.com/RedPitaya/RedPitaya/ ... copegenpro

Sincerly :)

TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Re: Moving Average on Red Pitaya example

Post by TheGeri » Tue Aug 27, 2024 12:57 pm

Good afternoon,

Perfect, I'll look at it. Thank you very much!

Kind regards,

TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Re: Moving Average on Red Pitaya example

Post by TheGeri » Wed Aug 28, 2024 12:48 pm

Good afternoon,

I followed the first example: https://redpitaya.readthedocs.io/en/lat ... eparations using Latest Stable version (2.04-35). When compiling I get the following:

Code: Select all

root@rp-f06276:/opt/redpitaya/www/apps/myFirstApp# make INSTALL_DIR=/opt/redpitaya
make -C src
make[1]: Entering directory '/opt/redpitaya/www/apps/myFirstApp/src'.
g++ -c -Wall -fPIC -Os -s -std=c++11 -I/opt/redpitaya/include -I/opt/redpitaya/include/api2 -I/opt/redpitaya/include/apiApp -I/opt/redpitaya/rp_sdk -I/opt/redpitaya/rp_sdk/libjson main.cpp -o main.o
g++ main.o -o ../controllerhf.so -shared -Wall -fPIC -Os -s -L/opt/redpitaya/lib -L/opt/redpitaya/rp_sdk -Wl,--whole-archive,--no-as-needed -lcryptopp -lrpapp -lrp -lrp_sdk -Wl,--no-whole-archive
make[1]: Abandoning directory '/opt/redpitaya/www/apps/myFirstApp/src'.
But I don't see the application in the web browser. Do you know what could be the reason?

Thanks in advance again,

Kind regards,

TheGeri
Posts: 32
Joined: Wed Sep 13, 2023 12:46 pm

Re: Moving Average on Red Pitaya example

Post by TheGeri » Wed Aug 28, 2024 1:33 pm

Update: If instead of using the template file I used the one of the following examples, it worked correctly!

User avatar
redpitaya
Site Admin
Posts: 967
Joined: Wed Mar 26, 2014 7:04 pm

Re: Moving Average on Red Pitaya example

Post by redpitaya » Fri Oct 04, 2024 1:50 pm

Hello The Geri,

Sorry for the late reply. I found the mistake after a lot of checking.

The moving average.vhd in the current form causes and overflow in the "sum" variable.

Since the sum has 14 bits and each of the registers also has 14 bits this results in an overflow, which causes the error. I have no idea why this works on 1.04 OS - it should not.

The solution is to resize the sum to 16 bits (sum of three binary numbers of 14 bits can have a maximum of 16 bits).

Here is the new code:

Code: Select all

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.all;

entity moving_average is
    Port ( data_i   : in std_logic_vector (13 downto 0);    -- unfiltered adc data in
           clk_i    : in std_logic;                         -- bus clock
           rstn_i   : in std_logic;                         -- bus reset - active low
           tag_i    : in unsigned (1 downto 0);             -- filter value
           data_o   : out std_logic_vector (13 downto 0));  -- filtered adc data out
end moving_average;

architecture Behavioral of moving_average is
    type mem_t is array (0 to 2) of signed (13 downto 0);

    signal regs: mem_t := (others =>(others => '0')); -- buffer for moving average algorithm
    signal sum: signed(15 downto 0);
begin

regs(0) <= signed(data_i);

process (clk_i)
begin
    if(rising_edge(clk_i)) then
        if (rstn_i = '0') then
            sum <= (others => '0');
        else
            case tag_i is
                -- regs
                when "01" => data_o <= std_logic_vector(resize(sum, 14));                           -- leave the same

                -- regs / 2
                when "10" => data_o <= std_logic_vector(resize(shift_right(sum, 1), 14));           -- divide by 2

                -- (regs * 85) / 256
                when "11" => data_o <= std_logic_vector(resize(shift_right(sum * 85, 8), 14));      -- mulitply by 0.33203

                -- (regs * 85) / 256
                when others => data_o <= std_logic_vector(resize(shift_right(sum * 85, 8), 14));    -- mulitply by 0.33203
            end case;

            if (tag_i(1) = '1') then
                regs(1) <= regs(0);
            else
                regs(1) <= (others => '0');
            end if;

            if (tag_i(0) = '1') then
                regs(2) <= regs(1);
            else
                regs(2) <= (others => '0');
            end if;

            sum <= resize(regs(0), 16) + resize(regs(1), 16) + resize(regs(2), 16);
        end if;
    end if;
end process;

end Behavioral;

User avatar
redpitaya
Site Admin
Posts: 967
Joined: Wed Mar 26, 2014 7:04 pm

Re: Moving Average on Red Pitaya example

Post by redpitaya » Fri Oct 04, 2024 1:51 pm

I will update the tutorial on the web with the new version. Thank you for pointing this out.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 1 guest