EmbDev.net

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


von James Y. (Company: Student) (eejyang)


Attached files:

Rate this post
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
1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
4
5
entity demoW2 is
6
    Port ( CLK : in  STD_LOGIC;
7
           RST : in  STD_LOGIC;
8
           DIR : in  STD_LOGIC;
9
           C : out  STD_LOGIC_VECTOR (6 downto 0));
10
end demoW2;
11
12
architecture Behavioral of demoW2 is
13
signal Q : STD_LOGIC_VECTOR (24 downto 0);
14
signal Y : STD_LOGIC_VECTOR (3 downto 0);
15
signal ck1hz : STD_LOGIC_VECTOR (24);
16
begin
17
process (CLK,Q)
18
begin
19
if CLK' event and CLK = '1'
20
  then 
21
      Q <= Q + '1';
22
  end if;
23
end process;
24
ck1hz <= Q(24) => Y when DIR = '1' else DIR = '0';
25
with Y select 
26
  C <= "1000000" when "0000", 
27
      "1111001" when "0001", 
28
      "0100100" when "0010", 
29
      "0110000" when "0011", 
30
      "0011001" when "0100", 
31
      "0010010" when "0101", 
32
      "0000010" when "0110",
33
      "1111000" when "0111",      
34
      "0000000" when "1000",
35
      "0011000" when "1001",
36
      "0001000" when "1010",
37
      "0000011" when "1011",
38
      "1000110" when "1100",
39
      "0100001" when "1101",
40
      "0000110" when "1110",
41
      "0001110" when others;
42
43
end Behavioral;

: Edited by User
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
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.

von James Y. (Company: Student) (eejyang)


Rate this post
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.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
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
von C. A. Rotwang (Guest)


Rate this post
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'.
1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
-- .....
4
signal Q : STD_LOGIC_VECTOR (24 downto 0);
5
--....
6
      Q <= Q + '1';
7
--...

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

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
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:
1
...
2
use IEEE.NUMERIC_STD.ALL;
3
...
4
signal prescaler : integer range 0 to 33333332 := 0; -- 1.5Hz = 50000000/1.5
5
signal index     : integer range 0 to 15 := 0;
6
signal clockenable1hz5: STD_LOGIC;
7
8
begin
9
10
-- prescaler
11
process begin
12
   wait until rising_edge(clk);  -- only 1 clock throughout the whole design!
13
   if prescaler < 33333332 then 
14
      clockenable1hz5 <= '0';    
15
      prescaler       <= prescaler+1;
16
   else
17
      clockenable1hz5 <= '1';     -- generate a clock enable with 1.5 Hz
18
      prescaler       <= 0;
19
   end if;
20
end process;
21
22
-- index counter
23
process begin
24
   wait until rising_edge(clk);  -- only 1 clock throughout the whole design!
25
   if clockenable1hz5 = '1' then
26
      if index < 15 then  index <= index+1;
27
      else                index <= 0;
28
      end if;
29
   end if;
30
end process;
31
32
-- the decoder
33
with index select 
34
   C <= "1000000" when 0, 
35
        "1111001" when 1,
36
        "0100100" when 2, 
37
        "0110000" when 3, 
38
        "0011001" when 4, 
39
        "0010010" when 5, 
40
        ....
41
        "0000110" when 14,
42
        "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
von James Y. (Company: Student) (eejyang)


Rate this post
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
von James Y. (Company: Student) (eejyang)


Rate this post
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.

von James Y. (Company: Student) (eejyang)


Rate this post
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
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.