Events Synchronization using CTU in MPC57x (Model Based)

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

Events Synchronization using CTU in MPC57x (Model Based)

Jump to solution
1,779 Views
abhishek_kumar1
Contributor IV

Hello,

I have been trying to catch events from CTU where the origin in PWM and I want o start ADC conversion as following below. The model is attached.

1. Read PWM ABC and Fire PWM @ 20kHz => T = 1/20000 = 50μs
      a. Fire an interrupt (1) with delay of T/2 (for Centrally aligned PWM), using CTU (I cannot find Delay block or option           for firing interrupt in CTU)
2. Catch the interrupt (1), start ADC conversion for Phase Currents
      a. Fire an interrupt for End of Conversion (2)
3. Catch Interrupt (2) and Trigger Calculation to update PWM A B C

Issues

To see if the CTU is firing the Interrupt I made a counter to see how many times the interrupt were fired, and a GPIO to see what is the delay between PWM Edge and Start of conversion of ADC.

Also, I was end able to find End of Conversion Interrupt in ADC which was there in previous version.

I have attached the model for you.

 

I have checked the model in Samples and was not clear for me, so I try to build my own to understand it better.

Best Regards

Abhishek

1 Solution
1,453 Views
mariuslucianand
NXP Employee
NXP Employee

Hello abhishek.kumar@chassisbrakes.com‌,

You are trying to achieve the following chain FlexPWM0->CTU1->ADC2 which I think is wrong. 

If you are trying to use the FlexPWM1->CTU1->ADC2, then the chain is valid and the board is measuring the ADC value. 

A real explanation of the FlexPWM0/1 to CTU0/1 relation in this  Application note @ page 15 :

"The MRS signal generated from the FlexPWM_0 0 and FlexPWM_1 module is internally routed to the CTU_0 and CTU_1 module respectively." 

Also, in the Reference Manual Figure 7-6. CTU inter-module connections - Chapter 7 Chip Configuration - MPC5744P Reference Manual, Rev. 6, 06/2016 you can find an schematic. 

pastedImage_1.png

Hope this helps, 

Marius

View solution in original post

6 Replies
1,452 Views
mariuslucianand
NXP Employee
NXP Employee

Hello abhishek.kumar@chassisbrakes.com‌,

Sorry for my delayed answer. 

In your requirements you want to use just a half of one hardware chain PWM->PDB->ADC which is independent by the mcu and can provide more precise timing. In my opinion there’s no need to insert an interrupt in which to start an ADC conversion by software and to wait until the conversions are done. Besides, you can start the both ADC converters at once, so you actually can convert two different channels at the same time, but about this will talk later.

Let’s take it step by step.

PWM

   To achieve the right moment when the ADC conversions must be started, you need to keep in mind the PWM period in ticks. To obtain a frequency of 20kHz the counter must have a period of 4000 ticks with no prescaling. In order to trigger an interrupt at T/2, the CTU must be delayed with 2000 ticks, since peripherals uses the same clock. So, we need to keep in mind the value 2000 for the PDB.

pastedImage_2.png

The hardware also gives the ability to set the PWM Reload frequency. In all motor control examples from this toolbox you will find the reload frequency of 2. So every second reload point the PWM triggers the CTU. This value can be changed from the “Reload frequency” field in the PWM Config Block.

pastedImage_3.png

And just a little remark here: By default, the submodules of a PWM module are not synchronized together because they are using different counters. This can be a nightmare when you need to control a motor. In order to sync them, you need to set them like so: submodule 0 must have the Counter init field as “Local sync” and the others must have the “Sub-module 0 master sync” option selected.

pastedImage_4.png

CTU

Here we need explain a little bit how it works and where to insert the delay: each CTU module acts like this: when the trigger appears, it starts a counter incremented by the same clock as the PWM. The prescaler is 1, the same with the one used fot the PWM. So we need to wait 2000 ticks in order to trigger the ADC at the exactly T/2 period. Now, the CTU can have 8 different triggers. For this example we will choose the Triggered mode. We can start all three ADC channels conversion from the same trigger.

pastedImage_6.png

We enabled the Trigger 0 and set the compare value at 2000. So, when the PWM triggers the CTU, it will start counting and when matches the 2000 value it will trigger the ADC conversions with the index between Start and Stop. The pin PTC14 from the Pins tab is enabled to be toggled by the Trigger 0 by checking the “External Output enable” checkbox.

