Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mod 8 AHDL Please help

  1. Nov 26, 2006 #1
    I'm working on a project for my digital electronics class and part of it is designing a mod 8 counter using AHDL, I have the counter designed no problem but the only catch is the counter once it reaches the number 7 should stay there and not start over until an external source tells it to.

    here's my code so far
    SUBDESIGN mod8_counter
    (
    CLK, CLR :INPUT;
    Y[2..0] :OUTPUT;
    )

    VARIABLE
    count[2..0] :DFF;

    BEGIN
    count[].clk = clk;
    IF !CLR THEN
    count[] = count[] + 1;
    END IF;
    Y[] = count[];
    END;
     
  2. jcsd
  3. Nov 26, 2006 #2

    berkeman

    User Avatar

    Staff: Mentor

    Seems like that's the part you need to modifiy the IF on, eh?
     
  4. Nov 26, 2006 #3
    I'm getting that my first if statement should be something to the effect of telling it that if y = 7 then it stays there else it will count up to 7 but I have no idea how to do that code, probably something easy but I'm still kinda new to this and I'm sure I'm just overlooking it.
     
  5. Nov 26, 2006 #4

    berkeman

    User Avatar

    Staff: Mentor

    You're on the right track. Just do some more reading about IF statements and other conditional statements.
     
  6. Nov 26, 2006 #5
    SUBDESIGN mod8_counter
    (
    CLK, CLR :INPUT;
    Y[2..0] :OUTPUT;
    )

    VARIABLE
    count[2..0] :DFF;

    BEGIN
    count[].clk = clk;
    IF !CLR THEN
    IF count[] < 7 THEN
    count[] = count[] + 1;
    ELSE count[] = count[];
    END IF;
    END IF;
    Y[] = count[];
    END;

    How's that look? I simulated and it seems to work ok?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?