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
Transportation & Automotive
  • Technologies
  • More
Transportation & Automotive
Blog Create and Measure signals with Hercules High End Timer (HET) - 4: Getting Started
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Transportation & Automotive to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 14 Jan 2020 7:42 PM Date Created
  • Views 2111 views
  • Likes 5 likes
  • Comments 5 comments
  • n2het
  • halcogen
  • texas_instruments
  • hercules
  • code_composer_studio
Related
Recommended

Create and Measure signals with Hercules High End Timer (HET) - 4: Getting Started

Jan Cumps
Jan Cumps
14 Jan 2020

A very simple HET example: Project0 - generate a PWM signal with a fixed duty cycle.

image

The previous posts were a showcase: let the timer module do some calculations while generating and and measuring signals. In this much simpler post let's take a step back. The TI Application Note NHET Get Started*1 shows the core specialty of the HET module: counting

 

In order to create a fixed frequency pulse with a fixed duty cycle, only two lines of PWM code are needed:

 

L00: CNT{next = L01, reg = A, max = 624}
L01   MCMP { next=L00,hr_lr=HIGH,en_pin_action=ON,pin=6,order=REG_GE_DATA,action=PULSEHI,reg=A,data=0x1D4,hr_data=0x00};

 

The first one, CNT, is a Counter to 624. It generates the frequency.

The second instruction, MCMP, is a compare. It generates the duty cycle.

image

source: TI document SPU490 Enhanced High-End Timer (NHET) Assembler User's Guide

 

Let's have a look at the problem statement and some calculations first (translated to a different clock and different output signal requirements from the NHET Get Started application note)

 

given:

  • Main system clock HCLK = 110 MHz

asked (what do we want to achieve as putput signal?):

  • PWM frequency = 11 kHz
  • PWM duty cycle dc = 25%
  • PWM accuracy = 150 ns steps or better

 

Calculate the HET Clock Settings

 

First, I need to calculate what frequency is needed to drive the precision of 150 ns.

This is a function of the High Resolution clock.

That clock is 110 MHz by default, good for an 9.091 ns  (1/110 MHz) accuracy.

 

-> VCLK2 = 110 MHz

 

 

We can achieve a precision of 150 with a 6.667 MHz clock (1/150 ns).

To derive an approx 6.667 MHz clock, we can divide our 110 Mhz by 16.

This gives 6.875 MHz, better than the minimum req of 6.667 to get the precision.

 

Note that we can only get frequencies by dividing the 110 MHz clock using the HR (high-resolution divide ratio).

The result is that we'll have a better than 150 ns (145.455 ns) even if we divide the clock by 16.

 

takeaway: the slowest HET high-resolution clock that allows us to give an accuracy of 150 ns (or better) is 6.875 MHz. That's 110 MHz / 16.

 

-> hr = 16

 

Second, let's see how to set the loop resolution pre-scaler.

As seen at the start of the blog, we need to be able to run 2 instructions. Both instructions take 1 cycle.

The number of available timeslots (cycles) is lr * hr.

 

We need 2 cycles, and the number of available cycles is lr * hr.

lr = 2/hr= 2/16. That allows us to set the lowest setting, 1, to have enough  calculation time

 

-> lr = 1

 

image

source: TI document RM46x 16/32-Bit RISC Flash Microcontroller Technical Reference Manual - PFR register

 

the number of timeslots is lr * hr.

 

-> ts = 16 * 1 = 16

 

With that, the high resolution and loop resolution period can be calculated:

 

image

 

-> LRP = 16 * 1 / 110 MHz = 0.0000001454545 = 145.45 ns

 

-> HRP = 1/110 MHz = 0.00000000909 = 9.09 ns

 

Configure the HET Program to Generate the Desired PWM Signal with these Timings

 

PWM frequency is driven by the first line of code, the Count instruction.

The duty cycle is controlled by the second line, the Compare instruction.

 

To achieve a frequency of 11 MHz, we have to calculate how many counts it takes to achieve the goal.

 

-> Signal Period = 1 / 11 MHz = 90.90909 µs

image

 

-> CNT_max = (90.90909 µs / 145.45 ns) - 1 = 624

 

You can see that in line 1 of the HET code:

 

L00: CNT{next = L01, reg = A, max = 624}

 

 

To achieve a duty cycle of 25%, we need to calculate the compare value for the Compare instruction.

 

-> dc = 0.25

 

The MCMP instruction can be configured to set the pin to a logic 1 when the compare matches a virtual counter value.

With a duty cycle requirement of 25% the number of hr cycles =

 

image

 

-> PWM_duty = ((624 + 1) × 1) × (1 – 0.25) = 468

 

Now comes a tricky part image - check Application Note SPRABA0B - NHET Getting Started (link in the post header) for a full explanation.

I can't do it better and don't want to copy the whole section.

 

In essence:

The MCMP instruction's compare value exists of 2 pieces of data, named hr_data and data.

image

