ADC port definition, K20dx256Z

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

ADC port definition, K20dx256Z

1,295 Views
Cdn_aye
Senior Contributor I

Hi

I am trying to test our ADC on a custom board using mqx 3.8.1. and CW10.3. I downloaded and built the example mqx 3.8.1 app: adc_twrk40x256 without error, but this is set to use a twrk40dx256 and we are using our custom board with a k20dx256z part and not a Tower module.

We are using the bsp for the twrk40dx256, so I looked in the twrk40x256.h file and can see a definition for ADC1_SOURCE_AD1, but I don't know what that translates to; is this ADC1_DP1, or ADC1_DM1, or the differential pair??

We want to use a SE (single ended), ADC1_DM1 pin 15 for conversion. Can someone suggest how I go about making a definition for that channel please?

I tried following the declarations in the debugger but I do not get a specific define that I can relate to the base package. Thanks for the help.

Robert

Tags (5)
7 Replies

712 Views
BielikM
Contributor III

Hi Robert,

ADC1_DM1 is name of pin for differential negative input of ADC. You need to find assigned single ended ADC channel to this name.

Open RM of your chip. There is table  ADC1 Channel Assignment.(chapter 3.7.1.4.1 in K20P100M72SF1RM).

If you want to use ADC1_DM1 as single ended you need to check this input signal in right column of table (When DIFF is 0).

Then you need to check channel column to assign channel to your ADC1_DM1(Channel AD20 in my RM).

Now you are working with ADC1_SOURCE_AD20 in MQX and it should works.


PS.Make sure that your ADC driver use correct file for your chip family .(\mqx-repo\mqx\source\io\adc\kadc\adc_mk20.h).

Regards,

Martin

712 Views
Cdn_aye
Senior Contributor I

Hi Martin

Thank you for the help.

I can see the channel and input signal I want in the table, ADC0_DP1, but the problem I have is I do not know how to define this for MQX. I am using the example mqx project code adc_twrk40x256

  1. Do I have to rebuild any of the MQX libraries? If so where do I make the change
  2. I don't see where to set this as a Single Ended input. Normally I would expect to use an mqx _io_ctrl fcn. But I don't see this being done in the example either for single or differential setup
  3. I think my definition is ADC0_SOURCE_ADPM0, for SE ADC0_DP1 according to the table. Do I just add this to the code base where the control block structure is being filled in? This seems reasonable but again there is no element for SE in the structure

Can you recommend or point me to any other sample code to test the adc under MQX?

Thank you

Robert

0 Kudos

712 Views
Monica
Senior Contributor III

Hello Robert!

Was your question cleared out?

Keep us posted! :smileywink:

Monica

0 Kudos

712 Views
Cdn_aye
Senior Contributor I

Hi Monica

Thank you for checking; no it is not sorted out yet. I get the code to build, but it will only read once correctly then never again. Should I create a new discussion, or continue with this issue here? The sample code didn't work well for me.

Robert

0 Kudos

712 Views
c0170
Senior Contributor III

Hello,

continue discussion here if required and it's still not sorted out yet  :smileywink: Why does it read only once ? Have you checked flags in ADC registers? What does it return?

Regards,

c0170

0 Kudos

712 Views
Cdn_aye
Senior Contributor I

I do not know why it only reads 1 - 3 times. I tried changing the number of samples to a lower number but that did not change the problem result.

I think it is related to the PDB. We are using just the code for a single channel from the example code. It compiles and loads and runs without error, but after 1 - 3 samples always traps on the fail printf. I am assuming that it is the ADC not completing a read in the required time but I don't know.

Can you suggest anything for me to check?

Thanks

Robert

0 Kudos

712 Views
BielikM
Contributor III

Hi Robert

There are definitions in mentioned file (\mqx-repo\mqx\source\io\adc\kadc\adc_mk20.h). You can check MQX name of  your pin there. There is defined if the pin is single ended or differential. Name for ADC0_DP1 is ADC0_SOURCE_AD1. This name you can use as any other single ended channel and it should works.

Answers for your questions:

  1. You need to rebuild MQX libraries only if you change something inside lib code. But make sure that you are using correct  KADC driver for your kinetis family.
  2. You don't need to use _io_ctrl . Differential setup is in  pin definition.
  3. You should use ADC0_SOURCE_AD1 as i mentioned earlier. But  i am not sure if you checked it right in RM because in your first topic you was talking about ADC1_DM1 therefore single ended alternative should be also from ADC1 module.

Almost all kinetis board use potentiometer connect to differential input. We  used it in way i described.

adc_demo should be enough for testing. Other examples are more complex and not point only on ADC.

I hope this information's should help you.

Martin