Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/12/06 18:46
Read: times


 
#127826 - more work?
Responding to: ???'s previous message
Richard Erlacher said:
The description of the count process is but a small part of the counter. You have to define the "count" as a signal and, outside the process, transfer the "count" to a STD_LOGIC_VECTOR, since XILINX, among others, doesn't support BUFFER mode. Of course, you'd have to support the enable and the reset, wouldn't you?


Oh, jeez.

First of all, there's rarely ANY reason to put the simple counter into its own counter module, as you probably end up using more lines of code for the counter instantiation than you would use just to describe it. And sometimes the counter (including its enable, reset, load, etc) is embedded in a state machine description because that makes more sense.

And you're confusing things here ... a buffer is a direction (like in, out and inout) whereas std_logic_vector is a type. There's nothing saying you can't have an unsigned or signed port, especially with modules that don't drive port pins.

Xilinx XST isn't the only synthesizer that doesn't support buffer ports; most HDL experts agree that buffer ports are "broken." And a buffer port isn't the problem with your counter, anyways; you're taking issue with the fact that VHDL (unlike Verilog) doesn't allow a signal declared as a module output to be used on the right-hand-side of an assignment. Here's a cool tip: I pretty much always declare my counters as integers with a specific range; for example:
signal counter : integer range 0 to 100;
Now, we all know that this will synthesize to a 7-bit counter (actual range 0 to 127) but for internal counting purposes, who cares? In fact, it's useful to take advantage of this in simulation. Test your code and the simulation complains if the counter is assigned, say, 102. Your description indicates the legal values that counter may be assigned and you're told if you're outside the range.

But back to the "internal vs external" signal problem. Write your counter using the usual addition operators (well handled by the integer type). If your module uses the counter values for other purposes, like in a comparison, all of the usual operators are available to you (and they AREN'T available when you're using std_logic_vector). So you do all of your work inside the module with the integer type without worrying about casting and such. The only place you do the typecast is the one assignment to the module output port.

I also like the unsigned and signed types provided by the numeric_std package.