You have to fit the number 468 in that.

 

Depending on the lr setting, you have a number of bits of that 468 that 'll fit in the hr_data. The rest has to go into data.

image

 

Our lr is 1, so we don't have access to the hr_data. So we have to skip the whole 6 bits of hr_data.

468 =  111010100b

left shifted by 6 bits: 111010100000000b

 

The right 6 bits ( 6 LSBs) (I know this is silly, but in the TI app note they have an example where the lr = 8, so that explains it better because they will have hr_data bits) have to go to hr_data:

hr_data = 000000b = 0x00

 

The remaining bits (all MSBs exept the 6 LSBs) go to data: 111010100b = 0x1D4

 

This gives the 2nd line of HET code:

 

L01   MCMP { next=L00,hr_lr=HIGH,en_pin_action=ON,pin=6,order=REG_GE_DATA,action=PULSEHI,reg=A,data=0x1D4,hr_data=0x00};

 

 

The result is the PWM signal shown in the post header: 11 kHz, 25% duty cycle.

As you can see, even for the simplest of examples, you need to use your brain - and get used to the mechanisms.

 

To make things somewhat more confusing, a hr of 16 and a lr of 1 are configured like this in HALCoGen image  :

image

This is because they represent the values as explained in the technical reference manual for the PFR register:

 

    /** - Setup prescaler values
    *     - Loop resolution prescaler
    *     - High resolution prescaler
    */
    hetREG1->PFR = (uint32)((uint32) 0U << 8U)
                | ((uint32) 15U);

 

You have to use the translation table from that manual (see above, I've copied the relevant parts called LRPFC and HRPFC) to get the values that are to be used in the calculations.

 

In the HET IDE, the same prescalers are configured so:

image

These are the translated values. I hope that by writing this down here, I never ever have to look this up again in the manuals and code.

 

A lot to learn and remember ...

 

AcronymDescription

CNT_max

CNTHCLK

hr High

hr_data

HRP

lr

LRP

PWM

ts

VCLK2

Maximum counter value of virtual count instruction

Main system clock

resolution divide ratio

High resolution data field of an instruction

High resolution period

Loop-resolution divide ratio

Loop-resolution period

duty PWM duty cycle

Timeslots

Peripheral clock used as master clock for NHET

 

The project is attached to this post. It includes the Code Composer Studio, HET and HALCoGen projects. Enjoy!

 

*1: Not available from TI USA anymore - this is a backup from TI Japan. If you have a link to a good TI application note, better download it. They are disappearing from their website regularly, also for active components and designs.

Their wiki site, containing labs and errata that have never been moved to official documentation, is slanted for removal. I think their e2e community (as a forum to discuss, not a support forum) and the LaunchPad initiative are all but dead. Don't know what's going on there but it looks like they gave up on the maker community as a gateway for future customers.

 

Related Blog
1: adapt TI example to a LaunchPad
2: Generate Dynamic Duty Cycle
3: Measure a PWM Signal and HET Interrupts
4: Getting Started
5: Getting Started with the Wave Form Simulator
Attachments:
RM46_het_getting_started_SPRABAOb20200114.zip
  • Sign in to reply

Top Comments

  • DAB
    DAB over 5 years ago +1
    Good update Jan. DAB
  • Jan Cumps
    Jan Cumps over 5 years ago

    A much simpler example, from another getting started guide (Application Report SPNA069 - High End Timer (HET) Getting Started Guide):

     

    ; HET_PWM_01_H.het
    L00: CNT {next=L01, reg=A, irq=OFF, max=0x214A, data=0}
    ; PWM (50% duty cycle)
    L01: ECMP {next=L02, reg=A, hr_lr=LOW, en_pin_action=ON, pin=CC0, action=PULSEHI, irq=Off,
    data=0x10A5}
    ; PWM (25% duty cycle)
    L02: ECMP {next=L03, reg=A, hr_lr=LOW, en_pin_action=ON, pin=CC2, action=PULSEHI, irq=Off,
    data=0x852}
    L03: BR {next=L00, cond_addr=L00, event=NOCOND}

     

    This one creates two PWMs with the same frequency but a different duty cycle, on HET pins 0 and 2.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to clem57

    The source is myself. My own experience and observations.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • clem57
    clem57 over 5 years ago

    *1: Not available from TI USA anymore - this is a backup from TI Japan. If you have a link to a good TI application note, better download it. They are disappearing from their website regularly, also for active components and designs.

    Their wiki site, containing labs and errata that have never been moved to official documentation, is slanted for removal. I think their e2e community (as a forum to discuss, not a support forum) and the LaunchPad initiative are all but dead. Don't know what's going on there but it looks like they gave up on the maker community as a gateway for future customers.

    I find this very disturbing! Can you expand on the reasons or source?image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago

    The PWM signal in the HET simulator:

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 5 years ago

    Good update Jan.

     

    DAB

    • Cancel
    • Vote Up +1 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 © 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