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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog Sync PWM with an External Signal - TI Hercules Microcontroller
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 19 Sep 2020 5:54 PM Date Created
  • Views 2031 views
  • Likes 2 likes
  • Comments 0 comments
  • halcogen
  • texas_instruments
  • herciules
  • automotove
Related
Recommended

Sync PWM with an External Signal - TI Hercules Microcontroller

Jan Cumps
Jan Cumps
19 Sep 2020

At times it is useful to get activities in your firmware synced up with external events.

There are several types of events that are dependent of the speed, frequency, state, ... of something external.

In this blog, I'm showing martinvalencia's solution to synchronise a microcontroller PWM signal with an external clock.

 

image

image: a blue 20 kHz signal kept under control of an external 60 Hz pulse

 

The PWM is (in this example) 20 kHz. The external clock is a 60 Hz signal.

Those two values are selected because they show up nicely on an oscilloscope. They 'll allow you to see the syncing vs. not-syncing.

In a real world example, the 60 Hz could be the zero-crossing point of your utility line. And the PWM signal a 3-phase signal generated by your controller, syncing up with the line power.

 

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

video: the 20 kHz signal synked by the external 60 Hz signal, control released and control regained

 

What Does it Do?

Every time the controlling signal has a rising edge, the PWM signal is reset.

It's current activity, whether it was high or low, regardless of however long it was high or low, will be stopped and discarded.

The PWM will start generating as if it's just been switched on.

You can see this as a triggered restart.

 

Setting up de Peripherals

 

You need to enable the PWM driver, because that's the one that 'll be used both for detecting the sync pulses and generating the PWM.

This is done vie the HALCoGen application for Hercules controllers.

 

image

 

Then in the PWM settings, enable the 1st one, and set its behaviour.

 

image

 

image

 

Then the Pin Multiplexer. This is different for the RM46 and 57 (and the same image different for their TMS570LS12 TMS570LC43 twins).

 

RM46:

image

 

image

 

RM57:

 

image

 

image

 

That's it. Let HALCoGen generate the project code.

 

Source Code

 

Very simple. It sets that the counter (re)loads on sync.

 

    etpwmInit();

    etpwmEnableCounterLoadOnSync(etpwmREG1, 0, COUNT_UP);
    while (1) {
    }

 

The behaviour is as you can see in the video at the start of this article.

If no external pulse, the PWM happily pulses at its set frequency. Each time the external sync pulse is detected, the PWM resyncs on that event.

  • 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