element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
FPGA
  • Technologies
  • More
FPGA
Forum FPGA: trigger on both flanks of a clock to toggle output
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join FPGA to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 4 replies
  • Answers 2 answers
  • Subscribers 559 subscribers
  • Views 2135 views
  • Users 0 members are here
  • fpga
  • hdl
Related

FPGA: trigger on both flanks of a clock to toggle output

Jan Cumps
Jan Cumps over 4 years ago

I tried to take a naïve approach to (if needed) toggle an output pin either on the rising or falling edge of  clock signal.

Line 17 below:

 

entity variable_clock is
    Port ( 
      clk_i    : in  STD_LOGIC;
      resetn_i : in  STD_LOGIC;
      ticks_i  : in  STD_LOGIC_VECTOR (7 downto 0);
      clk_o    : out STD_LOGIC
    );
end variable_clock;

architecture Behavioral of variable_clock is
  signal counter_s: natural range 0 to 2**ticks_i'length-1 := 0;
  signal clk_out_s: STD_LOGIC := '0';
begin

process (clk_i, resetn_i)
begin
  if rising_edge(clk_i) then
    if resetn_i = '0' then
      counter_s <= 0;
      clk_out_s <= '0';
    else
      if counter_s >= unsigned(ticks_i) then -- >= because the value can change
        counter_s <= 0;
        clk_out_s <= not clk_out_s;
      else
        counter_s <= counter_s + 1;
      end if;
      clk_o <= clk_out_s;
    end if;
  end if;
end process;

end Behavioral;

 

 

This synthesises without errors, but the output is identical when I use

  if rising_edge(clk_i) then

or

  if (rising_edge(clk_i) or falling_edge(clk_i)) then

Not double speed when using both edges, as the naïve me would expect.

 

Internet has many opinions and warnings on this subject - both for simulation and synthesis. Your thoughts?

  • Sign in to reply
  • Cancel

Top Replies

  • michaelkellett
    michaelkellett over 4 years ago +2 suggested
    I've never tried this so all suggestions are theory only ! Don't expect it to be easy to fool the tools into allowing this - FPGAs do not expect double data rate stuff internally. VHDL and simulation won…
  • wolfgangfriedrich
    wolfgangfriedrich over 4 years ago +2 suggested
    I always try to remind myself that the if rising_edge () statement is a special case as it does get synthesized into the clock input of a flip-flop instead of some logic gates/lookup tables. Putting more…
  • genebren
    genebren over 4 years ago +2
    Jan, I remember that some Xilinx parts (XC9500 and CoolRunner CPLD) use to have DUALEdge or Cool_Clock logic built in. They used special attributes to enable this feature into the synthesis process. Here…
Parents
  • wolfgangfriedrich
    0 wolfgangfriedrich over 4 years ago

    I always try to remind myself that the

    if rising_edge ()

    statement is a special case as it does get synthesized into the clock input of a flip-flop instead of some logic gates/lookup tables. Putting more conditions into that if clause, especially the falling_edge() function would make the synthesizer throw up in some form or another as there is no easy hardware equivalent to implement that. I would hope that there would be at least some warnings from the tool, that some statements get ignored.

    - W.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • wolfgangfriedrich
    0 wolfgangfriedrich over 4 years ago

    I always try to remind myself that the

    if rising_edge ()

    statement is a special case as it does get synthesized into the clock input of a flip-flop instead of some logic gates/lookup tables. Putting more conditions into that if clause, especially the falling_edge() function would make the synthesizer throw up in some form or another as there is no easy hardware equivalent to implement that. I would hope that there would be at least some warnings from the tool, that some statements get ignored.

    - W.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube