Solved

Using ATD on HCS12 microprocessor

Posted on 2009-05-02
5
2,909 Views
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:
http://www.ece.utep.edu/courses/web3376/Dragon12_files/Dragon12_Large.jpg

ATD Block User Guide (specific info on the registers related to the ATD)
http://www.cse.yorku.ca/course/3215/labs%20documentation/S12ATD10B8CV2.pdf

HCS12 Block Diagram (note the  ATD0 and ATD1 blocks, those are the magic components)
http://www.technologicalarts.com/myfiles/jpeg/9s12xdp512block.jpg

HCS12 Microprocessor Complete Documentation:
http://www.cse.yorku.ca/course/3215/labs%20documentation/MC9S12DP256.pdf

Dragon12 Schematic:
http://www.cse.yorku.ca/course/3215/labs%20documentation/DRAGON12_Schematics.pdf

Example code that may or may not work:
http://users.ece.utexas.edu/~valvano/programs/adtest.c
0
Comment
Question by:Frosty555
  • 3
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
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.

ATDCTL2:
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.

ATDCTL3
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.

ATDCTL4:
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.

ATDCTL5:
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:
initialization:
    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
0
 
LVL 31

Author Closing Comment

by:Frosty555
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!
0
 
LVL 22

Expert Comment

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

Author Comment

by:Frosty555
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! :)
0
 
LVL 22

Expert Comment

by:NovaDenizen
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

910 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

17 Experts available now in Live!

Get 1:1 Help Now