ADC 1 Module Acting Strange

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

ADC 1 Module Acting Strange

Jump to solution
1,423 Views
sparkee
Contributor V

I'm trying to move some of my ADC reads from ADC0 to ADC1 so that I can isolate the most important read to module 0 and use module 1 for all of the secondary data.  ADC0 works fine reading multiple channels using PDB single-shot and back-to-back triggering.  When I move to ADC1, it looks like my inputs are floating.  Stranger, when I point my heat gun at the board, the ADC reading rises (or drops depending on the input pin).  I have backed all the way out of my design and back to your ADC_PDB_Trigger sample.  Again it's working with ADC0 but when I change the pins to PTB0 and PTB1 using ADC1, it behaves erratically.  I've changed the trigger and the ADC Config from module 0 to 1.  I'm attaching for reference.  

PTB0 and PTB1 show to be pins 5 and 7 on J4 per the diagram.  Nothing I do to these pins causes any change in FreeMaster.  If I put voltage on pin 10 however, it acts just as I would expect it to.  The other ADC input seems to pick up on any voltage to pin 10 as well and somewhat mimics the voltage change (though very noisily and at roughly half the counts).  If I plug my voltage into pin 12, I get the second ADC to read normally.  Strangely, I don't get the mimic effect of pin 12 onto pin 10 the way pin 10 acted on pin 12.  Why is this behavior happening??  It seems the pins aren't lining up with the ADC options in Simulink.

pastedImage_1.png

1 Solution
1,299 Views
adriantudor
NXP Employee
NXP Employee

Hi sparkee‌,

The direction of your observations it's correct. 

As you can see in this picture ( S32K1xx Series Reference Manual, Rev. 12.1, 02/2020, page 1197), some of the ADC1 inputs can be switched. This function it's called "interleave". 

By default, as you can see here, those switches are in a position (that's the reason for the behavior that you observed when ADC1 was connected to PTB15 J4-10) that doesn't allow you to do what you tried (e.g.: to use ADC1 with pin PTB0). To switch those pins to ADC1, you have to add ADC interleave block. When you do that, let say for PTB0, then ADC0 and ADC1 will be connected to the same input pin. At this time for every SIM_CHIPCTL[x] (ADC switch), you have to add an ADC interleave block, but the function called by this block overwrites the previous one (not a correct behavior). For example, if you want to use interleave for PTC0 and PTC1, you will have to add two ADC interleave blocks,  but the second one will overwrite the effect of the first one (and PTC1 will be disconnected from ADC1). 

pastedImage_3.png

To overcome that you will have to add two blocks (see below): model header block (used to include "adc_interleave.h") and System initialize block used to call once the function "SIM_HAL_SetAdcInterleaveSel(SIM, 3);".

pastedImage_4.png

The second parameter is telling the interleave switches to switch the first two switches (SIM_CHIPCTL[0] and SIM_CHIPCTL[1]). This input parameter is formed by 4 bits (0b0011 in our case), where every bit it enables his corresponding switch. 

There is one more thing that you have to do, edit "mbd_s32k_user_copy_required_files.m" (path: src\mbdtbx_s32k\mscripts\utils) file to copy the header file to your build project. 

Here you have the project modified to have a correct mode of functioning and ".m" file.

We will add a fix for that after release, as a patch, because we have some models that use this ADC interleave block and we must test them all. 

Best regards,

Adrian

View solution in original post

6 Replies
1,299 Views
constantinrazva
NXP Employee
NXP Employee

Hello sparkee ,

You have a strange issue indeed - we'll look into it, but not for a few days as we're crammed with our release to come. We'll probably dive into this early next week - hope you understand.

Kind regards,

Razvan.

1,299 Views
sparkee
Contributor V

constantinrazvan.chivu sorry to bother you again but I have some new data and it might be an easy fix that you roll into the Toolbox update on Monday.

So it might have something to do with those pins being on the same channel of the ADC.  Pins 10/12 work with either PTB0/1 selected or PTB15/16 selected.  I just happened to notice that they share the same ADC channel.  That's the only pair that share a channel.  If I choose another pin (ex: PTA2) then the ADC works as expected on the pin expected so I think I've ruled out my software as the problem.  Might need to fix the block.

pastedImage_1.png

0 Kudos
1,300 Views
adriantudor
NXP Employee
NXP Employee

Hi sparkee‌,

The direction of your observations it's correct. 

As you can see in this picture ( S32K1xx Series Reference Manual, Rev. 12.1, 02/2020, page 1197), some of the ADC1 inputs can be switched. This function it's called "interleave". 

By default, as you can see here, those switches are in a position (that's the reason for the behavior that you observed when ADC1 was connected to PTB15 J4-10) that doesn't allow you to do what you tried (e.g.: to use ADC1 with pin PTB0). To switch those pins to ADC1, you have to add ADC interleave block. When you do that, let say for PTB0, then ADC0 and ADC1 will be connected to the same input pin. At this time for every SIM_CHIPCTL[x] (ADC switch), you have to add an ADC interleave block, but the function called by this block overwrites the previous one (not a correct behavior). For example, if you want to use interleave for PTC0 and PTC1, you will have to add two ADC interleave blocks,  but the second one will overwrite the effect of the first one (and PTC1 will be disconnected from ADC1). 

pastedImage_3.png

To overcome that you will have to add two blocks (see below): model header block (used to include "adc_interleave.h") and System initialize block used to call once the function "SIM_HAL_SetAdcInterleaveSel(SIM, 3);".

pastedImage_4.png

The second parameter is telling the interleave switches to switch the first two switches (SIM_CHIPCTL[0] and SIM_CHIPCTL[1]). This input parameter is formed by 4 bits (0b0011 in our case), where every bit it enables his corresponding switch. 

There is one more thing that you have to do, edit "mbd_s32k_user_copy_required_files.m" (path: src\mbdtbx_s32k\mscripts\utils) file to copy the header file to your build project. 

Here you have the project modified to have a correct mode of functioning and ".m" file.

We will add a fix for that after release, as a patch, because we have some models that use this ADC interleave block and we must test them all. 

Best regards,

Adrian

1,299 Views
sparkee
Contributor V

Wow that's a little more complex than I was expecting.  Thank you for the detailed answer and example.  I think in my next iteration I'll just do a physical change of the pins being used so we don't have to jump through hoops though. 

I see that this is documented in the Ref Manual but I feel like this is such a special use case that requires so much extra execution that maybe there needs to be a note in the drop down box referring you to the documentation of how to accomplish it so that a user can easily decide not to use the pins like this except as absolutely necessary.  It seems too easy to make this mistake without understanding the consequences.

Thank you again, I'm looking forward to the Toolbox update.

1,299 Views
constantinrazva
NXP Employee
NXP Employee

Hello sparkee ,

Thank you for investigating this issue - we will try and find a solution so we can roll it into our release.

Kind regards,

Razvan.

0 Kudos
1,299 Views
sparkee
Contributor V

Totally understand.  Looking forward to the release on Monday.

0 Kudos