KV30x ADC_SE4a Issue

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

KV30x ADC_SE4a Issue

1,029 Views
nicolag
Contributor II

Hi, I'm trying to develop a new board with the MKV30F64VMF10 and I'm testing my new hardware now; The problem I have is readind ADC in single-ended on ADC0_SE4a because I have a big value ascillation. I started with Processor Expert but after a while I started with a new empty project. My very simple code is this:

/* Write your code here */

//16 bit unsigned result

unsigned short Value;

  //Enable port E

  SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK;

  //Enable ADC0    

  SIM_SCGC6 |= SIM_SCGC6_ADC0_MASK;

  //ADC0 in 16bit mode, long time sample, input clock / 8

  ADC0_CFG1 = ADC_CFG1_ADIV(3) | ADC_CFG1_ADLSMP_MASK | ADC_CFG1_MODE(0x03);

  //Disable conversion

  ADC0_SC1A = ADC_SC1_ADCH(31);

//my loop

for (;;) {

  //select AD4 (ADC0_SE4a) and start the conversion

  ADC0_SC1A |= 4 & ADC_SC1_ADCH_MASK;

  //Wait while conversion is in progress

  while(ADC0_SC2 & ADC_SC2_ADACT_MASK);

  //Wait until conversion complete

  while(!(ADC0_SC1A & ADC_SC1_COCO_MASK));

  //Delay between end of conversion and read value (nedeed???)

  Delay(0xFFFF);

  //Read 16 bits conversion value

  Value = ADC0_RA;

}\\ end of loop

//The simpliest delay function...

void Delay(unsigned long Ritardo) {

  while (Ritardo) {

  Ritardo--;

  }

}

If I force elettrically the input pin (n° 3 in my package) to GND I always read values from 48000 to 52000 (but I expect to read about 0). If I put 1.2V on the same pin I read values from 44000 to 50000 (but I expect to read about 23800... If I do the same things with ADC0_SE17 (pin 10, changing the bolded line with the neew ADC0_SC1A |= 17 & ADC_SC1_ADCH_MASK) or ADC0_SE15 (pin 22, chancging the same line with ADC0_SC1A |= 15 & ADC_SC1_ADCH_MASK) I read about 0 in the first sample and about 24000 in the second... CORRECT!

What I'd like to know is if there are differences between ADx channels and ADxa/ADxb channels. (ADC0_SE4a and ADC0_SE15 for example)

Data sheet about MKV30F64VMF10 reports:

ADC0.png

Is there something I don't understand on how to use this channels?

I thank you in advance for your help.

Regards,

Nicola

0 Kudos
Reply
3 Replies

699 Views
EarlOrlando
Senior Contributor II

Hello Nicola,

The ADC has a multiplexer for the channels. The channels which don't have any letter (i.e. ADC0_SE12) can be read from either the A channels or the B channels. However, if the channel has a letter at the end (i.e. ADC0_SE4a or ADC0_SE4b) it only can be converted from the A "side" or the B "side" of the multiplexer, depending on the case. In this case the "side" A is OK. It is configured through the register ADC0_CGF2[MUXSEL].

I can see a potential error in your code. When you start a channel conversion you assign to the ADC0_SC1A register the actual value OR the new channel. It is incorrect because you never clear the old channel for the conversion.

  ADC0_SC1A |= 4 & ADC_SC1_ADCH_MASK;

I think that you must replace that line with:

  ADC0_SC1A = 4 | (ADC0_SC1A & ~ADC_SC1_ADCH_MASK);

Please let me know if this solves your problem.

Best regards,

Earl.

0 Kudos
Reply

699 Views
nicolag
Contributor II

Hi Earl, first of all I thank you for your answer. About the MUXSEL I saw it and, like you can see, I left the ADC0_CFG2 at reset state where MUXSEL bit is 0, meanings A "side" of the multiplexer (ADC0_SE4a is A "side"; I also try to set MUXSEL bit but nothing change...)

Regarding the ADC0_SC1A setting to start conversion you're right; infact I changed it after I had written post on community. My new line, similar but not like yours, was:

ADC0_SC1A = 4;

(this because I don't want interrupt, AIEN = 0, I want single ended, DIFF = 0, and COCO is only a reading bit)

And I made the same tests with your line code but nothing changed. It seems that when I use an "a" or "b" channel I can't read right values, when I use "normal" channel (no ending with a or b) all is correct.

Any other ideas?

I thank you for your help.

Best regards,

Nicola

0 Kudos
Reply

699 Views
isaacavila
NXP Employee
NXP Employee

Hello Nicola,

We have agreed that this issue was related to damage on Microcontroller. Once you replaced this MCU for another one and ran your test you could get ADC readings withouth problems.

About selecting this signal when using PEx tool, We have already reported this bug to Processor Expert Team and they are working on fsl_adc component. This error is reported for channels that share one pin by two channels, i.e. when one pin can be used as two different ADC channels in the single ended mode the fsl_adc component cannot select the channel number according to the pin.

I hope this has helped you, if you have another doubts please do not hesitate on share them with us.

Best Regards,

Isaac

----------------------------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

----------------------------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply