ADC trigger by FTM directly on KV5x MBDT

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

ADC trigger by FTM directly on KV5x MBDT

Jump to solution
2,624 Views
CauTran
Contributor I

Hi, nxp service,
I would like to ask you a question about ADC and FTM. I want to trigger ADC by FTM0 directly.
I configure the software with MCUxpresso Configuration Tool. But, when I generate the code, I debug this code, I see that ADC ISR doesn't work. 

I attached the simulink and the configuration file. 

Please help me to know issues.

0 Kudos
1 Solution
2,452 Views
nxa11767
NXP Employee
NXP Employee

Hi @CauTran ,

 

You can configure two ADC channel, but you need to assign them to separate groups:

nxa11767_0-1639241692742.png

 

  In the interrupt handler, you can check the channel group register to see if conversion is done and read the converted value:

nxa11767_0-1639246727096.png

But you must configure the ADC channel assigned to group1 to be triggered by hardware event - software trigger is supported only on group 0 (you can see the information also in MCUX configuration tool as a tooltip in group selection for the channel but also in the processor reference manual).

You can try also to use the same conversion group for both channels with continuous conversion unchecked in the MCUX Configuration Tool file, and software trigger the conversion from Simulink alternatively on each channel (or at a user button press) by using the ADC Start Block. And in the ADC interrupt handler you add just one ADC Read block - will not matter what selection of the channel you do there, since the read on done on the conversion group and not on the channel (we need to rethink that block for the next release).

I hope this info helps!

Best regards,

Alexandra 

 

BR,
Alexandra

View solution in original post

0 Kudos
7 Replies
2,594 Views
nxa11767
NXP Employee
NXP Employee

Hi @CauTran ,

 

I've looked into your .mex file and I've noticed multiple missing settings that explains the problem with the generating code.

First, the Hardware Interrupt blocks is telling that there is no interrupt enabled in the .mex file for the ADC peripheral. It also telling that the user should use the Configure button to open the .mex file in MCUXpresso Configuration Tool and enable the ADC interrupts.

nxa11767_1-1636486992442.png

If you check the Interrupt request in Configuration Tool (ctrl+S to save the change) and then Update in the Interrupt Handler block you'll see the name of the ADC interrupt handler:

nxa11767_2-1636487154777.png

Same applies for the Start/Stop Hardware Interrupt block:

nxa11767_3-1636487209882.png

Because in the .mex file, Interrupt request is set to Not initialized:

nxa11767_4-1636487298998.png

Then you need to add the Start/Stop Hardware Interrupt block to insert the code that enables the ADC0_IRQn interrupt. (EnableIRQ call). The alternative of this block is to choose the Enabled in Initialization, that will insert the peripherals.c, in ADC0_init the EnableIRQ call and so you'll not need to use the ISR start stop block.

nxa11767_5-1636487471732.png

You've noticed that the Configuration Tool is showing an warning on Interrupt Request - the warning is saying:

nxa11767_6-1636487612253.png

The next step, is to configure and ADC channel in the .mex file:

nxa11767_7-1636487727086.png

Use the + button to add an ADC channel, select the channel number on which the conversion will happen, enable the interrupt on the channel and also initialize the channel. For channel number, the selection, the tool provides a drop-down with the pins that were set in the pins view for the ADC0 peripheral:

nxa11767_8-1636488068270.png

I recommend to take a look at the ADC examples in the toolbox - we have examples on configuring and using the ADC on polling mode - twrkv58f_adc_polling.mdl-, so no interrupts are being configured, and also on interrupts - twrkv58f_adc_interrupt.mdl-, that's the use case described above.

As for the FTM configuration, if no channels are being set then the FTM will act as a simple timer. To use it for input capture/dual edge capture, pwm generation you must add and configure the FTM channels:

 

nxa11767_9-1636488688200.png

In order to use the FTM update duty cycle block, you must configure at least one FTM channel for PWM generation. Also for FTM you can take a look at the examples from the toolbox.

 In our ADC examples, the conversion is triggered by software. For hardware trigger, the Use Hardware Trigger must be enabled in the .mex file:

nxa11767_10-1636488991276.png

And you must configure at lease one of the trigger pins in the Pins view:

nxa11767_11-1636489156861.png

I've looked into the manual for KV5x and it mentions that the ADC can be triggered by the PDB:

nxa11767_12-1636489249515.png

And the FTM can trigger the PDB:

nxa11767_13-1636489341714.png

Can you please give more details on the application that you want to build? with more information I can try to create a .mex file that will map your application needs.

Best regards,

Alexandra

 

0 Kudos
2,473 Views
CauTran
Contributor I

Hi @nxa11767 ,

I would like to have a question about ADC. Is there any problems if I use more than one channel in ADC16 channels configuration check box? 

If I do it, How about the process for ADC convert and get the ADC data?

0 Kudos
2,573 Views
CauTran
Contributor I

Hi @nxa11767 ,

When I want to configure 2 channels ADC to sample and converter. But when I configure like that, ADC module can not interrupt like one channel. 

 

0 Kudos
2,453 Views
nxa11767
NXP Employee
NXP Employee

Hi @CauTran ,

 

You can configure two ADC channel, but you need to assign them to separate groups:

nxa11767_0-1639241692742.png

 

  In the interrupt handler, you can check the channel group register to see if conversion is done and read the converted value:

nxa11767_0-1639246727096.png

But you must configure the ADC channel assigned to group1 to be triggered by hardware event - software trigger is supported only on group 0 (you can see the information also in MCUX configuration tool as a tooltip in group selection for the channel but also in the processor reference manual).

You can try also to use the same conversion group for both channels with continuous conversion unchecked in the MCUX Configuration Tool file, and software trigger the conversion from Simulink alternatively on each channel (or at a user button press) by using the ADC Start Block. And in the ADC interrupt handler you add just one ADC Read block - will not matter what selection of the channel you do there, since the read on done on the conversion group and not on the channel (we need to rethink that block for the next release).

I hope this info helps!

Best regards,

Alexandra 

 

BR,
Alexandra

0 Kudos
2,413 Views
nxa11767
NXP Employee
NXP Employee

Hi @CauTran ,

I've attached two models and their .mex files - one with two channels on same group and one with two channels on separate groups. For the latter, you need to configure for e.g PDB-ul to trigger the ADC conversion on group 1 (since group 1 can't be software triggered).

Hope this helps,

Alexandra

0 Kudos
2,407 Views
CauTran
Contributor I

Hi @nxa11767 ,

I saw your example files, but I have a question for you. 

My application is motor control and therefore, I need to measure phase currents and DC voltage. The measurement is a sequence and  triggered by FTM or PDB module. 

But, for your demo file, I have some confuses because, when I use both hardware trigger and software trigger ( ADC start block), the ADC interrupt will be not happen. 

Can you tell me how to configure ADC module based on my idea? 

0 Kudos
2,428 Views
CauTran
Contributor I

Hi @nxa11767 ,

Can you send me that demo file to deeply understand this issue? 

Thank you so much.

 

0 Kudos