Author Topic: A/D Channels  (Read 16528 times)

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
A/D Channels
« on: November 17, 2008, 03:16:10 PM »
Hi Mark,
  Is it possible to only use, say, 1 a/d channel on the 52235, and the rest of the port as I/O?

Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: A/D Channels
« Reply #1 on: November 17, 2008, 04:34:45 PM »
Hi Neil

Yes, you can mix as you want.

See fnConfigureADC() in application.c for an example of using the ADC - it uses just one of the inputs (the others are free for GPIO use).

See also the following:
http://www.utasker.com/forum/index.php?topic=280.0

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: A/D Channels
« Reply #2 on: December 12, 2008, 03:27:18 PM »
Hi Mark,
  I have setup channel 4 for A/D reading as follows:

void fnConfigureADC(void)
{
   ADC_SETUP adc_setup;                                                 // interrupt configuration parameters
    adc_setup.int_type = ADC_INTERRUPT;                                  // identifier when configuring
    adc_setup.int_adc_bit = 4;                                           // ADC channel 0
    adc_setup.int_adc_mode = (ADC_CONFIGURE_ADC | ADC_CONFIGURE_CHANNEL | ADC_SEQUENTIAL_MODE | ADC_SINGLE_ENDED | ADC_LOOP_MODE | ADC_START_OPERATION); // single ended configuration in loop mode
    adc_setup.int_adc_speed = (unsigned char)(BUS_CLOCK/5000000);        // 5MHz sampling (must be between 100kHz and 5MHz)
    adc_setup.int_adc_int_type = 0;                                      // no interrupt
    fnConfigureInterrupt((void *)&adc_setup);                            // configure and start operation
   }

And read the channel every second as follows:

void fnReadVoltageMonitor(void)
{
    char Res[20];
     int result;

     while (!(ADC_ADSTAT & RDY_CHANNEL4)) //wait until conversion
     ;

    result=ADC_ADRSLT4; //get result
    result>>=3; //move result
   
     sprintf(Res,"A/D=%d\r\n",result);
    fnDebugMsg(Res);
}

When checking the pin directly I have 0.74v ( I have a variable resistor, so I can adjust the input). I get an a/d value of 1222. If I am correct this calculates to 0.984v, which is not right. If I vary the voltage I do get the result following.

I tried changing to ADC_PARALLEL_MODE but the reading were like it was floating.

Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: A/D Channels
« Reply #3 on: December 12, 2008, 09:46:11 PM »
Hi Neil

Your calculation seems correct to me. The measured value suggests 0.984V as long as you have 3.3V reference.
Are you measuring the value at the same time as you are sampling it? Or is the measurement (eg. with a voltmeter) pulling the voltage down a bit when measured and it reads higher when sampled (with voltmeter removed)? In other words are you sure that it is not a measurement error?

Check whether there is an offset programmed in ADC_ADOFS4. It should be zero per default though.

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: A/D Channels
« Reply #4 on: December 12, 2008, 10:03:46 PM »
Hi Mark,
  Thanks for the reply.

Im measuring it at the same time as sampling. Is there a reference pin? I thought it uses the 3.3v supply as the reference?

regards
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: A/D Channels
« Reply #5 on: December 12, 2008, 11:14:11 PM »
Hi Neil

There are 2 reference pins - VRH and VRL which are used as default - check that they are correctly powered.
Pins 70 and 71 on the smaller package, or 94 and 95 on the larger package.

Alternatively it is possible to use AN2 and AN6 as reference pins (flags ADC_HIGH_REF_AN2 and ADC_LOW_REF_AN6 when configuring).

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: A/D Channels
« Reply #6 on: December 13, 2008, 12:14:07 AM »
Hi mark,
 I assumed it had its own 3.3v reference, I overlooked this..

Regards
Neil

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: A/D Channels
« Reply #7 on: December 13, 2008, 12:30:13 AM »
Hi Mark,
  I found a voltage reference chip from microchip that gives out 2.5v. I assume this would give me a 12bit swing for the 2.5v, or is there a min value for vref? I cant seem to find this is the manual I have.

Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: A/D Channels
« Reply #8 on: December 13, 2008, 04:23:09 PM »
Hi Neil

The VREFL and VREFH can both be any value between VSS and VDDA [3.0V ..3.6V] (where VREFH is always higher than VREFL). Therefore 2.5V could be used a reference.

Usually the digital supply (filtered to improve its quality) is however used (3V3).

Regards

Mark

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: A/D Channels
« Reply #9 on: December 21, 2008, 01:00:21 PM »
Hi Neil

I was reviewing the M5223X errata (http://www.freescale.com/files/32bit/doc/errata/MCF52235DE.pdf) and was reminded of several restrictions concerning the ADC use:
1) - VREFH and VREFL are recommended to be used at the same potentials as VDDA (>=) and VSSA (< 50mV) otherwise the ADC value can make errors
2) - if VREFH is below 3.1V further errors can occur, so ensure it is > 3.1V (connecting to VDDA as 1 avoids this)
3) - It is recommended not to power down the ADC when the device is operated for extended periods above 70°C

Regards

Mark


Offline mcosta

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: A/D Channels
« Reply #10 on: March 12, 2009, 02:54:11 AM »
Hi Mark,

I am having troubles to read adc channel 1 on the M52233DEMO board.
The channel 0 is OK, but I can´t get the channel 1 to work. After that, I will need
the channel 2 and 3

I don´t need to use the adc with interrupts or tasks. Just need to send the values when
a snmp get is issued.

Can you send some ideias?

Regards,
Marcelo Costa

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: A/D Channels
« Reply #11 on: March 12, 2009, 10:58:16 PM »
Hi Marcelo

I just looked to see whether there are any known difficulties reading from channel 1 but couldn't find anything. I know that there was once a problem when you reading 4,5,6,7 without one of the inputs 0,1,2 or 3 : http://www.utasker.com/forum/index.php?topic=280.msg1156#msg1156

Are you using the ADC interface or reading directly? If you are having troubles reading directly I would do a test with each of the inputs using the standard interface to verify that they all read correctly to ensure basic operation.

Regards

Mark