Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7987425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:08:46+00:00 2026-06-04T12:08:46+00:00

Is it possible to write a code segment and call it, instead of writing

  • 0

Is it possible to write a code segment and call it, instead of writing that segment many times? Ie. I want to reuse a segment of code as shown below:

process (currentState)
begin
    case currentState is
    when requiredCoinsTensAnode => anodes <= "100000";--turn on the tens display
        case tensCount is
        when "0000" => segDisplay <= "1111110"; --0
        when "0001" => segDisplay <= "0110000"; --1
        when "0010" => segDisplay <= "1101101"; --2
        when "0011" => segDisplay <= "1111001"; --3
        when "0100" => segDisplay <= "0110011"; --4
        when "0101" => segDisplay <= "1011011"; --5
        when "0110" => segDisplay <= "1011111"; --6
        when "0111" => segDisplay <= "1110000"; --7
        when "1000" => segDisplay <= "1111111"; --8
        when others => segDisplay <= "1111011"; --9
        end case;
        nextState <= requiredCoinsUnitsAnode;--just displayed the tens digit, next we need to display the units digit
    when requiredCoinsUnitsAnode => anodes <= "010000";--turn on the units display
        case unitsCount is
        when "0000" => segDisplay <= "1111110"; --0
        when "0001" => segDisplay <= "0110000"; --1
        when "0010" => segDisplay <= "1101101"; --2
        when "0011" => segDisplay <= "1111001"; --3
        when "0100" => segDisplay <= "0110011"; --4
        when "0101" => segDisplay <= "1011011"; --5
        when "0110" => segDisplay <= "1011111"; --6
        when "0111" => segDisplay <= "1110000"; --7
        when "1000" => segDisplay <= "1111111"; --8
        when others => segDisplay <= "1111011"; --9
        end case;
        nextState <= insertedCoinsTensAnode;
    end case;
end process;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:08:48+00:00Added an answer on June 4, 2026 at 12:08 pm

    Functions are one option, as ravi has pointed out.

    function f_segDisplay (
      signal segCount : std_logic_vector(6 downto 0))
      return std_logic_vector(3 downto 0) is
    begin  -- f_segDisplay
        case segCount is
          when "0000" => return "1111110";  --0
          when "0001" => return "0110000";  --1
          when "0010" => return "1101101";  --2
          when "0011" => return "1111001";  --3
          when "0100" => return "0110011";  --4
          when "0101" => return "1011011";  --5
          when "0110" => return "1011111";  --6
          when "0111" => return "1110000";  --7
          when "1000" => return "1111111";  --8
          when others => return "1111011";  --9
        end case;
    end f_segDisplay;
    
    process (currentState, tensCount, unitsCount)
    begin
      case currentState is
        when requiredCoinsTensAnode =>
          anodes     <= "100000";          --turn on the tens display
          segDisplay <= f_segDisplay(tensCount);
          nextState  <= requiredCoinsUnitsAnode;
        when requiredCoinsUnitsAnode =>
          anodes     <= "010000";          --turn on the units display
          segDisplay <= f_segDisplay(unitsCount);
          nextState  <= insertedCoinsTensAnode;
      end case;
    end process;
    

    Depending on the compiler and options, it may decide to put the function code in-line. This would cause multiple instances of the logic to be placed, much like your original code.

    An alternative is that you take the common code out into another process:

    p_segdisplay : process (segCount)
    begin  -- process p_segdisplay
      case segCount is
        when "0000" => segDisplay <= "1111110";  --0
        when "0001" => segDisplay <= "0110000";  --1
        when "0010" => segDisplay <= "1101101";  --2
        when "0011" => segDisplay <= "1111001";  --3
        when "0100" => segDisplay <= "0110011";  --4
        when "0101" => segDisplay <= "1011011";  --5
        when "0110" => segDisplay <= "1011111";  --6
        when "0111" => segDisplay <= "1110000";  --7
        when "1000" => segDisplay <= "1111111";  --8
        when others => segDisplay <= "1111011";  --9
      end case;
    end process p_segdisplay;
    
    process (currentState, tensCount, unitsCount)
    begin
      case currentState is
        when requiredCoinsTensAnode =>
          anodes    <= "100000";          --turn on the tens display
          segCount  <= tensCount;
          nextState <= requiredCoinsUnitsAnode;
        when requiredCoinsUnitsAnode =>
          anodes    <= "010000";          --turn on the units display
          segCount  <= unitsCount;
          nextState <= insertedCoinsTensAnode;
      end case;
    end process;
    

    BTW: You need tensCount and unitsCount in your sensitivity list.

    Abstracting a common resource like this is a useful technique when doing area or power concious designs.

    Both should work in the same way, and perfect tools would produce the same logic from the two, but we rarely have perfect tools. Experiment with different styles. Some produce better results on some tools, some on others.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As in the images shown below, is it possible to write code to write
I would like to know whether it is possible to write code that would
Is it possible to write Python code that gets a video file (mpg, avi,
Is it possible to write code in a Flex application that will only be
If it possible to write byte code for a method that is supposed to
Is it possible to write code that wrap any node.js i/o-callback with my own
I've heard that it is possible to write some code like this SomeClass obj
Is it possible to write code which generates a regular expression or XPath that
This link says that it is indeed possible to write code in Python and
Even though it is possible to write generic code in C using void pointer(generic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.