Analog To Digital Conversion

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Analog To Digital Conversion

跳至解决方案
1,164 次查看
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;
 }
}

 

 


 
 

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
502 次查看
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 项奖励
回复
1 回复
503 次查看
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 项奖励
回复