How to add AD IOs in the LWADC example?

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

How to add AD IOs in the LWADC example?

Jump to solution
1,956 Views
franciscolocate
Contributor I

Hello,

I´m having trouble trying to add adc IOs in the LWADC example located in C:\Freescale\Freescale_MQX_4_1\mqx\examples\lwadc.

In order for the example to run, it is defined by default "BSP_ADC_POTENTIOMETER" as "ADC1_SOURCE_AD20" in twrk60n512.h.

The problem is: I don´t know what to define to make the other ADC inputs work.

I saw in the file adc_mk60.h a list of defines linking all the ADC_SOURCE_CHANNELS, but I can´t make a connection between those source channels and physical pins in my TWRK60N512.

Can someone help me with that?

Thank you very much.

Best regards,

Francisco S. Locatelli

Tags (3)
0 Kudos
1 Solution
1,488 Views
DavidS
NXP Employee
NXP Employee

Hi Francisco,

I have reproduced what you said you have tried.  I used the TWR-K60N512, soldered a wire from Primary side pin A30 to the POT wiper R52 pin 2.

I changed the twrk60n512.h header to use the ADC1_SOURCE_AD19 for the BSP_ADC_POTENTIOMETER #define.

Re-compiled BSP, then lwadc MQX application and ran.  I can see expected results.

Regards,

David

View solution in original post

0 Kudos
12 Replies
1,488 Views
pasini
Contributor I

Hi all

I am having the same problem with TWR-K60N512 to read other ADCs.

What exactly should I change in my code and in the BSP to allow correct connection between the ADC peripheral the pins ?

Where can I find the correct analog pins specification and usage ?

Thanks in advance

Pasini

0 Kudos
1,488 Views
DavidS
NXP Employee
NXP Employee

Hi Pasini,

Please look at Reference Manual Chapter 3 and 10 to find ADC connections.  Link below.

There are also good appnotes to review from the K60 Product page:

K60_100 |Kinetis K60 100 MHz MCUs|Freescale

Look for:

AN4373 Cookbook for SAR ADC measurements

AN4590 Using DMA to emulate ADC flexible scan mode on Kinetis K

AN4568 Understanding the 16-bit ADC PGA in Kinetis K Series

AN4410 FlexTimer and ADC synchronization for Field-Oriented-Control

And others...

http://cache.freescale.com/files/32bit/doc/app_note/AN4590.pdf?fasp=1&WT_TYPE=Application%20Notes&WT...

Regards,

David

0 Kudos
1,488 Views
franciscolocate
Contributor I

Hello David.

Thank you for your repply.

Coud you please post the link for the Reference Manual you mentioned?

My MQX_REFERENCE_MANUAL only has 3 chapters.

Best regards,

Francisco S. Locatelli

0 Kudos
1,488 Views
DavidS
NXP Employee
NXP Employee

Hi Francisco,

The Reference Manual I am referring to is the device/chip/MK60 and not MQX.  You actually have a link to it in above post:

In the document http://cache.freescale.com/files/32bit/doc/ref_manual/K60P144M100SF2V2RM.pdf , page 123, the table lists AD19 to the input ADC1_DM0.

Using MQX with ADC the following appnote is good read:

http://cache.freescale.com/files/32bit/doc/app_note/AN4590.pdf

http://cache.freescale.com/files/32bit/doc/app_note/AN4590SW.zip

Regards,

David

0 Kudos
1,488 Views
franciscolocate
Contributor I

Hello David,

I added the #define BSP_ADC_INPUT_0                 (ADC1_SOURCE_AD19) to the twrk60n512.h file, expecting to read the channel from the input ADC1_DM0, but all I get is a trash signal around 1000mV, as described before.

I can´t use the REGs directly because we have a project rule to use only high level funcions so it will be an easy legacy to maintain with easy processor porting, so I can only use the MQX drivers.

