AnsweredAssumed Answered

Analog To Digital Conversion

Question asked by Guest on May 6, 2010
Latest reply on May 6, 2010 by kef

Hello ,

I have tried analog input programming where the variable potentiometer  readings are converted into subsequent voltage levels. I am unable to retrieve the same on the simulator window.. what is wrong with the code? I am using an Evaluation board from Softech on code warrior version 5.0. I am looking forward for the correction of my code aand useful tips to understand and program the ADC of my controller..Here is the code,

 

#include<hidef.h>
#include<mc9s12xdp512.h>
#pragma LINK_INFO DERIVATIVE "mc9s12xdp512"

void ATD_init(void);
void ATD_CONV(void);

unsigned long int voltage;
unsigned int pot_value, ix;

void main (void)
{
 ATD_init();
 for(;:smileywink: 
{
 ATD_CONV();   
 }
}

void ATD_init(void)
{
ATD1CTL2  = 0x80;  /*ATD power up enable*/
ATD1CTL3  = 0x20;  /*4 conversions per sequence; conversion in freeze mode*/
ATD1CTL4  = 0x00;  /*10-bit resolution;2 convrsn clk periods;prescalar divide by 2*/
ATD1CTL5  = 0xAA;  /*right justified;analaog channel 10, scan*/
ATD_CONV();
}                                                                
void ATD_CONV(void)
{
 {
  pot_value =  ATD1DR0;
 voltage   =  ((long)pot_value*5000)/1024;
 }
}

 

 


 
 

Outcomes