10 years, 6 months ago.

A/D pins

The drawing implies that there are only 5 A/D input pins. But I believe that the cpu allows others. On the other hand, when I tried PTC1, it didn't work. Can anyone clarify? Ie, what pins can be used as analog inputs on the KL25Z with mbed's AnalogIn()?

http://mbed.org/handbook/mbed-FRDM-KL25Z

Question relating to:

3 Answers

10 years, 6 months ago.

Hello Jon Z,

how can you tell it did not work? Here are MUX options for KL25Z ADC:

static const PinMap PinMap_ADC[] = {
    {PTE20, ADC0_SE0,  0},
    {PTE22, ADC0_SE3,  0},
    {PTE21, ADC0_SE4a, 0},
    {PTE29, ADC0_SE4b, 0},
    {PTE30, ADC0_SE23, 0},
    {PTE23, ADC0_SE7a, 0},
    {PTB0,  ADC0_SE8,  0},
    {PTB1,  ADC0_SE9,  0},
    {PTB2,  ADC0_SE12, 0},
    {PTB3,  ADC0_SE13, 0},
    {PTC0,  ADC0_SE14, 0},
    {PTC1,  ADC0_SE15, 0},
    {PTC2,  ADC0_SE11, 0},
    {PTD1,  ADC0_SE5b, 0},
    {PTD5,  ADC0_SE6b, 0},
    {PTD6,  ADC0_SE7b, 0},
    {NC,    NC,        0}
};

Provide some details, snippet of code. I can test it.

Regards,
0xc0170

Accepted Answer
Jon Z
poster
10 years, 6 months ago.

Thanks. Reads on PTC1 yielded nonsense values, using PTE23 made PTE20 not work. But PTE20, PTE22 and PTC2 all work fine. adc.read_u16().

Edit: turned out to be a program error (sorry), probably all pins work properly.

PTC1 is used as the RTC clock input by the mbed firmware. So that indeed will yield results which you aren't expecting.

posted by Erik - 02 Oct 2013
10 years, 2 months ago.

Hello,

I have tested the Analog Inputs base on your table above and found that the following don't work:

PTE23,PTE21 and PTB1

Any reasons???

Could have been a different topic/question ;).

First of all, which library do you use? mbed or mbed-src? (If you don't know it, it is the first one). Recently there has been a significant overhaul of the KL25's code, which is already rolled out in mbed-src, and not yet in mbed. That said AnalogIn behavior shouldn't have changed (but shouldn't isnt the same as hasn't).

Then when you say they don't work, how do you mean it? Does the mbed lock up? Does it always return 0? Random values?

If it hasn't been figured out by then I can probably look at it in the weekend. I have no idea why PTB1 wouldn't work. PTE23 and PTE21 are the only two AnalogIns which use a different setting of an internal multiplexer, so that is a possibly error.

Edit: And are you using any other AnalogIns at the same time?

posted by Erik - 06 Feb 2014

Hello Erik,

Thank you for your quick response.

Base on online compiler it seems Like I am using mbed and not mbed-src. I don't know how to switch to mbed-src.

  1. include "mbed.h"

Serial pc(USBTX,USBRX); DigitalOut led(LED1);

AnalogIn adc0(PTE30); AnalogIn adc1(PTE29); AnalogIn adc2(PTE23); AnalogIn adc3(PTE22); AnalogIn adc5(PTE21); AnalogIn adc6(PTE20); AnalogIn adc7(PTC1); AnalogIn adc8(PTC2); AnalogIn adc9(PTB3); AnalogIn adc10(PTB2); AnalogIn adc11(PTB0);

then I call adc2.read_u16() for PTE23, etc

if I connect 0 volts on PTE23 the call to the adc2.read_u16() returns a wrong value not 0. if I connect 3.3 volts on PTE23 then call to the adc2.read_u16() returns the wrong value not even close to 65535.

the same happens with PTE21 and PTB1. The other channels work OK.

How to fix this on the mbed lib?

posted by Moises Escobedo 07 Feb 2014

Hello Moises Escobedo,

the PTE21 and PTE24 are A channels, the register ADC0->CFG2 should be set accordingly. Can you investigate if A channel is selected? To find out mask that register with ADC_CFG2_MUXSEL_MASK, to get that bit if it's set or not. compare settings with the reference manual to see if it's set properly.

But why PTB1 does nto work is a mystery. Can you test only one adc channel at the time, just to confirm the properly settings first.

Regards,
0xc0170

posted by Martin Kojtal 07 Feb 2014

Hello Martin,

Thank you so much for your responses to my questions.

I have not been able to verify ADC_CFG2_MUXSEL_MASK.

I was able to get PTB1 to work. That was my mistake. I am not able to get PTE21 and PTE23.

Also I know that PTC1 is use for RTC In but I need PTC1 to function as Analog is there a quick way to force PTC1 to function as Analog?

posted by Moises Escobedo 10 Feb 2014

Martin,

As for PTC1 I can get it to work if I remove R24 from the board. R24 is 0 ohm resistor from OpenSDA Interface to the KL25Z PTC1 which is providing the RTC clock signal.

Removing R24 isolates PTC1 and then it functions OK as analog.

Now if I just get PTE21 and PTE23 I will be set.

Thank you.

posted by Moises Escobedo 10 Feb 2014