Using ATD on HCS12 microprocessor

Posted on 2009-05-02
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
  • 3
  • 2
LVL 22

Accepted Solution

NovaDenizen earned 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The Rasberry PI is a low cost piece of hardware that you can have a lot of fun with through experimenting and building/working on projects like media players, running a low cost computer, build data loggers etc. - see:
this article is a guided solution for most of the common server issues in server hardware tasks we are facing in our routine job works. the topics in the following article covered are, 1) dell hardware raidlevel (Perc) 2) adding HDD 3) how t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now