AnsweredAssumed Answered

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

Question asked by Cesar Rabak on Oct 23, 2014
Latest reply on Oct 24, 2014 by Cesar Rabak

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 ):

 

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

**     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

Outcomes