[VHDL] Licznik modulo n

Jun 08, 2004 1 Replies

Witajcie grupowicze!



Chcê stworzyæ ogólny licznik modulo n, gdzie n by³o by parametrem modu³u. Interfejs Licznika wygl±da³by mniej wiêcej tak:



entity modulo_counter is generic (n: positive); port ( clk, enable, reset: in std_ulogic; q: out std_ulogic_vector (???? downto 0) ); end entity modulo_counter;



Co powinienem wstawiæ zamiast "????" ? Wiem, ¿e powinna byæ (i tak chcê!) to warto¶æ równa



sufit (log2 (n)) -1,



ale jak to mam wyraziæ w jêzyku VHDL?


-- rwpg


Chyba trochê pospieszy³em siê z pytaniem i nie poszuka³em dobrze zanim je og³osi³em...

Znalaz³em ju¿, ¿e nie ma w bibliotekach VHDL operatora log2, ale znalaz³em jak mo¿na tak± funkcjê utworzyæ samemu:

function Log2( input : integer ) -- input number return integer is variable temp, log : integer; begin assert input /= 0 report "Error : function missuse : log2(zero)" severity failure; temp := input; log := 0; while (temp /= 0) loop temp := temp/2; log := log+1; end loop; return log; end log2;

Czy s± jeszcze jakie¶ inne podej¶cia do problemu?

-- rwpg

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required