element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • 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
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • 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
FPGA
  • Technologies
  • More
FPGA
Blog Learning Xilinx Zynq: a Quadrature Oscillator - variable frequency
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
FPGA requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 31 Aug 2021 10:09 AM Date Created
  • Views 1733 views
  • Likes 6 likes
  • Comments 3 comments
  • summer_of_fpgas
  • zynq
  • xilinx
  • fpga
  • vhdl
  • pynq
  • sdr
Related
Recommended

Learning Xilinx Zynq: a Quadrature Oscillator - variable frequency

Jan Cumps
Jan Cumps
31 Aug 2021

This post is a follow up on a previous article to generate a quadrature clock for shabaz 's Software Defined Radio (SDR) Experiment Board.

It's a circuit with 4 PWM outputs that are each 90° shifted.

I'm adding programmable frequency control. Without the need to change the fabric clocks.

It will be a VHDL module, that's put in between the fabric clock and the quadrature oscillator from the previous blog. A register allows you to control the output frequency.

 

image

 

Programmable Frequency

 

There are several options to generate a variable frequency with an FPGA:

  • Use a std_logic_vector counter incremented at the input clock, and select what bit you'll use as output clock. The LSB will generate the fastest clock, MSB the slowest (examples).

  • Use a counter that indicates how many input clock ticks you wait before toggling the output clock. I'm writing one of these in this post.
  • clock wizards and proprietary IP that offer PLL and other device specific precise derived clock signals.

 

Here's the VHDL code. I attempted to make it easy to read. No tricks or smart things. Critique and advice: put it in the comments.

 

variable_clock.vhd

source available as GitHub Gist.

 

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

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 s_counter: natural range 0 to 2**ticks_i'length-1 := 0;
  signal s_clk_out: STD_LOGIC := '0';
begin

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

end Behavioral;

 

You can set the program register between 0 and 255.

A full output cycle requires two toggles of the output signal. A toggle to generate the high halve of the period, a second one to generate the low halve.

By incrementing the program register, you add the time of one input clock tick to each half period of the output.

 

If you put it to 0, it will toggle the output at each rising edge of the input clock.  It requires two input clock ticks for a full period so it halves the input clock frequency.

If you pass 1, the block will ignore 1 input clock tick before toggling the output. 4 input ticks are needed to generate one output clock period.

If you pass 2, 2 ticks are ignored at each output toggle. It takes 6 input ticks to generate a full period.

 

In my example, I'm driving the input with a 100 MHz fabric clock.

One period is 10 ns. So we get a rising edge each 10 ns.

Because we add 2 input ticks for each increment, the output period gets 20 ns longer each time.

Let's see what the results is:

 

register value output clock period output clock frequency
0 2 * 10 ns = 20 ns 1/20 ns = 50 MHz
1 4 * 10 ns = 40 ns 1/40 ns = 25 MHz
2 6 * 10 ns = 60 ns 1/60 ns = 16.667 MHz

 

The formula: (register value + 1) * 2 * input clock period = output clock period.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

video: a Jupyter notebook sweeps through the frequency range

 

Fit it into the Quadrature Oscillator design

 

The purpose of this variable frequency block is to  control the speed of the quadrature oscillator of the previous post. This is an easy exercise, done in Vivado.

Remove the link between fabric clock and quadrature oscillator clock input.

Add your new variable clock IP to the design by adding it to the block diagram. Link its clock input to the fabric clock. Clock output to the quadrature oscillator.

I've exposed the variable clock output so that you can probe it and verify the claims above. This is optional.

 

image

 

The reset is shared with the rest of the PL.

The ticks_i register is an 8 bit input.

In my design, I've attached it to the ARM/Linux part via the AXI interface. That makes that I can program it from the ARM/Linux part.

 

image

 

This is a choice specific to achieve my goal of having it software changeable. You could also control it from an FPGA quadrature decoder block, from 8 input pins, an FPGA sweep generator (counter), ...

 

Jupyter notebook

 

The notebook allows you to load the bitstream into the FPGA, and set the register of the variable clock:

image

 

The Vivado project is attached to this post.

 

