EmbDev.net

Forum: FPGA, VHDL & Verilog New to VHDL Need help with this assignment


Author: James Y. (Company: Student) (eejyang)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Hey guys!
I'm a new university freshman and new to VHDL.
So recently I've given this sort of assignment,
in class,and some clue codes from professor,but nothing really helps.
The picture in the attachment is the subject I been trying to code.
Here's some partial clue codes provided by professor,of course with some 
errors need to correct...
Thanks guys for any thoughts and guide me through this.

edit : errors are :
signal ck1hz : STD_LOGIC_VECTOR (24); <-The expression can not be 
converted to type STD_LOGIC_VECTOR.
Q <= Q + '1'; <- + can not have such operands in this context.
ck1hz <= Q(24) => Y when DIR = '1' else DIR = '0'; <- Undefined symbol 
'ck1hz'. & parse error, unexpected ROW, expecting SEMICOLON
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;


entity demoW2 is
    Port ( CLK : in  STD_LOGIC;
           RST : in  STD_LOGIC;
           DIR : in  STD_LOGIC;
           C : out  STD_LOGIC_VECTOR (6 downto 0));
end demoW2;

architecture Behavioral of demoW2 is
signal Q : STD_LOGIC_VECTOR (24 downto 0);
signal Y : STD_LOGIC_VECTOR (3 downto 0);
signal ck1hz : STD_LOGIC_VECTOR (24);
begin
process (CLK,Q)
begin
if CLK' event and CLK = '1'
  then 
      Q <= Q + '1';
  end if;
end process;
ck1hz <= Q(24) => Y when DIR = '1' else DIR = '0';
with Y select 
  C <= "1000000" when "0000", 
      "1111001" when "0001", 
      "0100100" when "0010", 
      "0110000" when "0011", 
      "0011001" when "0100", 
      "0010010" when "0101", 
      "0000010" when "0110",
      "1111000" when "0111",      
      "0000000" when "1000",
      "0011000" when "1001",
      "0001000" when "1010",
      "0000011" when "1011",
      "1000110" when "1100",
      "0100001" when "1101",
      "0000110" when "1110",
      "0001110" when others;

end Behavioral;

: Edited by User
Author: Lothar M. (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
James Y. wrote:
> Here's some partial clue codes provided by professor,of course with some
> errors need to correct...
What are your suggestions? What error messages does the toolchain 
report?  What's wrong in the erronous lines?


James Y. wrote:
> Thanks guys for any thoughts and guide me through this.
It's your homework, when you give some reasonable suggestions then maybe 
someone will help you further on.

Author: James Y. (Company: Student) (eejyang)
Posted on:

Rate this post
0 useful
not useful
Lothar M. wrote:
> James Y. wrote:
>> Here's some partial clue codes provided by professor,of course with some
>> errors need to correct...
> What are your suggestions? What error messages does the toolchain
> report?  What's wrong in the erronous lines?
> signal ck1hz : STD_LOGIC_VECTOR (24); <-The expression can not be converted to 
type STD_LOGIC_VECTOR.
Q <= Q + '1'; <- + can not have such operands in this context.
ck1hz <= Q(24) => Y when DIR = '1' else DIR = '0'; <- Undefined symbol 
'ck1hz'. & parse error, unexpected ROW, expecting SEMICOLON
>
> James Y. wrote:
>> Thanks guys for any thoughts and guide me through this.
> It's your homework, when you give some reasonable suggestions then maybe
> someone will help you further on.
I know I supposed to work out my own homework,but I'm honestly out of 
ideas,and the clues aren't helping...I can't see the points where I need 
to do.

Author: Lothar M. (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
James Y. wrote:
> I can't see the points where I need to do.
You have a sketch of a hardware you have to describe with VHDL.
So
1. describe the prescaler for the 1.5 Hz and
2. the 4 bit counter, connect
3. them together and
4. to the 7 segment decoder.

: Edited by Moderator
Author: C. A. Rotwang (Guest)
Posted on:

Rate this post
0 useful
not useful
Check with the internet how to code an incrementing counter in VHDL. 
It's important to use the approbiate types und libraries and not to be 
confused with the differences beetwenn 1 and '1'.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- .....
signal Q : STD_LOGIC_VECTOR (24 downto 0);
--....
      Q <= Q + '1';
--...

Compare the quoted lines with the lines there: 
http://www.asic-world.com/examples/vhdl/simple_counter.html

Author: Lothar M. (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
James Y. wrote:
> signal ck1hz : STD_LOGIC_VECTOR (24);
Looks like this should be an alias of Q(24)

> process (CLK,Q)
There are too much sichals in the sensitivity list here.
clk is enough.

> Undefined symbol 'ck1hz'.
Define it in a proper way. And define its name in a way that it matches 
the real world: you do not want a 1 Hz clock, you want 1.5 Hz.
BTW: are 1.562 Hz close enough to the 1.5 Hz you want? Then maybe you 
can head on with your "2^24 prescaler clock divider", although you 
should not use such a "clock-divider-prescaler" design strategy in 
modern FPGAs.

Do you have to use as much as you can from that very old fashioned 
example? Or can you write code thats more up to date? Code with clock 
enables and so on?


All in all my attempt would look like this:
...
use IEEE.NUMERIC_STD.ALL;
...
signal prescaler : integer range 0 to 33333332 := 0; -- 1.5Hz = 50000000/1.5
signal index     : integer range 0 to 15 := 0;
signal clockenable1hz5: STD_LOGIC;

begin

-- prescaler
process begin
   wait until rising_edge(clk);  -- only 1 clock throughout the whole design!
   if prescaler < 33333332 then 
      clockenable1hz5 <= '0';    
      prescaler       <= prescaler+1;
   else
      clockenable1hz5 <= '1';     -- generate a clock enable with 1.5 Hz
      prescaler       <= 0;
   end if;
end process;

-- index counter
process begin
   wait until rising_edge(clk);  -- only 1 clock throughout the whole design!
   if clockenable1hz5 = '1' then
      if index < 15 then  index <= index+1;
      else                index <= 0;
      end if;
   end if;
end process;

-- the decoder
with index select 
   C <= "1000000" when 0, 
        "1111001" when 1,
        "0100100" when 2, 
        "0110000" when 3, 
        "0011001" when 4, 
        "0010010" when 5, 
        ....
        "0000110" when 14,
        "0001110" when 15;
All in all that coding style is far more read- and understandable for 
humans. And thats the style I'm teaching my students...

: Edited by Moderator
Author: James Y. (Company: Student) (eejyang)
Posted on:

Rate this post
0 useful
not useful
Lothar M. wrote:
> Do you have to use as much as you can from that very old fashioned
> example? Or can you write code thats more up to date? Code with clock
> enables and so on?
I can't be sure,but I don't think there is any limitation.

: Edited by User
Author: James Y. (Company: Student) (eejyang)
Posted on:

Rate this post
0 useful
not useful
C. A. Rotwang wrote:
> Check with the internet how to code an incrementing counter in VHDL.
> It's important to use the approbiate types und libraries and not to be
> confused with the differences beetwenn 1 and '1'.
Ok,I'll try to google more information about it as possible.

Author: James Y. (Company: Student) (eejyang)
Posted on:

Rate this post
0 useful
not useful
Lothar M. wrote:
> All in all that coding style is far more read- and understandable for
> humans. And thats the style I'm teaching my students...
And may I ask,can you recommend a book for me to study VHDL?(I'm using 
Xilinx ISE)

: Edited by User

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.