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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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
Blog ePWM, an improvement for less processing
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join FPGA to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: pandoramc
  • Date Created: 29 Jul 2022 12:21 PM Date Created
  • Views 910 views
  • Likes 8 likes
  • Comments 0 comments
  • 7 Ways to Leave Your Spartan-6: Additional experiment
  • 7 Ways to Leave Your Spartan-6
  • pwm
  • xilinx
  • arty s7
  • verilog
  • 7 Ways to Leave Your Spartan-6 FPGA: Arty S7 Activities
  • microblaze
Related
Recommended

ePWM, an improvement for less processing

pandoramc
pandoramc
29 Jul 2022

The enhanced Pulse Width Modulation (ePWM) IP creation has only one objective, to reduce the processor time required for direction control in the motor driver. It is based on a 32-bit signed int data type and can handle positive and negative values. A positive number indicates a clockwise rotation action while a negative number allows a counterclockwise rotation.

image

ePWM IP

The motor control port (M_CTRL) has 3 signals: Enable, PWM, and Direction. At this moment, the Enable signal is always assigned to 1, to maintain the motor activated according to the motor driver architecture. PWM handles a duty cycle from 0 to (Width - 1), this allows a complete deactivation of the channel. Finally, Direction changes the rotation direction.

image

ePWM simulation

`timescale 1ns / 1ps

module PWM(
    input clock,
    input reset,
    input [31:0] Width,
    input signed [31:0] Duty,
    output reg oPWM,
    output oDIR
    );

reg [31:0] count;
wire [31:0] aDuty;

assign aDuty = Duty[31]? -Duty[31:0]: Duty[31:0];

always @ (posedge clock)
begin
    if(reset) begin
        count = 0;
    end else begin
        if(!(count < Width)) begin
            count = 0;
        end else begin
            count = count + 1;
        end
    end
end

always @ count
begin
    if(count < aDuty) begin
        oPWM = 1;
    end else begin
        oPWM = 0;
    end
end

assign oDIR = Duty[31];
    
endmodule

All the processing required by software for the direction change using a GPIO is delegated to the ePWM with a direct connection to the control terminals. The module only requires two values: the Period and the Duty cycle. This approach allows replacing the following code, 

...

static uint32_t pPWM;

response = PID_CalcResponse(&MotorCtrl, (float)sMt -> Position);

if(response >= 0)
	OUTS -> DATA2 |= 0x02;
else
	OUTS -> DATA2 &= 0x0D;

pPWM = (uint32_t)(fabs(response));

*Duty = (uint32_t)pPWM;

...

For the next one,

...

response = PID_CalcResponse(&MotorCtrl, (float)sMt -> Position);

*Duty = (int32_t)response;

...

It is required only a typecasting to accomplish the module design and all additional validations are made by hardware, obtaining the same results with less processor time.

  • Sign in to reply
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