ATD using MC9S12XDT512

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

ATD using MC9S12XDT512

802 Views
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

Labels (1)
0 Kudos
Reply
1 Reply

388 Views
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 Kudos
Reply