Finally, an easy loadable, clearable counter of arbitrary width. Assume WIDTH is a generic, and initval is a module input of type std_logic_vector(WIDTH-1 downto 0).
signal count_i : unsigned (WIDTH-1 downto 0);
mycounter : process (clk, arst_l) is
begin
    if (arst_l = '0')  then  -- async reset
        count_i <= (others => '0');
    elsif rising_edge(clk)
    begin
        if (srst = '1') then -- synchronous reset
            count_i <= (others => '0');
        elsif (load = '1') -- synchronous load
            count <= unsigned(initval);
        elsif (enable  = '1') then
            if (count_i = (others => '1')  then -- gracefully handle overflow
                count_i <= (others => '0');
            else
                count_i <= count_i + 1;
            end if;
        end if; -- enable/reset/load?
    end if; -- clock edge
end process mycounter;

countout <= std_logic_vector(count_i);


Yeah, more complicated, perhaps, than pulling a counter symbol from your schematic library, but does the library have parametrized width?

-a

List of 81 messages in thread
TopicAuthorDate
Getting Started With FPGAs            01/01/70 00:00      
   A Book            01/01/70 00:00      
   Proceed with caution!            01/01/70 00:00      
   This is quite a nice deveolpment board            01/01/70 00:00      
   I like this board            01/01/70 00:00      
      I\'ve got one of these and can\'t recommend it            01/01/70 00:00      
         What are you talking about            01/01/70 00:00      
            Let me explain ...            01/01/70 00:00      
   generaly speaking            01/01/70 00:00      
      Damn, Jez, you need a spell-checker!            01/01/70 00:00      
         HDL-based design needs TEST BENCHES            01/01/70 00:00      
            I use 'em all the time, but ...            01/01/70 00:00      
               If your design is so simple            01/01/70 00:00      
                  What\'s important is the entry effort            01/01/70 00:00      
                     I dunno where you get these ideas from Richard            01/01/70 00:00      
                        Can you say ModelSim?            01/01/70 00:00      
                     Wrong            01/01/70 00:00      
                        Well, the schematic needs a little work            01/01/70 00:00      
                           more work?            01/01/70 00:00      
                              a few points ...            01/01/70 00:00      
                           ...            01/01/70 00:00      
                     HDL vs Schematics, take 1E6            01/01/70 00:00      
                        Thta may be great comfort to you ...            01/01/70 00:00      
                           Schematics? You're kidding!            01/01/70 00:00      
                              No, nor is my customer.            01/01/70 00:00      
                              both are a 'representation of Boole'            01/01/70 00:00      
                                 Yep, you're right...            01/01/70 00:00      
                                    To Clarify            01/01/70 00:00      
                                       schematic as equivalence check            01/01/70 00:00      
                                          Manual verification impossible because ...            01/01/70 00:00      
                                             schematic verification            01/01/70 00:00      
                                       Some more clarification            01/01/70 00:00      
                                          hanging problem            01/01/70 00:00      
                                             so will your post be            01/01/70 00:00      
                                    it's not fear of the unknown, but fear of its cost            01/01/70 00:00      
                           Static Timing Analysis and those "young engineers"            01/01/70 00:00      
                              It's a sign of the times, I suppose            01/01/70 00:00      
                                 And times change            01/01/70 00:00      
                                 senior?            01/01/70 00:00      
                                    That's because you've been avoiding the subject            01/01/70 00:00      
            I agree entirely. test benches are a pain but            01/01/70 00:00      
   Update from the OP            01/01/70 00:00      
      It's true ... we see things differently            01/01/70 00:00      
      the first buuk for any such venture            01/01/70 00:00      
      FPGA boards and that Cypress book            01/01/70 00:00      
         This may answer your question(s)            01/01/70 00:00      
   some of the references in the fpga faq            01/01/70 00:00      
      Good attitude            01/01/70 00:00      
   Also remeber to look at webistes like www.xilinx.c            01/01/70 00:00      
   My recommendation and opinions            01/01/70 00:00      
      I would stay away from Virtex-II            01/01/70 00:00      
         If you're going to fiddle with the 805x core ...            01/01/70 00:00      
            Something about life-cycles            01/01/70 00:00      
               No doubt about it.            01/01/70 00:00      
                  useful work            01/01/70 00:00      
                     Well, I beg to differ.            01/01/70 00:00      
                        salient point            01/01/70 00:00      
                           There's an area where that's not necessarily true            01/01/70 00:00      
                           FPGA Editor            01/01/70 00:00      
            Not necessarily            01/01/70 00:00      
               It's still too costly            01/01/70 00:00      
   Thanks to all            01/01/70 00:00      
   Update #2 from the OP            01/01/70 00:00      
   A testbench is...            01/01/70 00:00      
      I C            01/01/70 00:00      
         test bench            01/01/70 00:00      
            Makes sense            01/01/70 00:00      
   Yeah but...            01/01/70 00:00      
   Tristate buffer with propagation delays            01/01/70 00:00      
   Schematics vs. HDL            01/01/70 00:00      
      In a nutshell            01/01/70 00:00      
         it\'s been a while            01/01/70 00:00      
      Yes, but ... and there's always a but ...            01/01/70 00:00      
   Yep you can its called gate level design            01/01/70 00:00      
   Its really nothing to do with showing off            01/01/70 00:00      
      did you paraphrase this?            01/01/70 00:00      
      Jez, It\'s not \"sea of gates\" design, you know ...            01/01/70 00:00      
         Richards, it is there philosophy            01/01/70 00:00      
         Viewlogic            01/01/70 00:00      
   it is true            01/01/70 00:00      
   Here you go Richard graphical design exploration            01/01/70 00:00      

Back to Subject List