ATD using MC9S12XDT512

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

ATD using MC9S12XDT512

1,139件の閲覧回数
d0pplegangah
Contributor I

Hello everyone.  I'm having problems collecting an analog voltage from an infrared sensor using the MC9S12XDT512.  I'm very familiar with the MC9S12C32, so I'm trying to suit my code to this other microcontroller.  I'm only using one channel and one infrared sensor.  I have a DMM connected to the infrared sensor so I am able to match the voltage variable with the correct output voltage of the infrared sensor.  Here's my code:

 

void main(void) {

 

   float voltage;

  

   ATD0CTL2 = 0b11000000;

   ATD0CTL3 = 0b00001000;

   ATD0CTL4 = 0b10000001;   // 8-bit resolution

   ATD0CTL5 = 0b00000000;

 

   while(1) {

 

      voltage = (5 * (float)(ATD0DR0H / 256));

      ATD0CTL5 = 0b00000000;

 

   }

}

 

I've tested this code using the MC9S12C32 and its functional.  When I run this code using the MC9S12XDT512, it throws an error - voltage variable is always 0.  Any input and help would be appreciated.  Thanks in advance!

 

d0pplegangah

ラベル(1)
0 件の賞賛
返信
1 返信

725件の閲覧回数
kef
Specialist I

      voltage = (5 * (float)(ATD0DR0H / 256));

 

Here ^^ you first take integer ATD0DR0H and divide it by 256. Result is always 0. Then you convert 0 to float and multiply it by 5. Result is still 0.

0 件の賞賛
返信