Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

VHDL HC237 3-8 Decoder with latches

Hello, I'm trying to write the VHDL code for chip HC237. I think I have something written that will work for the most part, but my problem is in dealing with pin GL. Basically what this chip does is outputs all low if G1 is low or G2 is high. When GL is low everything runs normally, when GL is high the output is dependent upon what the last inputs (A,B, and C) were when GL was low. If my description doesn't make since you can check the truth table and it should be cleared up. Well I have something written that should work for every situation except for when GL goes high. I know in assembly you can make most anything a subroutine and just jump to that subroutine. Is it possible to do that in VHDL? Could I have an if statement that says if GL='1' then jump to this subroutine? I've attached the code I've written so far.

8 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    There is no such thing as a subroutine in VHDL. That is a programming concept. VHDL describes digital logic.

    Try drawing your circuit on paper before describing it in VHDL.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    VHDL does describe digital logic, but doesn't it also use programming concepts to describe the behavior of the digital circuit? For instance, you can use if then statements, cases, while loops and for loops in VHDL and those are all programming concepts. What exactly do you mean by drawing out my circuit on paper first? Draw out all the logic gates that form my circuit? That is listed in the datasheet for the chip, but there are some components that don't seem to be standard logic gates.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    It is true that HDLs are programming languages. The main difference that software mindset need to realise is that all constructs are settled at compile time into a netlist (circuit). The circuit itself will not run loops or ifs etc. as does sequential processor based software.

    Moreover, most statements in HDL are concurrent as they are meant for parallel implementation. Only certain bodies (processes) are there to describe to the compiler the sequential behaviour. Processes are themselves concurrent with each other and with other comb. assignments.

    for example you can design a counter in HDL from lowest level of flips and logic, in effect easing up on the compiler, or you may design it by describing (telling compiler) in a process what you want and leave the compiler to decide the implementation.

    You can use subroutines e.g. functions(procedures), instantiations to tell the compiler what you want be implemented. In short the HDL is sequential to the compiler but is interpreted into a netlist of parallel circuitry.

    Some statements are purely messages to the compiler e.g. for loops are just there to shorten the code and are unfolded into multiple statements at compile time.

    Your code looks ok to me (but you need to add I to sensitivity list). Regarding GL input when high then you need to save A,B,C on registers then apply logic as your "I" case statement.

    To register A,B,C state you need a separate clocked process to save previous values when GL was zero.

    e.g.

    clocked process...

    if GL = '0' then

    A_reg <= A;

    B_reg <= B;

    C_reg <= C;

    end if;

    then use A_reg... for your decoding logic process.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hm so do I need to restate my case statement for if GL=1 then? I attached an updated copy of my code. The concept makes sense to me but I'm not exactly sure if my implementation is correct. I just started learning VHDL so I'm still trying to get a decent grasp on it.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    What is the second process doing? where to A,B,C and A_reg, B_reg and C_reg come from? Looking at this process, no registers are created, just latches. There is no clock in your system.

    looking at the first process, all you have is asynchronous logic. Nothing wrong with it. G1 has prority over G2, and if they are equal to '1' and '0' then Y is basically a 1-hot output version of I. Simple decoding.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    All I'm trying to get process 2 to do is act like a storage latch. When GL is low everything should operate normally but when GL is high it should give an output based on what the inputs were when GL was low. I'm trying to store the inputs of I (A,B,C) into 3 separate variables when GL is low so that when it is high I can load those variables back into I and run the case statement. I'm not sure how exactly to go about that however.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I would not try and build transparant latches - you will run into all sorts of problems as you cannot garante timing with them. You would also be creating latches for Y because it is not given a value when GL = '0'. And if A,B,C are meant to be the bits from I, you cannot drive an input port.

    I would first bring a clock into the design, it will make your life much much easier.