All I need to do is an ADC in other pins as it is made to the potentiometer in the MQX LWADC example;

I don´t know what else to do.

Thank you very much.

Best regards,

Francisco S. Locatelli

0 Kudos
1,489 Views
DavidS
NXP Employee
NXP Employee

Hi Francisco,

I have reproduced what you said you have tried.  I used the TWR-K60N512, soldered a wire from Primary side pin A30 to the POT wiper R52 pin 2.

I changed the twrk60n512.h header to use the ADC1_SOURCE_AD19 for the BSP_ADC_POTENTIOMETER #define.

Re-compiled BSP, then lwadc MQX application and ran.  I can see expected results.

Regards,

David

0 Kudos
1,488 Views
franciscolocate
Contributor I

Hello, David.

My twr proto board was mounted wrongly, so I was reading from the secondary pins by mistake.

It works just fine, thank you very much!

Best regards,

Francisco S. Locatelli

0 Kudos
1,488 Views
DavidS
NXP Employee
NXP Employee

Hi Francisco,

I have done that before as well.

Thanks for sharing.

Regards,

David

0 Kudos
1,488 Views
soledad
NXP Employee
NXP Employee

Hello Francisco,

Please check the below thread, you can find a document that shows how add a LED pin for the BSP TWR-K70FN1M board. The procedure is the same for other ports and peripherals, using Kinetis devices.

MQX GPIO. How to add LED pins to the default BSP configurations

Please let me know if this helps!!


Have a great day,
Sol

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

1,488 Views
franciscolocate
Contributor I

Hello, Sol.

Thanks for your repply.

I found your example very usefull, but in the LWADC example, the ADC readings from the potentiometer channel are made without the configurations described by your example.

It is simply made a "#define BSP_ADC_POTENTIOMETER                  (ADC1_SOURCE_AD20)" in (your_board).h and it is working.

By following this define, searching for "ADC1_SOURCE_AD20" through all the build libs, I can´t find a reference to a specific pin.

I suppose that another simple "#define" should make de ADC through a specific pin.

Thank you!

Best regards,

Francisco S. Locatelli

0 Kudos
1,488 Views
soledad
NXP Employee
NXP Employee

Hello Francisco,

Please check the adc_mk60.h file located at the path C:\Freescale\Freescale_MQX_4_1\mqx\source\io\adc\kadc

This file contains the ADC1_SOURCE_AD20 definition

#define ADC1_SOURCE_AD20   (ADC_SOURCE_MODULE(2) | ADC_SOURCE_MUXSEL_X | ADC_SOURCE_CHANNEL(20))

Then please check the lwadc_kadc.h file located at the same path (C:\Freescale\Freescale_MQX_4_1\mqx\source\io\adc\kadc)

Regards

Sol

1,488 Views
franciscolocate
Contributor I

Hello Sol,

Thanks again for your repply.

After reading the files you pointed, I added the following line to the "twrk60n512.h" file: "#define BSP_ADC_INPUT_0                 (ADC1_SOURCE_AD19)".

In the document http://cache.freescale.com/files/32bit/doc/ref_manual/K60P144M100SF2V2RM.pdf , page 123, the table lists AD19 to the input ADC1_DM0.

In the twrk60n512 schematics, i found that the ADC1_DM0 is connected to the A30 pin in my twrk60n512, so I soldered a wire and put voltage signals ranging from gnd to Vcc.

The convertion is not working properly, as it is not varying with the input. It only shows a trash signal around 1000mV, independent of whatever I put in the input.

In my routine I:

Initiate the LWADC with the function: _lwadc_init_input(&input0,BSP_ADC_INPUT_0);

Attempt to read the ADC with the funciont: _lwadc_read_average(&input0, 10, &percentinput0);

Print the result of the convertion with the function: printf("input0 = %3d\r\n",percentinput0);

Can you help me with that?

Thank you very much.

Best regards,

Francisco S. Locatelli

0 Kudos