Forum Discussion

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

EPC20, VHDL Divider & PLL Question

hello,

not sure if this is the 'correct' sub-board in which to post these related questions....

i'm a newbie student of fpgas and vhdl. my setup:

2.6 ghz amd-64 with 4 gigs of ram

winxp pro sp3

terasic de1 development board w/cyclone ii, epc20-f484-cn7 fpga

hp8116a 50 mhz function generator

tektronix 2246 four channel oscilloscope

agilent frequency counter

quartus ii, v9.1 sp2, webed !! (thanks...altera)

the function generator output is set for 24 mhz, pulse-width 10% duty, with v[sub]ih = [/sub]+1.5 ~ +1.7 vdc wrt dc return (gnd). the generator is connected via rg-174u coax cable to the ext_clock input (sma) pin_m21 on the terasic de1 dev-board.

goal:

divide a clock signal down using a d flip-flop binary divider chain. 24 mhz / 23bits = 1.41 hz.

configuration:

the output signal is monitored via ledg[7], (de1-pin_y21) which is conncted to the last bit of the d-ff divider chain of the routed synthesized circuit. the divider chain is a 23 bit up incrementing binary counter which is being used to numerically divide-down the 24 mhz clock, in an attempt to generate an appx 1.4 hz signal.

problem:

the wrong signal frequency is being produced with (suspected...hoped for?) proper divide ratio.

perceived results:

applying 24 mhz pulse signal to divide-by binary counter, d-flip-flop divider chain generates proper simulation waveforms as can be seen in the simulation (screen-grab image provided below), but the output signal period is much too long. using 23 bits to divide the clock signal is given mathematically to be correct divide ratio, while, experimentally, it is found that 11 bit divide ratio generates desired result.

method:

24 mhz = 24[sup]+6[/sup]

24[sup]+6 [/sup]/ 23 bits (8,388,608) = ~1.43 hz

unfortunately, i don't see 1.43 hz on blinker_o (q23), instead, i see something on the order of 2 ~3 minutes per cycle when it is expected to be 1.43 hertz.

however, if i change the n_bit generic value from a divide ratio of 23 down to 11 (appx 1/2) i do see, appx 1.43 hz. i am confused, i do not understand what is happening? what am i missing?

and then, another question unrelated to the clock-divider problem, in reading through cyclone ii epc20 data-sheet, i see that there are plls that are available. how are those resources accessed using vhdl, or via any other manner?

below is the vhdl code for the divide_by_counter led "blinker", which is the 'top' level:


-- Dependencies:
-- Quartus II, v9.1, SP2
--
-- Description: Clock divide by N_BITS counter 'blinker'
-- 
-- Code Rev: rev 0.01 - file created
-- Additional Comments:
--
-- Development Platform: Terasic DE1, EPC20-F484-C7N 
--
-- by altera_student, 05-22-2013
--
---------------------------------------------------------------------------
--
-- library declaration
library IEEE;
use IEEE.std_logic_1164.all;     -- basic IEEE library
use IEEE.numeric_std.all;         -- IEEE library for the unsigned type and
use IEEE.std_logic_unsigned.all;  -- to overload the '+' operator
entity blinker is
generic (N_BITS     : integer := 23);        -- 'divide by' value
    port( 
            clk_i        : in    std_logic;    
            blinker_o  : out std_logic_vector((N_BITS-1) downto 0)                
        );
end blinker;
------------------------------------------------------
-- 12,000,000 Hz clock / 22 bit counter (8,388,608) = 1.43 Hz
-- 24,000,000 Hz clock / 23 bit counter (16,777,216) = 1.43 Hz
-- 24,000,000 Hz clock / 11 bit counter (2048)  = 11718.75 Hz
architecture behav of blinker is 
signal     cnt_r         : std_logic_vector((N_BITS-1) downto 0);
begin
-- divide clk by n_bits
process(clk_i) is        
    begin
        if rising_edge(clk_i) then -- clock on the hi pulse
              cnt_r <= cnt_r + 1;  -- increment the bin counter
        end if;
    end process;
    blinker_o <= cnt_r;  -- update the outputs, pickoff last bit for output signal
end behav;    -- blinker

here's a screen-shot of quartus sim depicting that the 11 bit version binary counter is producing proper waveforms:

https://www.alteraforum.com/forum/attachment.php?attachmentid=7284

so the question is, why isn't the circuit producing the correct output frequency? whats going on? with 24 mhz input, an 11 bit counter should produce 11,718.75 hz, not 1.41 hz?

any suggestions will be appreciated (aside from jumping into a lake), <g>

thanks in advance,

altera_student

3 Replies

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

    There is nothing that strikes me as bad here, except that you are using both numeric_std.all and std_logic_unsigned.all at the same time, which is usually a bad idea and confuses the synthesizer. I would suggest to only use numeric_std.all and declare your cnt_r signal as an unsigned instead of std_logic_vector. If you want to keep blinker_o a std_logic_vector, you can cast it with this line outside of the process:

        blinker_o <= std_logic_vector(cnt_r);  -- update the outputs, pickoff last bit for output signal
    Are you sure the FPGA is picking the clock correctly? You could compile a simple design that would recopy the clk_i signal to an outside pin and check with an oscilloscope that it is indeed 24MHz.

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

    --- Quote Start ---

    The function generator output is set for 24 MHz, pulse-width 10% duty

    --- Quote End ---

    You have a pulse that is at '1' state for 4.17ns. It may violate timing constraints.

    Clock signal should be 50% duty cycle, I think.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello Daixiwen and mmTsuchi,

    Thank your for your suggestions, I'll address them when I get the time.

    altera_student