ADC component generated by PE does not comply with A/D resolution chosen

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

ADC component generated by PE does not comply with A/D resolution chosen

Jump to solution
985 Views
cesarrabak
Contributor III

I'm using a FRDM-K20DM50 board, Code Warrior 10.6 (Build Id:140329), Processor Expert 10.3 [05.09].

I configured an ADC component to monitor the temperature sensor available in this board and connected to ADC0-DM3.

My choice was to read the temp sensor output with 12 bit resolution, and the results of the component generation can be seen in the headers of the AD1.c and AD1.h files, which the pertinent part I copy here (I think it is better than pasting a figure which would convey less information :smileycool:):

/* ###################################################################

**     THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.

**     Filename    : AD1.c

**     Project     : Temp_monitor

**     Processor   : MK20DX128VLH5

**     Component   : ADC

**     Version     : Component 01.697, Driver 01.00, CPU db: 3.00.000

**     Compiler    : GNU C Compiler

**     Date/Time   : 2014-10-23, 16:07, # CodeGen: 9

**     Abstract    :

**         This device "ADC" implements an A/D converter,

**         its control methods and interrupt/event handling procedure.

**     Settings    :

**          Component name                                 : AD1

**          A/D converter                                  : ADC0

**          Sharing                                        : Disabled

**          ADC_LDD                                        : ADC_LDD

**          Interrupt service/event                        : Enabled

**            A/D interrupt                                : INT_ADC0

**            A/D interrupt priority                       : medium priority

**          A/D channels                                   : 1

**            Channel0                                     :

**              A/D channel (pin)                          : ADC0_DM3

**              A/D channel (pin) signal                   : Temperatura

**              Mode select                                : Single Ended

**          A/D resolution                                 : 12 bits

**          Conversion time                                : 15.384615 µs

**          Low-power mode                                 : Disabled

**          High-speed conversion mode                     : Disabled

**          Asynchro clock output                          : Disabled

**          Sample time                                    : 0 = short

**          Internal trigger                               : Disabled

**          Number of conversions                          : 1

**          Initialization                                 :

**            Enabled in init. code                        : yes

**            Events enabled in init.                      : yes

**          CPU clock/speed selection                      :

**            High speed mode                              : This component enabled

**            Low speed mode                               : This component disabled

**            Slow speed mode                              : This component disabled

**          High input limit                               : 1

**          Low input limit                                : 0

**          Get value directly                             : yes

**          Wait for result                                : yes

**     Contents    :

**         Measure    - byte AD1_Measure(bool WaitForResult);

**         GetValue16 - byte AD1_GetValue16(word *Values);

**         Calibrate  - byte AD1_Calibrate(bool WaitForResult);

So far so good, and as can be seen above I also have a [getter] function for reading my temp values.

However, I find this function generated by PE to have a quirk which IMO does not comply with the expectation of a 12 bit value returning from the ADC and the operation executed (the shift which effectively multiplies the ADC reading by 16 doesn't add any worth for the program:

byte AD1_GetValue16(word *Values)

{

  if (!OutFlg) {                       /* Is output flag set? */

    return ERR_NOTAVAIL;               /* If no then error */

  }

  *Values = (word)((AD1_OutV) << 4U);  /* Save measured values to the output buffer */

  return ERR_OK;                       /* OK */

}

When I started the program and monitored the output I saw values well above 4095 in decimal and got puzzled!

I believe this is a bug, do you agree or am I missing something?

BTW: notice that the excelent tutorials in using the ADC (generally using the Freeedom board FRDM-Kl25Z) uses the default "Autoselect" option so this issue does not appear initially...

Regards,

--

Cesar Rabak

Labels (1)
1 Solution
510 Views
marek_neuzil
NXP Employee
NXP Employee

Hello Cesar,

I undestand you confusion about GetValue16 method but it is designed to return always 16 bits value, i.e. the maximal value is always 0xFFFF independently on the selected ADC resolution. It is sometimes usefull. In addition, when you select higher number of conversions (e.g. set the Number of conversions property to 16) you can obtain more precise value of the AD conversion. See also the help of the GetValue16 method:

GetValue16 - This method returns the last measured values of all channels. Compared with GetValue method this method returns more accurate result if the number of conversions is greater than 1 and AD resolution is less than 16 bits.

In addition, the user code dependency on AD resolution is eliminated.

If you want to get 12-bits value of the ADC use the GetValue method in your application. This method return the same value as is stored in the ADC register (e.g. 12 bits value when ADC resolution is 12 bits).

Best Regards,

Marek Neuzil

View solution in original post

2 Replies
511 Views
marek_neuzil
NXP Employee
NXP Employee

Hello Cesar,

I undestand you confusion about GetValue16 method but it is designed to return always 16 bits value, i.e. the maximal value is always 0xFFFF independently on the selected ADC resolution. It is sometimes usefull. In addition, when you select higher number of conversions (e.g. set the Number of conversions property to 16) you can obtain more precise value of the AD conversion. See also the help of the GetValue16 method:

GetValue16 - This method returns the last measured values of all channels. Compared with GetValue method this method returns more accurate result if the number of conversions is greater than 1 and AD resolution is less than 16 bits.

In addition, the user code dependency on AD resolution is eliminated.

If you want to get 12-bits value of the ADC use the GetValue method in your application. This method return the same value as is stored in the ADC register (e.g. 12 bits value when ADC resolution is 12 bits).

Best Regards,

Marek Neuzil

510 Views
cesarrabak
Contributor III

First of all, thank you for your comprehensive reply, and your kindness in understanding my confusion!

I'll keep this in mind when I design my systems.

Best regards,

--

Cesar Rabak

0 Kudos