If the “ADC enable” is also checked, you need to set an Index Start and an Index Stop.  Now, you need to think like this: In the ADC Commands tab, it can be inserted up to 24 ADC commands. Imagine all those 24 commands like an array of ADC Commands. So the Index start and Stop represents the ADC Index which will be converted first and the ADC index which will be last converted.

For example if the Index start is 0 and Index stop is 2 it will convert the ADC Index 0 configuration, the ADC index 1 config and last ADC Index 2 config.

pastedImage_9.png

Each ADC index Configuration can set the following: the FIFO index in which the conversion result will be stored, if is Single conversion ( Port A – ADC0, Port B – ADC1) and the channel port (ADC_AN11 -11 must be typed there) or Double conversion in which you need to provide the channels ports for each ADC0 and ADC1.

pastedImage_10.png

Now, the Fifo configurations gives the opportunity to set a threshold number of values over which to get an interrupt whenever the overflow appears. You know that you have 3 values to convert, so when the fifo contains 3 values it will trigger an interrupt.

ADC

Must be set in the CTU control mode and all the channels selected in order to initialize the pins. Now, to get all the converted values, you must use the CTU Get Converstion Result block. This pop a result from the selected Fifo and must be used for each value needed. For example for 3 conversion results you need to use this block three times in the same interrupt. It also can retuen the ADC port and the Channel Number to know exactly which value you've pop.

pastedImage_12.png

Another thing I have found is that you need to set the block priorities in order to generate the ADC code before the CTU.

Hope this helps you!

Best Regards,

Marius

1,452 Views
abhishek_kumar1
Contributor IV

Dear mariuslucianandrei

 

Thank you for the answer, I was trying o open the model you attached but it seems it was created in 2019a.

Is it possible for you to send be 2018b model? You can just export in older version. I do not have 2019a

 

There are a few things I do not understand in the explanation of your answer.

 

Now, the CTU can have 8 different triggers. For this example we will choose the Triggered mode. We can start all three ADC channels conversion from the same trigger.

 

What are these triggers? And which one shall I chose for ADC 0 conversion and ADC 1 Conversion etc…?

Below is CTU Diagram. Form this I cannot make out which Trigger corresponds to which ADC channel.

 pastedImage_1.png

 

 

Each ADC index Configuration can set the following: the FIFO index in which the conversion result will be stored, if is Single conversion ( Port A – ADC0, Port B – ADC1) and the channel port (ADC_AN11 -11 must be typed there) or Double conversion in which you need to provide the channels ports for each ADC0 and ADC1.

pastedImage_10.png

Now, the Fifo configurations gives the opportunity to set a threshold number of values over which to get an interrupt whenever the overflow appears. You know that you have 3 values to convert, so when the fifo contains 3 values it will trigger an interrupt.

 

What is the need for this overflow interrupt, when there already an interrupt after 2000 ticks?

I have followed your instructions and created a model (as attached)

On PWMA, I provide 100% duty cycle so you can see the deadtime (as seen in screenshot below)

And I toggle GPO on and Off (blue graph in screenshot below) when CTU fires interrupt for ADC Command) 

My observation

When I measure the time between deadtime and start of GPO Toggle, I seen 29ms (which is not the half of 50 ms (20 kHz))

There is a delay of 4 ms in processing of the interrupt.

What could be the reason for this?

pastedImage_2.png

Best Regards

Abhishek

0 Kudos
1,450 Views
mariuslucianand
NXP Employee
NXP Employee

Hello abhishek.kumar@chassisbrakes.com‌,

Sorry for adding the model in 2019a version, I've attached the model for the previous response exported in 2018b version. 

For the model attached, unfortunately right now I don't have a scope, so I will be able to have a look on it on Monday, when I get back to the office. 

However, I'll try to respond your wuestions:

What are these triggers? And which one shall I chose for ADC 0 conversion and ADC 1 Conversion etc…?

Below is CTU Diagram. Form this I cannot make out which Trigger corresponds to which ADC channel.

 pastedImage_1.png

