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
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • 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
Summer of FPGA
  • Challenges & Projects
  • Design Challenges
  • Summer of FPGA
  • More
  • Cancel
Summer of FPGA
Blog HACK CPUMOD S7 #4: PWM Module extension
  • Blog
  • Forum
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
Author: pandoramc
Date Created: 24 Jan 2022 10:51 PM
Views: 171
Likes: 5
Comments: 0
  • fpga
  • HACK CPU
  • summer of fpga
Related
Recommended

HACK CPUMOD S7 #4: PWM Module extension

pandoramc
pandoramc
24 Jan 2022

Consider the IP Catalog, mainly the Clocking Wizard. For this component we can stablish an input clock of 12MHz, as the boards has, and the output is multipled by power of two values.

This allow a power up in the clock speed, consequently, the PWM could be faster according the needs. Unfortunately, my implementation of HACK CPU is not efficient and there is a timming violation with superior clock frequencies. To test this I only changed the clock input for each instance and the intructions are the same from the last blog.

The first step is a Clock Wizard IP instantiation,

    DIV: ENTITY WORK.clk_wiz_0 
    port map(
      CLK16  => CLK16,
      CLK8  => CLK8,
      CLK4  => CLK4,
      CLK2  => CLK2,
      CLK1  => CLK1,
      reset     => RST,
      clk_in1   => CLK_SYS
     );

Here, the block is syncrhonized with the system reset and the clock input of the module is assigned with the 12MHz board clock. In the output we have a set of multipled clocks by 1, 2, 4 and so on. This allow modify the clock base of the PWM modules.

PWMA: entity work.WG_PH
     generic map(   Width => 16
     )
     port map(      CLK => CLK8,
                    MAX => pwmMaxA,
                    CMP => pwmCmpA,
                    Q => LEDS(2)
     );
     
PWMB: entity work.WG_PH
     generic map(   Width => 16
     )
     port map(      CLK => CLK4,
                    MAX => pwmMaxB,
                    CMP => pwmCmpB,
                    Q => LEDS(1)
     );
     
PWMC: entity work.WG_PH
     generic map(   Width => 16
     )
     port map(      CLK => CLK2,
                    MAX => pwmMaxC,
                    CMP => pwmCmpC,
                    Q => LEDS(0)
     );

As the code above shown, each instance of the PWM module has a 16 bit width to accomplish the processor word length. Remember the ISA of the HACK CPU, the processor has 15 bits of mantissa and one bit of sign. The three instances has the same structure but different memory map and clock source. These allow the PWM frequency configuration using software for the frequency and ducty cycle configuration, and hardware for the clock base module input configuration. Hence, the module C is faster than module B, and module B is faster than module A.

You can see the Duty Cycles of each PWM module is the same of the las blog, but the clock base of the modules allows a different PWM frequency even the same instructions. A benefit of the IP Catalog is the quick implementation of modules like Counters, Memories, Transforms and more. Another example is the ROM memory with the Block Memory Generator. This  wizard allow the an initilization file. Each time we generate our .hack file with the courseware tools it is possible to create a .coe file with the code. The following represent the .coe file for the configuration of the PWM modules. You only need replace the memory_initialization_vector with the respective compiled code.

;******************************************************************
;********              Example of .COE file               *********
;******************************************************************
;
; This .COE file specifies initialization values for PWM modules
; configuration with HACK CPU. The wizard uses this information to
; instantiate the ROM memory with the instructions
memory_initialization_radix=2;
memory_initialization_vector=
0000010000000000
1110110000010000
0100000000000011
1110001100001000
0000000010000000
1110110000010000
0100000000000100
1110001100001000
0000010000000000
1110110000010000
0100000000000101
1110001100001000
0000001000000000
1110110000010000
0100000000000110
1110001100001000
0000010000000000
1110110000010000
0100000000000111
1110001100001000
0000001100000000
1110110000010000
0100000000001000
1110001100001000
0000000000011001
1110101010000111;

The next step, create a software functionality for the PWM clock base configuration. The memory map should be updated to accomplish a peripheral philosophy in a microcontroller.

Anonymous
Element14

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 © 2022 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