Faster CTU triggering but slower PWM

cancel
Showing results for 
Search instead for 
Did you mean: 

Faster CTU triggering but slower PWM

483 Views
sagardhavali
Contributor III

Hi,

Currently:

"In our motor control application, we do have PWM triggering CTU and CTU initiating ADC conversions. Since PWM frequency is 10KHz, it drives the CTU interrupt at every 100us." This loosely follows: https://community.nxp.com/docs/DOC-104570 

This was okay until now but one of our interface (Encoder) is being changed and new one is faster by 5x.

To be Changed:

Since the new encoder is faster, I will need to read the ADCs (Encoder inputs) at every 20us instead of original 100us, keeping PWMs at same 10KHz.

Question

How do I trigger CTU and ADCs conversions at every 20us and keep PWMs at the same old rate? Also how do I achieve the synchronization among CTU, ADC and PWMs?

Thanks in advance.

- Sagar

Labels (1)
0 Kudos
6 Replies

141 Views
petervlna
NXP Employee
NXP Employee

Hi,

With so few information I can only give you general advice.

for example:

1. create PWM synchronized with your 10kHz PWM

2. set its frequency for 1/5 of your PWM

3. trigger CTU at 1st clock of this PWM and trigger ADC conversion in first clock of CTU counter.

4. set another 4 triggers always at 1/5 of 10kHz frequency

I will post example of it here later.

Peter

141 Views
petervlna
NXP Employee
NXP Employee

Even simpler:

Use CTU triggers 0 to 4 to create triggers for measurement.

Like bellow:

pastedImage_1.png

Peter

141 Views
sagardhavali
Contributor III

Peter,

Thanks for those options. I will try them.

I was thinking of another option. Tell me if that works please.

1. Use eTimer to trigger CTU at every 20us.

2. Keep a counter of this 20us at every interrupt.

3. When this counter is 5, generate a Software Interrupt.
( This is the reason I was asking about the software interrupt generation at will).

Thank You,
Sagar

0 Kudos

141 Views
sagardhavali
Contributor III

petervlna‌, I think I did not explain clearly what I am trying to achieve.

Currently: Every 100us Task_A and Task_B gets executes. CTU triggers ADC and upon ADC completing conversions, an interrupt is generated to take care of both the tasks.

Change Required: Now because of component change, Task_A needs to run at every 20us and Task_B needs to run at every 100us. With both solutions you suggested, no doubt I can get to execute Task_A at every 20us by triggering an interrupt; But I still need an interrupt to run Task_B at every 100us. I cannot simply execute this Task_B at every 5th instance of 20us interrupt because Task_B is longer than 20us. So, I need another lower priority interrupt to do Task_B.

How do I do that is my question.

Please suggest how do I achieve the above with those 2 solutions. Also, please tell me if my option stated above works as well.

Please let me know if you need anymore information.

Thanks,

Sagar

0 Kudos

141 Views
petervlna
NXP Employee
NXP Employee

hi,

Do you need task A to be synchronous with task B?

This is what I expect when we are talking about motor control timing applications.

If not, then you can use any counter to trigger interrupt for you. For example PIT,eTimer,etc... I see no issue here.

It is still not fully clear what are you trying to achieve.

Peter

0 Kudos

141 Views
sagardhavali
Contributor III

Hi petervlna

  • Yes, I need both Task_A and Task_B in synchronous

Here is what I am trying to do:

Currently, all the computations are done in 100us. Say those are: ADC reads ADC_R1, ADC_R2 and computation Comp_1 and Comp_2.
Note: Please don't assume that all these tasks take just 50us. I have it marked wrongly in the following picture. 

Now, I would want to handle all those tasks differently as follows.

  • I can use CTU to trigger 0 to 4 to generate 5 interrupts at every 20us. In these ISRs, I can do ADC-R1, ADC_R2 and Computations_1.
  • That leaves me to do computations_2 at the same 100us interval. And, I need this to be done in a different ISR and in synchronous with those CTU trigger interrupts.

Question/Clarification:

  • I want to accomplish computations_2 in the same old 100us ISR. I don't want it those executions be done at every 5th instance of 20us.
  • How do I get that 100us ISR set up?
  • And I want it to be in sync with CTU triggers.

pastedImage_1.png

Thank You,

Sagar

0 Kudos