Analog To Digital Conversion

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Analog To Digital Conversion

Jump to solution
1,150 Views
admin
Specialist II

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;
 }
}

 

 


 
 

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
488 Views
kef
Specialist I

ATD1CTL5  = 0xAA;  /*right justified;analaog channel 10, scan*/

In comment I see channel 10. ATD1CTL5 Cx bits are also set to 10(0xA). I don't have EVB schematics, but please note that PAD10 pin is wired to ATD1 channel 2. If potentiometer is wired to PAD10, then you need to set Cx bits to 2.

View solution in original post

0 Kudos
Reply
1 Reply
489 Views
kef
Specialist I

ATD1CTL5  = 0xAA;  /*right justified;analaog channel 10, scan*/

In comment I see channel 10. ATD1CTL5 Cx bits are also set to 10(0xA). I don't have EVB schematics, but please note that PAD10 pin is wired to ATD1 channel 2. If potentiometer is wired to PAD10, then you need to set Cx bits to 2.

0 Kudos
Reply