Author Topic: Reading Analog to Digital Port  (Read 10104 times)

Offline Marco

  • Newbie
  • *
  • Posts: 21
    • View Profile
Reading Analog to Digital Port
« on: February 16, 2009, 04:53:22 PM »
Hi

I'm trying to figure out how to read analogue on the PAD on the MC9S12NE64, can someone please point me in the right direction?

Cheers

Marco
« Last Edit: February 18, 2009, 12:58:00 PM by Marco »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Reading Analog to Digital Port
« Reply #1 on: February 18, 2009, 02:45:02 PM »
Hi Marco

Here is a very old file which was used once to trigger sending Emails when ADC inputs measured values lower or higher than defined levels.
I haven't use this in a long time but at least you will see how to configure and read the ADC inputs on the NE64.

Regards

Mark

Offline Marco

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Reading Analog to Digital Port
« Reply #2 on: February 24, 2009, 01:41:32 PM »
Thanks Mark, that really put me on the right track.  I setup the port up so that it scans continiously, and set it to multi-channel Mode.

Code: [Select]
    static int State = 0;

    if(State==0)
    {
      ATDCTL3 = 0;       // Read all 8 Channels
      ATDCTL4 = 0xf3;    // 8 bit mode suitable for our bus speed
      ATDCTL2 = ADPU;    // power up the ADC
      ATDCTL5 = 0x30;       // Multi-Channel, Scan Mode
      State = 1;
    }

I just inserted this inside a looping function, and it only runs once.

Because the ADC scans continiously, I can just use ATDDR0H~ATDDR7H to aquire the ADC values.  I have tested all the ATD ports symoultaniously on the NeCore12Board, and it seems to work quite well.
« Last Edit: February 24, 2009, 08:12:37 PM by Marco »