EmbeddedRelated.com
Forums

Analog to Digital conversion

Started by leoshakeme March 3, 2006
Hi,
I am very new to microcontrollers. I am using a MC9S12DP256C on a 
trainer board. To develop I'm using CodeWarrior and C code. It is all 
overwhelming. 

I am trying to write a program that will compare two voltages and 
depending on which voltage is greater to send a digital signal to a 
stepper motor controller. 

My biggest problem stems from interfacing. I dont know how to 
initialize the ATD to obtain the voltages on pins PAD10 and PAD11 
using C code. Does anyone know a good tutorial or have some sample 
code? I appreciate any help, thank you.
	Regards,
Leo
	
Dear Leo,

Use the manuals supplied online for your controller as regards to the ATD
registers. Its pretty simple once you read it.

Secondly, search for this thread in the archives of the group. I had started
on the same lines as you a year ago, and I believe I had posted a similar
query. You may get useful results.

All the best!
Rahul

On 3/4/06, leoshakeme <leoshakeme@leos...> wrote:
>
>  Hi,
> I am very new to microcontrollers. I am using a MC9S12DP256C on a
> trainer board. To develop I'm using CodeWarrior and C code. It is all
> overwhelming.
>
> I am trying to write a program that will compare two voltages and
> depending on which voltage is greater to send a digital signal to a
> stepper motor controller.
>
> My biggest problem stems from interfacing. I dont know how to
> initialize the ATD to obtain the voltages on pins PAD10 and PAD11
> using C code. Does anyone know a good tutorial or have some sample
> code? I appreciate any help, thank you.
>
>
> Regards,
> Leo
>
>
>
>
>
>
>  SPONSORED LINKS
>   Fast
track<http://groups.yahoo.com/gads?t=ms&kt+track&w1t+track&w2=Microcontrollers&w3=Technical+support&w4=Intel+microprocessors&w5=Pic+microcontrollers&c=5&s4&.sig=nA8l9JqNmviNfMI5MX4wNQ>
>
Microcontrollers<http://groups.yahoo.com/gads?t=ms&k=Microcontrollers&w1t+track&w2=Microcontrollers&w3=Technical+support&w4=Intel+microprocessors&w5=Pic+microcontrollers&c=5&s4&.sig=R9keRDMYBnmeZHL4gCczKQ>
 Technical
>
support<http://groups.yahoo.com/gads?t=ms&k=Technical+support&w1t+track&w2=Microcontrollers&w3=Technical+support&w4=Intel+microprocessors&w5=Pic+microcontrollers&c=5&s4&.sig=Sd-HtLKo96IyTEbWeB8nhw>
  Intel
>
microprocessors<http://groups.yahoo.com/gads?t=ms&k=Intel+microprocessors&w1t+track&w2=Microcontrollers&w3=Technical+support&w4=Intel+microprocessors&w5=Pic+microcontrollers&c=5&s4&.sig=VAEnNl74YXlUuN2unFBtsg>
 Pic
>
microcontrollers<http://groups.yahoo.com/gads?t=ms&k=Pic+microcontrollers&w1t+track&w2=Microcontrollers&w3=Technical+support&w4=Intel+microprocessors&w5=Pic+microcontrollers&c=5&s4&.sig=qt-XTQmiIr-YEqxb2gGstw>
>  ------------------------------
> >.
>
>
>  ------------------------------
>
	--
Warm Regards,
Rahul.
	
	
Did you see the Processor Expert support for this chip?
Create a new project (File->New, select "HC(S)12 Project Wizard")
with 
Processor Expert, add two ADC beans to your project, enable "Sharing"
in 
the Bean Inspector and pick the right converters and ports, choose an 
acceptable conversion time, and it should generate all the code you need 
for the ADT interfacing.

Of course, if you want to learn how to set it up, well, then this might 
be a bit too easy. Do study their code. And also check the Freescale 
pdfs about the ADT.

Daniel
	leoshakeme wrote:
> Hi,
> I am very new to microcontrollers. I am using a MC9S12DP256C on a 
> trainer board. To develop I'm using CodeWarrior and C code. It is all 
> overwhelming. 
>
> I am trying to write a program that will compare two voltages and 
> depending on which voltage is greater to send a digital signal to a 
> stepper motor controller. 
>
> My biggest problem stems from interfacing. I dont know how to 
> initialize the ATD to obtain the voltages on pins PAD10 and PAD11 
> using C code. Does anyone know a good tutorial or have some sample 
> code? I appreciate any help, thank you.
>
>
> Regards,
> Leo
>
>
>
>
>
>
>  
> Yahoo! Groups Links
>
>
>
>  
>
>
>
>
	
Thank you for your reply!
   
  I've been reading through the manual but it just all goes over my head. I
learn a lot better from samples and examples but the manuals are very technical.
What threat do you mean to search? ie. search ATD?
   
  Thanks again!
   
  Leo
	Rahul Sangole <rahul.sangole@rahu...> wrote:
  Dear Leo,

