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 ADC with DMA on a Hercules Safety MCU - Part 1: Port an existing example
  • 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: 12 Jul 2020 4:32 PM Date Created
  • Views 2078 views
  • Likes 2 likes
  • Comments 1 comment
Related
Recommended

ADC with DMA on a Hercules Safety MCU - Part 1: Port an existing example

Jan Cumps
Jan Cumps
12 Jul 2020

Goal: Continuously sample an ADC on a single thread microcontroller, with as little as possible CPU overhead.

I'm trying to use internal timers and DMA to fill memory with samples, and leaving all processing power for working with that data.

image

 

This post is a side effect of porting a TI example for another controller of the Hercules family.

The example works, but it's useful to find out the settings done in the HAL utility. Those weren't documented so it took me some effort to sort those out.

That work  to adapt from a Hercules RM46 to a TMS570LC43 is documented here.

 

Example's functionality: Hardware triggered sampling, DMA to move results into RAM.

 

One of the on-board ADCs is used to sample a signal. Results are moved to memory via DMA.

The trigger for each sample is a PWM signal generated by one of the on-board hardware timers.

 

HAL Configuration

 

The majority of the initialisation and driver generation is done via the HALCoGen utility.

 

Driver Enable

 

Two need to be enabled: the ADC and HET (timer) drivers.

image

The ADC 1 is used to sample. HET 1 (high-end-timer) for generating the hardware trigger at a fixed frequency.

Later in the post I will point out why the particular HET and a specific pin of that timer is used (giveaway: It 'll be HET1 pin 17).

 

ADC and HET clock frequency

 

To stay as close as possible to the original example, that runs on a different clock frequency, I changed prescalers:

image

I didn't calculate. Just used settings until the timer and ADC frequencies (see later) matched the RM46 example.

 

Configure the HET and DMA Interupt

 

Some of the Hercules members have specialised trigger options available in hardware.

One of those "easy-overrides"  called Alternative ADC Trigger Options is that you can trigger ADC from a few other internal peripherals without external connections.

We want to use a clocked ADC sequence. HET is a good candidate to generate those trigger blips.

 

image

There are other peripherals that could be used with similar result: the real time interrupt ant the ePWM. Both are also able to generate timed interrupts to the ADC.

 

Also the DMA interrupt needs to be set.

 

image

 

Configure Memory for DMA

 

This is a difficult exercise. I need to do some reading. I'll update the blog or write a follow up after that.

For DMA, the correct memory block must have correct cache attibutes.

A post I wrote about that earlier, that I'll reuse if possible: https://texasinstruments.hackster.io/jancumps/hercules-configure-memory-cache-for-dma-0945cd

 

Configure the Timer (HET)

 

HET1 pin 17 is used. It's one of the pins that are eligible to provide the internal alternate ADC interrupt.

 

image

Although it can be tricky to work with the HET, configuring it to generate a 30 kHz PWM isn't.

You select one of the 7 PWM slots, set it to pin 17 and set the period (30 kHz = 33.3.. µs).

 

Configure ADC

 

The ADC 1 is the one we use. Here's the config:

 

image

 

image

image

 

Firmware

 

That's 1-to-1 portable without changes, except for the header file names that are different.

 

/* USER CODE BEGIN (0) */
#include "HL_adc.h"
#include "HL_het.h"
#include "HL_sys_dma.h"
#include "HL_sys_core.h"
/* USER CODE END */

 

The enable interrupt on the TMS570 takes a mandatory parameter extra. The info on hat this should be is a little cryptic.

One more todo

 

    // todo: check if parameter 3 i INTA or Lockstep-specific INTB
    dmaEnableInterrupt(DMA_CH0, BTC, DMA_INTA);
    dmaEnableInterrupt(DMA_CH1, BTC, DMA_INTA);

 

With these actions, I have firmware that compiles. Ready to load it and check with a debugger...

  • Sign in to reply
  • DAB
    DAB over 4 years ago

    Nice post Jan.

     

    DAB

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