Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Using ATD on HCS12 microprocessor

Posted on 2009-05-02
Medium Priority
Last Modified: 2012-06-27
This is a really long shot, but here goes.

I am working on a lab. It is a school assignment. We are working on creating a simple C program that is downloaded to a Dragon12 Development Board. The program runs on the HCS12 microprocessor.

The point of the lab is to read in an analog signal, and display it's value on a seven segment display.

To do this you have to set a number of control registers, and configure the board so that the ATD works properly and samples at a reasonable rate. Enable the ATD, and finally capture input every time an interrupt is triggered (again by reading some more registers). Probably there's some special cleanup you have to do in the interrupt as well to prepare for another read.

Most of the code I have done. I can download programs to the board, I can access the registers by name, I know how to hook into interrupts on the board and setup interrupt service routines.

What I don't understand is just the idea of how this particular microcontroller / development board uses the ATD. What's the process by which the data flows from it's analog state, to an appropriate variable in my program? The documentation is very cryptic.

Any help before Monday would be greatly appreciated.

Some reference material:

Picture of a Dragon12 Development Board:

ATD Block User Guide (specific info on the registers related to the ATD)

HCS12 Block Diagram (note the  ATD0 and ATD1 blocks, those are the magic components)

HCS12 Microprocessor Complete Documentation:

Dragon12 Schematic:

Example code that may or may not work:
Question by:Frosty555
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 22

Accepted Solution

NovaDenizen earned 2000 total points
ID: 24296705
Everything is in the "Complete Documentation" pdf.

Figure 111 on page 573 shows all the control registers you use to manage the ATD.

The register map on pages 559-560 show the individual control/status bits.

ATDCTL0 and 1 are reserved, so ignore them.

ATDCTL2 and 3 control the configuration of the ATD module.  You choose a value for all the control bits, put them together into bytes, then write these bytes to each control register.

ADPU : set to 1, you want it powered on and working.  This needs to be set for a little while before the ATD module can be used.  How long?  I don't know.
AFFC:  do you want to use a polling loop to check for the conversion complete flag, or do you want to be interrupted?  I suspect a polling loop will do because you don't have anything better to do.  So set this to 0 to use normal mode
AWAI:  I don't think you need to worry about power consumption, so set this to 0
ETRIGLE, ETRIGP, ETRIGE, see table 96 on page 566.  You are using an internal timer, not an external trigger, so you only need to make sure you set ETRIGE to 0.  Might as well set the other two to 0 too.
ASCIE:  I assume you will be polling the conversion complete flag, so disable the interrupt.  set to 0.
ASCIF:  This is read-only, so don't worry about it.

bit 7 is ignored.
S8C,S4C,S2C,S1C: You are only doing one conversion at a time, so set them to 0,0,0,1 respectively.
FIFO:  Enabling this causes each new conversion to be written into the next result register, cycling around the result registers.  You don't want this, it should just write each result into the same register every time.  So set it to 0.
FRZ0,FRZ1:  depends on how you want the debugging behavior to be. If you're not debugging, anything will do here.

ATDCTL4 and 5 are special registers, in that they enable you to configure the ATD module, and they trigger a whole ATD conversion sequence when you write to either one of them.  If you write to one of them while it is in the middle of a conversion sequence, the sequence is aborted and a new sequence begun.

SRES8: I'm guessing you want 10-bit resolution, not 8.  So set it to 0.
SMP1,SMP0:  This controls how long the ATD takes to carefully store a copy of the original signal's value into the sample storage capacitor.  Longer is a little better.  Time isn't a critical factor, so might as well use the highest setting.  Set to 1 and 1.
PRS4-0:  I don't understand the ramifications of this setting.  Maybe performance vs. power consumption?  So just pick a value somewhere in the middle.  0/1/0/0/0 or so.

DJM:  You probably want the result right-justified since you're just displaying it and not doing any fancy math with it.  So set it to 1.
DSGN:  We're using right-justified mode, so set it to 0.
SCAN: just want to do one conversion each time, so set to 0.
MULT:  Only want one channel, so set to 0.
bit 3 is ignored
CC/CB/CA: channel 0 right?  So set to 0/0/0

You only need to check one bit in the ATDSTAT register, and it can be either SCF or CCF0.

So the whole process goes like this:
    Write configuration values to ATDCTL2, ATDCTL3, and ATDCTL4.  Writing to ATDCTL4 triggers a conversion sequence whose result we can ignore.

When a timer interrupt occurs:
    Write the control value to ATDCTL5.  
    Poll the ATDSTAT register until a completion bit is set.  
    Read the result value out of ATDDR0H and ATDDR0L.  
    Send the result value to the 7-segment display
LVL 31

Author Closing Comment

ID: 31577272
Awesome work, that's bang on. It's too late, though, I already did the lab. But everything you said was exactly how I ended up doing it. Thanks!
LVL 22

Expert Comment

ID: 24305766
I miss this sort of project.  I've barely touched electronics since I graduated college.
LVL 31

Author Comment

ID: 24306565
:( that's discouraging, i was hoping i'd be doing this kind of stuff out in the real world

It's too bad I only have one more lab left. But if I run into trouble maybe I'll post another question up in math/science! :)
LVL 22

Expert Comment

ID: 24306686
I've been programming for a living, and my jobs haven't given me any opportunities to do it.  I haven't been motivated enough to make it a hobby, either.  If you look for it, you could probably find an opportunity to do electronic engineering for a living.

Featured Post

Take our survey for a chance to win!

As a valued customer of Targus, we’d like to ask you a few questions about us. As thanks, you will be automatically entered for a chance to win a $500 VISA gift card. To enter, just complete the survey by September 15, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
If you're a modern-day technology professional, you may be wondering if certifications are really necessary. They are. Here's why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question