Use the manuals supplied online for your controller as regards to the ATD
registers. Its pretty simple once you read it.

Secondly, search for this thread in the archives of the group. I had started
on the same lines as you a year ago, and I believe I had posted a similar
query. You may get useful results.

All the best!
Rahul

On 3/4/06, leoshakeme <leoshakeme@leos...> wrote:
>
>  Hi,
> I am very new to microcontrollers. I am using a MC9S12DP256C on a
> trainer board. To develop I'm using CodeWarrior and C code. It is all
> overwhelming.
>
> I am trying to write a program that will compare two voltages and
> depending on which voltage is greater to send a digital signal to a
> stepper motor controller.
>
> My biggest problem stems from interfacing. I dont know how to
> initialize the ATD to obtain the voltages on pins PAD10 and PAD11
> using C code. Does anyone know a good tutorial or have some sample
> code? I appreciate any help, thank you.
>
>
> Regards,
> Leo
>
>
>
>
>
>
>  SPONSORED LINKS
>   Fast
track<http://groups.yahoo.com/gads?t=ms&kt+track&w1t+track&w2=Microcontrollers&w3=Technical+support&w4=Intel+microprocessors&w5=Pic+microcontrollers&c=5&s4&.sig=nA8l9JqNmviNfMI5MX4wNQ>
>
Microcontrollers<http://groups.yahoo.com/gads?t=ms&k=Microcontrollers&w1t+track&w2=Microcontrollers&w3=Technical+support&w4=Intel+microprocessors&w5=Pic+microcontrollers&c=5&s4&.sig=R9keRDMYBnmeZHL4gCczKQ>
 Technical
>
support<http://groups.yahoo.com/gads?t=ms&k=Technical+support&w1t+track&w2=Microcontrollers&w3=Technical+support&w4=Intel+microprocessors&w5=Pic+microcontrollers&c=5&s4&.sig=Sd-HtLKo96IyTEbWeB8nhw>
  Intel
>
microprocessors<http://groups.yahoo.com/gads?t=ms&k=Intel+microprocessors&w1t+track&w2=Microcontrollers&w3=Technical+support&w4=Intel+microprocessors&w5=Pic+microcontrollers&c=5&s4&.sig=VAEnNl74YXlUuN2unFBtsg>
 Pic
>
microcontrollers<http://groups.yahoo.com/gads?t=ms&k=Pic+microcontrollers&w1t+track&w2=Microcontrollers&w3=Technical+support&w4=Intel+microprocessors&w5=Pic+microcontrollers&c=5&s4&.sig=qt-XTQmiIr-YEqxb2gGstw>
>  ------------------------------
> >.
>
>
>  ------------------------------
>
	--
Warm Regards,
Rahul.
	
	  SPONSORED LINKS 
        Fast track   Microcontrollers   Technical support     Intel
microprocessors   Pic microcontrollers 
    
---------------------------------
  YAHOO! GROUPS LINKS
	---------------------------------
	---------------------------------
Yahoo! Mail
Bring photos to life! New PhotoMail  makes sharing a breeze. 


	
Hi Leo

I haven't done much work with the ADC but did test it once (using 
MC9S12NE64 - I am assuming that it is more or less the same as in 
your chip).
Try the following, it may work for you - else use it as a starting 
point for your own project.
The ADC is initialised in 8bit mode for a 25MHz bus and the first 
conversion is started.
Then the value is read from ADC0 and the next conversion started.
Note that there is a conversion time requirement and I was polling 
quite slowly so didn't check any status registers.

Maybe it helps you make your first steps.

Cheers

Mark Butcher
www.mjbc.ch

void fnInitialise ADC(void)
{
  // Initialise ADC in 8 bit mode
 ATDCTL4 = 0xf3;    // 8 bit mode suitable for our bus speed (25MHz)
 ATDCTL2 = ADPU;    // power up the ADC
 ATDCTL5 = 0;       // start first conversion
}

unsigned char ucReadADC(void)
{
 unsigned char ucADCValue = (ATDDR0H);  // read the value

 ATDCTL5 = 0;       // start next conversion

 return ucADCValue ;
}
	--- In 68HC12@68HC..., "leoshakeme" <leoshakeme@...> wrote:
>
> Hi,
> I am very new to microcontrollers. I am using a MC9S12DP256C on a 
> trainer board. To develop I'm using CodeWarrior and C code. It is 
all 
> overwhelming. 
> 
> I am trying to write a program that will compare two voltages and 
> depending on which voltage is greater to send a digital signal to 
a 
> stepper motor controller. 
> 
> My biggest problem stems from interfacing. I dont know how to 
> initialize the ATD to obtain the voltages on pins PAD10 and PAD11 
> using C code. Does anyone know a good tutorial or have some sample 
> code? I appreciate any help, thank you.
> 
> 
> Regards,
> Leo
>