Analog To Digital Conversion

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Analog To Digital Conversion

ソリューションへジャンプ
1,487件の閲覧回数
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 解決策
825件の閲覧回数
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 返信
826件の閲覧回数
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 件の賞賛
返信