I used a hierarchy to show the variable clock and the quadrature oscillator as one block on the main design:

image

the content of the dark blue block is the 1st image at the top of this article.

 

For a pure FPGA implementation, check FPGA: a quadrature oscillator with rotary encoder control.

 

 

Pynq - Zync - Vivado series
Add Pynq-Z2 board to Vivado
Learning Xilinx Zynq: port a Spartan 6 PWM example to Pynq
Learning Xilinx Zynq: use AXI with a VHDL example in Pynq
VHDL PWM generator with dead time: the design
Learning Xilinx Zynq: use AXI and MMIO with a VHDL example in Pynq
Learning Xilinx Zynq: port Rotary Decoder from Spartan 6 to Vivado and PYNQ
Learning Xilinx Zynq: FPGA based PWM generator with scroll wheel control
Learning Xilinx Zynq: use RAM design for Altera Cyclone on Vivado and PYNQ
Learning Xilinx Zynq: a Quadrature Oscillator - 2 implementations
Learning Xilinx Zynq: a Quadrature Oscillator - variable frequency
Learning Xilinx Zynq: Hardware Accelerated Software
Automate Repeatable Steps in Vivado
Learning Xilinx Zynq: Try to make my own Accelerated OpenCV Function - 1: Vitis HLS
Learning Xilinx Zynq: Try to make my own Accelerated OpenCV Function - 2: Vivado Block Design
Learning Xilinx Zynq: Logic Gates in Vivado
Learning Xilinx Zynq: Interrupt ARM from FPGA fabric
Learning Xilinx Zynq: reuse and combine components to build a multiplexer
PYNQ version 2.7 (Austin) is released
PYNQ and Zynq: the Vitis HLS Accelerator with DMA training - Part 1: Turn C++ code into an FPGA IP
PYNQ and Zynq: the Vitis HLS Accelerator with DMA training - Part 2: Add the Accelerated IP to a Vivado design
PYNQ and Zynq: the Vitis HLS Accelerator with DMA training - Part 3: Use the Hardware Accelerated Code in Software
PYNQ and Zynq: the Vitis HLS Accelerator with DMA training - Deep Dive: the data streams between Accelerator IP and ARM processors
Use the ZYNQ XADC with DMA part 1: bare metal
Use the ZYNQ XADC with DMA part 2: get and show samples in PYNQ
VHDL: Convert a Fixed Module into a Generic Module for Reuse

 

Attachments:
quadrature_oscillator_advanced.zip
  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 1 year ago in reply to shabaz +1
    The variable frequency increases 2 input periods per step. In my case, 100 MHz, that's 20 ns. The increment is linear in the time domain. Always adds a fixed time. The quadrature clock generator then needs…
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to shabaz

    The variable frequency increases 2 input periods per step. In my case, 100 MHz, that's 20 ns.

    The increment is linear in the time domain. Always adds a fixed time.

     

    The quadrature clock generator then needs 4 ticks of that output to generate a full period (in a quadrature signals, there are 4 points in time where the signals change, per period).

     

    The variable clock resolution can be doubled by using both edges of the input clock.

    Likewise, it should be possible to generate a full quadrature period in 2 ticks by using both edges of its input clock to change outputs.

    tested and it doesn't work. I need to dive deeper into this.

     

    The register bus width doesn't impact the resolution. It's a function of the input clock speed only.

    The width does influence the number of clock ticks you burn when generating the output, so a wider register allows you to create a wider range. But not a finer one.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 1 year ago

    Hi Jan,

     

    This is looking really neat!

    I was wondering, what will the frequency increment be? Would it need to be more than 8-bit register, to get the resolution finer?

    The resolution likely needs to be at low kHz (like 1-2 kHz max, but preferably less), since it's possible to do some of the tuning in the SDR receiver software.

    If you're planning on using it in just one band like say AM broadcast band then that could be a good way to go, if it's easier to have such resolution there.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago

    This is the Python code that makes the oscillator sweep:

     

    image

    I changed the fabric clock to 10 MHz because that's easier to probe than 100 MHz.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
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 © 2023 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube