"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.
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.
With so few information I can only give you general advice.
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.
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).
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.
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.
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.