Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #54728

Re: embedded forth

From rickman <gnuarm@gmail.com>
Newsgroups comp.lang.forth
Subject Re: embedded forth
Date 2017-02-08 18:22 -0500
Organization A noiseless patient Spider
Message-ID <o7g948$huf$1@dont-email.me> (permalink)
References (9 earlier) <d126a340-9abd-4145-99f6-2d01915ebe64@googlegroups.com> <o6odhv$qg4$1@dont-email.me> <453ff717-47e2-4b43-87e5-38d3b6d05f89@googlegroups.com> <o6p2ij$fll$1@dont-email.me> <473c8a9d-752c-40c1-ad66-0a6fd368de02@googlegroups.com>

Show all headers | View raw


On 1/31/2017 12:32 PM, Ilya Tarasov wrote:
>
>> You still don't get it.  CORDIC is implemented using a large amount of
>> FPGA fabric.  Sines can be calculated much more efficiently using hard
>> IP multipliers which use a much smaller area on the chip and so cost
>> less in real estate and so chip cost.  They also operate very fast.
>>
>> You seem to be accustomed to designing in the days when multipliers were
>> either not available or to be avoided and so the "no multiplier" aspect
>> of the CORDIC algorithm sounded like a good idea.  We are way beyond
>> that with today's chips.
>
> Not only multipliers are cheap. Words are cheap too :)
> Ok, let me do your job. Let's create a project for calculating sin with 16-bit argument. Divide that argument to 8-bit coarse and fine parts. We will need to implement: sin(a+b) = sin(a)*cos(b) + cos(a)*sin(b);
>
> Assume Kintex-7 Xilinx FPGA. First, we will need to create sin annd cos tables, otherwises synthesizer will optimize out empty tables to simple constants.
>
> Here is a Forth script to generate VHDL initialization lines
> ===================================================================
> {
> " sin_coarse.dat" NEWFILE TO HF-OUT
> 256 0 DO
>   I .F " => " PRINTF
>   I S>F 256.0 F/ PI F* 2.0 F/ FSIN 65535.0 F* F>S
>   .F
>   " ," PRINTF CRF
> LOOP
>
> HF-OUT CLOSE
>
> " cos_coarse.dat" NEWFILE TO HF-OUT
> 256 0 DO
>   I .F " => " PRINTF
>   I S>F 256.0 F/ PI F* 2.0 F/ FCOS 65535.0 F* F>S
>   .F
>   " ," PRINTF CRF
> LOOP
>
> HF-OUT CLOSE
>
> " sin_fine.dat" NEWFILE TO HF-OUT
> 256 0 DO
>   I .F " => " PRINTF
>   I S>F 256.0 F/ PI F* 2.0 F/ 256.0 F/ FSIN 65535.0 F* F>S
>   .F
>   " ," PRINTF CRF
> LOOP
>
> HF-OUT CLOSE
>
> " cos_fine.dat" NEWFILE TO HF-OUT
> 256 0 DO
>   I .F " => " PRINTF
>   I S>F 256.0 F/ PI F* 2.0 F/ 256.0 F/ FCOS 65535.0 F* F>S
>   .F
>   " ," PRINTF CRF
> LOOP
>
> HF-OUT CLOSE
> }
> ===================================================================
>
> VHDL code
>
> ----------------------------------------------------------------------------library IEEE;
> use IEEE.STD_LOGIC_1164.ALL;
> use IEEE.NUMERIC_STD.ALL;
>
> entity top is
>     Port ( clk : in STD_LOGIC;
>            phase : in STD_LOGIC_VECTOR (15 downto 0);
>            result : out STD_LOGIC_VECTOR (31 downto 0));
> end top;
>
> architecture Behavioral of top is
>
> type TTable is array(0 to 255) of integer range 0 to 65535;
>
> signal SinCoarse : Ttable := (
> 0 => 0 ,
> -- skipped lines generated by Forth
> others => 0);
>
> signal SinFine : Ttable := (
> 0 => 0 ,
> -- skipped lines generated by Forth
> others => 0 );
>
> signal CosCoarse : Ttable := (
> 0 => 65535 ,
> -- skipped lines generated by Forth
> others => 0);
>
> signal CosFine : Ttable := (
> 0 => 65535 ,
> -- skipped lines generated by Forth
>  others => 0);
>
> signal sina, sinb, cosa, cosb : integer range 0 to 65535;
> signal sin : integer;
>
> begin
>
> -- sin(a+b) = sin(a)*cos(b) + cos(a)*sin(b);
>
> process(clk)
> begin
>   if rising_edge(clk) then
>     sina <= SinCoarse(to_integer(unsigned(phase(15 downto 8))));
>   end if;
> end process;
>
> process(clk)
> begin
>   if rising_edge(clk) then
>     sinb <= SinFine(to_integer(unsigned(phase(7 downto 0))));
>   end if;
> end process;
>
> process(clk)
> begin
>   if rising_edge(clk) then
>     cosa <= CosCoarse(to_integer(unsigned(phase(15 downto 8))));
>   end if;
> end process;
>
> process(clk)
> begin
>   if rising_edge(clk) then
>     cosb <= CosFine(to_integer(unsigned(phase(7 downto 0))));
>   end if;
> end process;
>
> process(clk)
> begin
>   if rising_edge(clk) then
>     sin <= sina*cosb + cosa*sinb;
>   end if;
> end process;
>
> result <= std_logic_vector(to_unsigned(sin, 32));
>
> end Behavioral;
> =========================================================================
>
> Report Cell Usage:
> +------+--------+------+
> |      |Cell    |Count |
> +------+--------+------+
> |1     |BUFG    |     1|
> |2     |DSP48E1 |     2|
> |3     |LUT2    |     2|
> |4     |LUT3    |     2|
> |5     |LUT4    |     1|
> |6     |LUT5    |    10|
> |7     |LUT6    |   145|
> |8     |MUXF7   |    64|
> |9     |MUXF8   |    32|
> |10    |IBUF    |    17|
> |11    |OBUF    |    16|
> +------+--------+------+
>
> Finally, this project requires two multipliers, and this is clearly
from the source formula. All tables goes to distributed memory, since
they are not so large. LUT are required for this. BRAM usage can be
switched by synthesys options or will be applied automatically when
larger tabel size will required.
>
> I have several questions here.
>
> 1. If you want to go to 32-bit phase, can we simple change MSB of
> angle parts, increase table sizes and keep this code? How many DSP
> blocks will be used in this case? What about memory size? 2. If we
> will go to (a+b+c) approach, are there any hidden traps? Can we
> simple double the number of calculating resources, i.e. assume d =
> a+b, calculate sin(a+b), when calculate finale angle as d + c. How
> many resources will be used in this case?

