Unclear behaviour of ADC_Enable/Disable

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

Unclear behaviour of ADC_Enable/Disable

917 Views
mkrug
Contributor II

Hello,

I just discovered a behaviour of the PE ADC Component. I tried to use the ADC_Enable/Disable Methods. First I realized that the enable method did not turn on my ADC as expected. However if I set the marker on 'enable in init code' it starts working. So in a second stage I tried ADC_Disable and realized that it works as expected. However turning on the ADC right after disabling failed again. So I looked into the generated code. I was surprised because in disabling the code does something I would expect. It changes the configuration bits in the ADC to disable it:

LDD_TError Potentiometer_Disable(LDD_TDeviceData *DeviceDataPtr)

{

  ((Potentiometer_TDeviceDataPtr)DeviceDataPtr)->EnUser = FALSE; /* Set the flag "device disabled" */

  ADC_PDD_SetConversionTriggerType(ADC1_BASE_PTR, ADC_PDD_SW_TRIGGER); /* Select SW triggering */

  ADC_PDD_WriteStatusControl1Reg(ADC1_BASE_PTR, 0U, 0x1FU); /* Disable device */

  return ERR_OK;                       /* If yes then set the flag "device enabled" */

}

If you look in the enable code there is no access to the ADC configuration registers. It just changes a field in the LDD_TDeviceData. But that has no influence on the behaviour of the actual hardware.

LDD_TError Potentiometer_Enable(LDD_TDeviceData *DeviceDataPtr)

{

  ((Potentiometer_TDeviceDataPtr)DeviceDataPtr)->EnUser = TRUE; /* Set the flag "device enabled" */

  return ERR_OK;                       /* If yes then set the flag "device enabled" */

}

Does anyone understand the different behaviour of these functions?

Best Regards

Markus


0 Kudos
Reply
3 Replies

742 Views
jch
NXP Employee
NXP Employee

Hi Markus,

On the ADC like on Kinetis, there is not Enable bit to enable/disable the hardware. The ADC is only in some very low power mode if it doesn't make conversions. So this is the answer why it is not hardware access in the Enable() method.

To disable ADC you need to set the ADC_SC1[ADCH] bits to 31, this is what you can see in the Disable() method.

So you needn't to write any bits to enable the ADC.

If you want to start measurement:

1) Select channels which you want to use inside the A/D channel list property group

2) Two options are here:

a) Create the predefined sample groups inside the Static sample groups - here you can choose from before selected channels and specified the sample groups (on Kinetis it is posible to have just one channel inside the sample group by default, but you can by Enabling Discontinuous mode property add channels up to number of HW trigger - in this case you can measure by StartLoopTriggeredMeasurement() method from more channels each from different HW trigger).

b) Create during runtime the sample group by CreateSampleGroup() method in format specified by hint of the method.

3) Enable by Enable in init. code property or in code by Enable() method the state of driver.

4) Load/prepare to be loaded sample group to HW by SelectSampleGroup() method in case 2a or CreateSampleGroup() method in case 2b

5) Select appropriate Start method to start the measurement.

6) And after the measurement is complete you can read the results by the GetMeasuredValues() method.

For more information how to use ADC_LDD please right click on the component and select Help on Component and see the Typical Usage page: ADC_LDDTypical Usage.html.

Hope it is more clear now

Jiri

742 Views
mkrug
Contributor II

Hi Jiri,

thanks for your explaination. I can better understand now what happens. However I do not understand the total different behaviour of a pair of functions that should be somehow a complement of each other.

That might be worth of rethinking for one of the next PE versions - or at least a comment that explains what happens. Because currently the comment does not tell you that enable does not enable - actually it tells that enable does enable.

Best Regards

Markus

0 Kudos
Reply

742 Views
jch
NXP Employee
NXP Employee

Hi Markus,

The component itself is general for more families = same API, that's the one of the ProcessorExpert benefits.

So if on other ADC device the enable bit will be present, you can see that there will be the enable sequence, like on some DSCs. But on Kinetis this method enables the driver only, means that the methods will not return ERR_DISABLED if you call them after Enable() method.

I hope you understand this now better.
Jiri

0 Kudos
Reply