MCF51EM256 - how to use >2 channels of an ADC device

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

MCF51EM256 - how to use >2 channels of an ADC device

757 Views
ArtyCF
Contributor II

Hello,

 

I'm struggling to try and make sense of the ADC driver, specifically for the MCF51EM256 microcontroller.  I am trying to understand how to use more than two channels on a given ADC device.  For example, if I open the "adc1" device and then open channels on that device the first two are opened successfully but anything after that fails.

 

Digging down through the call to fopen() I can see that in the function _adc_open() of module "adc.c" that the channels are always bundled in groups of 2 channels.  Once both of those channels have been assigned, any attempt to open another channel will fail because there is no free channel available.  Presumably the channels are bundled in pairs so that they can be triggered via the two outputs of the Programmable Delay Block (PDB).

 

However, I feel like I must be missing something here.  For the MCF51EM256 microcontroller the ADC1 there should be 6 channels that can be used to read external voltages.  Surely it should be possible to use more than just two of those at a time?

 

In general, this is what I am trying to do:

 

fpADC = fopen("adc1:", (const char *)&adcInit);  // Open file pointer to ADC

.

.

.

// Open individual ADC channels

 

// ADC_SOURCE_ADC1_ADPM1

fpADCChTempr = fopen("adc1:temperature", (const char *)&adcChTemprInit);

 

// ADC_SOURCE_ADC1_AD5

fpADCChVoltage = fopen("adc1:voltage", (const char *)&adcChVoltageInit);

 

// ADC_SOURCE_ADC1_AD10

fpADCChCurrent = fopen("adc1:current", (const char *)&adcChCurrentInit);


// ADC_SOURCE_ADC1_AD11

fpADCChLux = fopen("adc1:lux", (const char *)&adcChLuxInit);


 

Any suggestions would be greatly appreciated.

 

Thank you.

 

 

 

0 Kudos
4 Replies

486 Views
petr_uhlir
NXP Employee
NXP Employee

Hallo ArtyCF,

check \demo\3phmeter application. It demonstrates 3 phase power meter and its ADC configuration have opened multiple channels on each ADC.

486 Views
ArtyCF
Contributor II

Thanks for the reply r51423,

It turns out that I had discovered that 3-phase meter example just hours before your post and I was hoping that the answer would be in there.  Unfortunately the code in that example, as with all the other examples I have found, uses only 2 channels on each ADC device.

 

I just can't win here! :smileywink:

 

There must be a way to do this (that doesn't involve continually closing and opening channels).

0 Kudos

486 Views
petr_uhlir
NXP Employee
NXP Employee

ArtyCF,

sorry for misleading you. The ADC driver on MCF51EM256 was designed to support only 2 channels on each ADC module as was required for 3 phase electrical power meter design. It would be pretty complicated to reconfigure on-fly to other channels (opening - closing). So you have 3 options.

  1. Connect flux and temperature to other ADC if possible
  2. Modify ADC driver to support more channels on each ADC module
  3. Do not use ADC driver and write your own one which will suite your needs (I would go this way)
0 Kudos

486 Views
ArtyCF
Contributor II

No worries r51423, that example still contains a lot of useful infomation and insight into how to use the driver so I'm glad you brought it to my attention.

 

Fortunately I was able to change the pin assignments on the microcontroller before board layout started so to make my life easier (for now anyway) I have assigned no more than 2 channels per ADC device.

 

In the future I will probably go the route of your suggestion #3 so as to take advantage of all the ADC channels that are available.

 

Thanks again!

0 Kudos