Somehow I missed this post.  But your code is wrong in that it is 
directly implementing the literal trig equation without taking advantage 
of any of the simplifications.

The actual equation implemented is:

sin(a+b) = sin(a) + cos(a)*(pi/2)*b,

where a and b are msbs and lsbs of the phase word, each half.  The LUT 
is indexed by (a) with each entry having a value for sin(a) and 
(pi/2)*cos(a).  Or call it two tables, both indexed by (a).  While 
sin(a) is of width N, (pi/2)cos(a) is only of width N/2.

The amount of memory should decrease to 3/2 N width and 2^(N/2) depth. 
I don't see memory in your utilization list unless it is the MUXF8 and 
MUXF7 items?  I don't see anything else in your code that would cause 
multiplexers to be used.  Perhaps you should invoke the block RAMs. 
Given the wide nature of the RAM required, there is no reason to use 
distributed memory.  256 x 16 fits nicely in a block RAM.

For this calculation the multiply will only be an 8x8, so one 
multiplier.  Even with a 32 bit sine word it will only use a single 
18x18 bit multiplier.

Regardless, I think you can see even from your data above the savings in 
real estate that will result from using the hard IP of block RAMs and 
multipliers.  That's why they are there.

-- 

Rick C

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

embedded forth Dale Scott <dalescottnet@gmail.com> - 2017-01-21 11:27 -0800
  Re: embedded forth Paul Rubin <no.email@nospam.invalid> - 2017-01-21 11:31 -0800
  Re: embedded forth stephen@mpeforth.com - 2017-01-22 00:52 -0800
  Re: embedded forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-01-22 17:09 +0000
    Re: embedded Forth Dale Scott <dalescottnet@gmail.com> - 2017-01-22 09:43 -0800
      Re: embedded Forth stephen@mpeforth.com - 2017-01-22 12:19 -0800
      Re: embedded Forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-22 21:25 +0100
      Re: embedded Forth john <anon@example.com> - 2017-01-22 21:04 +0000
        Re: embedded Forth "Elizabeth D. Rather" <erather@forth.com> - 2017-01-22 12:30 -1000
        Re: embedded Forth hughaguilar96@gmail.com - 2017-01-22 20:45 -0800
      Re: embedded Forth stephen@mpeforth.com - 2017-01-22 14:08 -0800
        Re: embedded Forth Paul Rubin <no.email@nospam.invalid> - 2017-01-22 14:55 -0800
          Re: embedded Forth Dale Scott <dalescottnet@gmail.com> - 2017-01-22 20:41 -0800
            Re: embedded Forth Paul Rubin <no.email@nospam.invalid> - 2017-01-22 21:19 -0800
      Re: embedded Forth hughaguilar96@gmail.com - 2017-01-22 21:36 -0800
        Re: embedded Forth Dale Scott <dalescottnet@gmail.com> - 2017-01-22 22:09 -0800
          Re: embedded Forth rickman <gnuarm@gmail.com> - 2017-01-23 04:15 -0500
            Re: embedded Forth Dale Scott <dalescottnet@gmail.com> - 2017-01-23 08:41 -0800
              Re: embedded Forth rickman <gnuarm@gmail.com> - 2017-01-23 14:32 -0500
                Re: embedded Forth Dale Scott <dalescottnet@gmail.com> - 2017-01-23 11:53 -0800
                Re: embedded Forth rickman <gnuarm@gmail.com> - 2017-01-23 15:10 -0500
              Re: embedded Forth Paul Rubin <no.email@nospam.invalid> - 2017-01-23 14:34 -0800
                Re: embedded Forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-01-24 03:14 -0600
        Re: embedded Forth rickman <gnuarm@gmail.com> - 2017-01-23 03:43 -0500
          Re: embedded Forth john <anon@example.com> - 2017-01-23 10:32 +0000
          keep secrets (was Re: embedded Forth) "Wolfgang Allinger" <all2001@spambog.com> - 2017-01-23 08:58 -0300
            Re: keep secrets (was Re: embedded Forth) Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2017-01-23 07:47 -0500
              Re: keep secrets (was Re: embedded Forth) "Wolfgang Allinger" <all2001@spambog.com> - 2017-01-23 18:18 -0300
                Re: keep secrets (was Re: embedded Forth) rickman <gnuarm@gmail.com> - 2017-01-23 19:15 -0500
            Re: keep secrets (was Re: embedded Forth) rickman <gnuarm@gmail.com> - 2017-01-23 14:38 -0500
              Re: keep secrets (was Re: embedded Forth) "Wolfgang Allinger" <all2001@spambog.com> - 2017-01-23 18:43 -0300
                Re: keep secrets (was Re: embedded Forth) rickman <gnuarm@gmail.com> - 2017-01-23 19:48 -0500
                Re: keep secrets (was Re: embedded Forth) "Elizabeth D. Rather" <erather@forth.com> - 2017-01-23 16:30 -1000
                Re: keep secrets (was Re: embedded Forth) rickman <gnuarm@gmail.com> - 2017-01-23 22:23 -0500
  Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-22 13:44 -0500
    Re: embedded forth Paul Rubin <no.email@nospam.invalid> - 2017-01-22 13:38 -0800
      Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-23 00:45 -0500
        Re: embedded forth Dale Scott <dalescottnet@gmail.com> - 2017-01-22 22:44 -0800
          Re: embedded forth Paul Rubin <no.email@nospam.invalid> - 2017-01-23 00:48 -0800
          Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-23 03:51 -0500
      Re: embedded forth john <anon@example.com> - 2017-01-23 10:02 +0000
    Re: embedded forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-01-23 09:01 +0000
      Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-23 13:05 +0100
        Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-23 14:40 -0500
          Re: embedded forth Mark Wills <markwills1970@gmail.com> - 2017-01-24 01:12 -0800
          Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-24 14:38 +0100
            Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-24 19:51 -0500
              Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-25 11:34 +0100
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-25 22:13 -0500
                Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-26 11:36 +0100
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-26 14:07 -0500
              Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-26 00:19 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-26 14:15 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-27 13:08 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-27 17:54 -0500
                Re: embedded forth Paul Rubin <no.email@nospam.invalid> - 2017-01-27 15:29 -0800
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-27 16:28 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-27 23:58 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-28 11:58 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-28 15:36 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-28 15:05 -0800
                Re: embedded forth Paul Rubin <no.email@nospam.invalid> - 2017-01-28 15:57 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-28 21:51 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-29 09:53 -0800
                Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-29 19:32 +0100
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-29 11:53 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-30 01:10 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-29 23:11 -0800
                Re: embedded forth Paul Rubin <no.email@nospam.invalid> - 2017-01-29 23:34 -0800
                Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-30 12:42 +0100
                Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-30 12:36 +0100
                Re: embedded forth ctmalan@gmail.com - 2017-01-30 11:02 -0800
                Re: embedded forth Paul Rubin <no.email@nospam.invalid> - 2017-01-30 11:04 -0800
                Re: embedded forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-01-31 04:34 -0600
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-30 12:15 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-30 10:15 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-30 12:20 -0800
                Re: embedded forth Paul Rubin <no.email@nospam.invalid> - 2017-01-30 14:09 -0800
                Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-31 03:04 +0100
                Re: embedded forth Paul Rubin <no.email@nospam.invalid> - 2017-01-30 20:19 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-30 17:10 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-30 14:38 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-30 23:09 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-31 09:32 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-02-08 18:22 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-09 01:46 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-02-09 05:11 -0500
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-02-12 01:30 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-12 10:21 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-02-12 19:37 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-14 13:26 -0800
                Re: embedded forth Gary Bergstrom <forthprgrmr@gmail.com> - 2017-02-14 11:36 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-02-14 18:13 -0500
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-28 21:51 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-29 10:20 -0800
                Re: embedded forth Cecil Bayona <cbayona@cbayona.com> - 2017-01-29 12:38 -0600
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-01-29 11:49 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-02-04 04:22 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-04 17:54 -0800
                Re: embedded forth hughaguilar96@gmail.com - 2017-02-04 20:26 -0800
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-05 07:53 -0800
                Re: embedded forth hughaguilar96@gmail.com - 2017-02-05 11:08 -0800
                Re: embedded forth hughaguilar96@gmail.com - 2017-02-05 11:39 -0800
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-08 06:46 -0800
                Re: embedded forth luser droog <mijoryx@yahoo.com> - 2017-02-13 19:17 -0800
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-15 06:23 -0800
                Re: embedded forth hughaguilar96@gmail.com - 2017-02-15 11:09 -0800
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-15 15:24 -0800
                Re: embedded forth jkn_gg@nicorp.f9.co.uk - 2017-02-16 09:49 -0800
                Re: embedded forth hughaguilar96@gmail.com - 2017-02-17 09:12 -0800
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-17 12:47 -0800
                Re: embedded forth hughaguilar96@gmail.com - 2017-02-17 16:18 -0800
                Re: embedded forth luser droog <mijoryx@yahoo.com> - 2017-02-16 08:43 -0800
                Re: embedded forth Alex <alex@rivadpm.com> - 2017-02-05 20:47 +0000
                Re: embedded forth hughaguilar96@gmail.com - 2017-02-05 13:36 -0800
                Re: embedded forth Alex <alex@rivadpm.com> - 2017-02-05 23:18 +0000
                Re: embedded forth hughaguilar96@gmail.com - 2017-02-05 21:10 -0800
                Re: embedded forth Alex <alex@rivadpm.com> - 2017-02-06 11:12 +0000
                Re: embedded forth hughaguilar96@gmail.com - 2017-02-05 21:15 -0800
                Re: embedded forth hughaguilar96@gmail.com - 2017-02-05 22:45 -0800
                Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-02-06 12:04 +0100
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-08 03:08 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-02-08 06:39 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-08 07:15 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-02-08 15:49 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-09 01:14 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-02-09 05:19 -0500
                Re: embedded forth Ilya Tarasov <ilya74.tarasov@gmail.com> - 2017-02-09 03:48 -0800
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-02-05 16:08 -0500
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-02-07 21:59 -0500
                Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-28 11:10 +0100
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-28 06:15 -0500
                Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-28 19:48 +0100
                Re: embedded forth rickman <gnuarm@gmail.com> - 2017-01-28 14:37 -0500
                Re: embedded forth mhx@iae.nl - 2017-01-28 07:48 -0800
                Re: embedded forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-28 19:53 +0100
                Re: embedded forth mhx@iae.nl - 2017-01-28 15:49 -0800
        Re: embedded forth "Wolfgang Allinger" <all2001@spambog.com> - 2017-01-23 18:46 -0300

csiph-web