In the RM at 41.6.1 Trigger Generator subunit (TGS) it says that in Triggered mode: each event source generates up to eight trigger event outputs. This means that each CTU module is able to provide 8 different actions (triggers) like triggering an ADC conversion.  But for ADC you can have a list of commands and every command to have one channel from ADC A or ADC B (ADC0 and ADC1) or two channels in Double conversion, each from ADCA or ADCB. 

And this is happening like this: Let's say you have enabled Trigger 0 (Compare Value: 1000) and Trigger 1(Compare Value: 2000). When the Input Trigger appear ( the reload of the PWM) the CTU counter starts and when it reaches the value 1000, it takes the actions from Trigger 0 (start converting the ADC list). The CTU counter continue counting and when it reaches value 2000 it takes the Trigger 1 actions. 

Each ADC index Configuration can set the following: the FIFO index in which the conversion result will be stored, if is Single conversion ( Port A – ADC0, Port B – ADC1) and the channel port (ADC_AN11 -11 must be typed there) or Double conversion in which you need to provide the channels ports for each ADC0 and ADC1.

pastedImage_10.png

Now, the Fifo configurations gives the opportunity to set a threshold number of values over which to get an interrupt whenever the overflow appears. You know that you have 3 values to convert, so when the fifo contains 3 values it will trigger an interrupt.

 

What is the need for this overflow interrupt, when there already an interrupt after 2000 ticks?

I have followed your instructions and created a model (as attached)

On PWMA, I provide 100% duty cycle so you can see the deadtime (as seen in screenshot below)

And I toggle GPO on and Off (blue graph in screenshot below) when CTU fires interrupt for ADC Command) 

My observation

When I measure the time between deadtime and start of GPO Toggle, I seen 29ms (which is not the half of 50 ms (20 kHz))

There is a delay of 4 ms in processing of the interrupt.

What could be the reason for this?

I think I know where the misunderstanding is: The trigger event is different than the Overflow interrupt! So when the Trigger 0 matches the value with the CTU Counter 2000, in that moment the CTU starts the ADC Conversion. This is, let's say, the 2000 interrupt. I advise you to use the Overflow Interrupt on FiFo instead, because it is triggered a bit later than the 2000 value, when you have all the ADC values converted and ready to be used. I don;t know on which channel  it triggers the ADC interrupt since you enabled in your second model on each of then, but you need to consider also the ADC conversion time.

 

Hope this helps you,

Marius

0 Kudos
1,449 Views
abhishek_kumar1
Contributor IV

Dear mariuslucianandrei

The current challenge I am facing now is with CTU1. I understand that there are no external interrupts for CTU1 in

MPC5744P 144LQFP package but the internal interrupts should works for ADC conversion.

pastedImage_2.png

I selected ADC2_AN4 to test if I can start conversion from CTU1, but I failed to do so.

pastedImage_3.png

I tried to get the FIFO overflow event use it to toggle a GPIO but it does not work.

pastedImage_1.png

I have attached the model for you. 

0 Kudos
1,454 Views
mariuslucianand
NXP Employee
NXP Employee

Hello abhishek.kumar@chassisbrakes.com‌,

You are trying to achieve the following chain FlexPWM0->CTU1->ADC2 which I think is wrong. 

If you are trying to use the FlexPWM1->CTU1->ADC2, then the chain is valid and the board is measuring the ADC value. 

A real explanation of the FlexPWM0/1 to CTU0/1 relation in this  Application note @ page 15 :

"The MRS signal generated from the FlexPWM_0 0 and FlexPWM_1 module is internally routed to the CTU_0 and CTU_1 module respectively." 

Also, in the Reference Manual Figure 7-6. CTU inter-module connections - Chapter 7 Chip Configuration - MPC5744P Reference Manual, Rev. 6, 06/2016 you can find an schematic. 

pastedImage_1.png

Hope this helps, 

Marius

1,451 Views
haoxue1027
Contributor IV

Hello,Marius

I have a little confuse about the  compare value between the general  and triggers configuration, like following:

pastedImage_1.png

the value here 4000 means that the counter will up to 4000 and reload 0, if it is less than 20KHz(4000 ticks),

But the demo pwm_ctu_adc_mpc574xP here is set to 16000. what is the meaning of that?

pastedImage_2.png

The value here 2000 is as explained above, when the counter is up to 2000. the trigger 0 is started.

best regards

hao

0 Kudos