Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20705 Discussions

Using MOD doubles number of LEs in VHDL

Altera_Forum
Honored Contributor II
910 Views

hi 

 

I'm just learning to programme an Altera MaxII development board having an EPM1270F256C5 CPLD. 

 

I was able to send VGA signals to my monitor based on a 3-horizontal-stripes VHDL programme I found on the internet. I amended this to produce vertical stripes of width 32 pixels, on a 640x480 screen. I'm using just one colour for each red,green and blue. I did this in the 'case' statement by specifying the stripe pixel count for eaach stripe. The number of LE's used was 70. 

 

architecture main of stripes_gen is 

begin  

process(vidon,hc)  

variable hc_offset : std_logic_vector (9 downto 0):=(others=>'0');  

variable div32 : std_logic_vector (9 downto 0):=(others=>'0');  

variable int32 : integer;  

variable rgb_s : integer; 

 

begin  

rgb<="000"; -- defined as an input std_logic_vector (2 downto 0), used for colours "red green blue" 

 

hc_offset:=hc - 144; -- hc is the total horizontal pixel counter 0<=hc<800, hc_offset is the display horizontal counter, 0<=hc_offset<640  

div32:="00000" & hc_offset(9 downto 5); -- divides hc_offset by 32 , 0<=div32<20, each one 32 pixels wide 

int32:=conv_integer(div32); -- converts div32 to an integer , range from 0->19 

 

if vidon = '1' then -- vidon=1 when hc is greater or equal to 144  

case int32 is 

when 0|3|6|9|12|15|18 => 

rgb(2)<='1'; 

when 1|4|7|10|13|16|19 => 

rgb(1)<='1'; 

when 2|5|8|11|14|17 => 

rgb(0)<='1'; 

when others => 

rgb<="111"; 

end case; 

end if; 

.. 

.. 

 

I wanted to make the code more 'efficient' by using MOD to create the 3 colours, without having to specify each stripe's starting pixel value, as above. The code below works, but the number of LEs used has shot up from 70 to 149, and I get lots of .tdf files generated, which I didn't before, such as lpm_divide_jql.tdf, sign_div_unsign_1nh.tdf, alt_u_div_tne.tdf and 7 variations on add_sub_e7c(f7c,g7c,h7c,h7c,i7c,m7c and u7c).tdf 

The slightly changed MOD code is :- 

.. 

.. 

hc_offset:=hc - 144;  

div32:="00000" & hc_offset(9 downto 5); -- divides hc_offset by 32 to get a stripe 32 pixels wide 

int32:=conv_integer(div32); -- converts div32 to an integer for easier dividing 

rgb_s:=int32 mod 3 ; -- integer, gives either 0,1 or 2 

 

if vidon = '1' then  

case rgb_s is 

when 0 => 

rgb(2)<='1'; 

when 1 => 

rgb(1)<='1'; 

when 2 => 

rgb(0)<='1'; 

when others => 

rgb<="111"; 

end case; 

end if; 

 

I thought this MOD code would have less overhead than the other, but it seems to be the opposite. What am I doing wrong. 

 

regards
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
219 Views

mod(3) is division by 3 to get remainder and so requires more logic. 

in the first case you are avoiding division
0 Kudos
Reply