F28335 Timer1 & Timer2 Construction - Using via Simulink

28 views (last 30 days)
Hello everyone;
Before the question let me introduce my tools;
C2000 board: F28335
Matlab Model : R2017b
Code Composer: CCS7.4
My question is about using CPU Timer1 and CPU Timer 2 options of this dsp via simulink. As you already now, there are 3 cpu timer in F28335(You can see the
the following figure).
But when I build a Simulink model that containes ADC, ePWM, SCI blocks, model creates(configures) only CPU Timer 0. When I examine the examples of matlab I found "Asynchronous Scheduling" model but in that model 2 different ePwm modules are used as timers because they can trigger subsystems via interrupts. However At the end still timer 0 is used for all timing operations. For example the generated code is seen like this:
My question is how can I implement Cpu Timer1 and Cpu Timer 2 in model so that I can get a code output like following code segment: ? I want to config CPU Timer 1 and CPU Timer 2. and also I don't want ePWM blocks as timers or interrupt sources.
Thanks in advance.
Best regards;
Ömer

Accepted Answer

Antonin
Antonin on 23 Apr 2019
To add to Venkatesh's response:
  • You can use regular sample times in your Simulink model to achieve 3 tasks of 100Hz, 1kHz and 10kHz, just mention the different sample times in the blocks that you are using. We create a multitasking scheduler baser on CPU Timer 0 that can schedule the 3 tasks. The fastest task has the highest priority and can preempt the slowest. you can also run in single tasking mode which disables the preemption. I would suggest that you exhaust this somution prior to using other CPU Timers. Enable sample time colors in your model to quickly watch which portion is executing at which rate. Use the rate transition block to send data from one rate to the other.
  • Simulink Coder custom code blocks can be used to configure CPU timers (https://www.mathworks.com/help/rtw/ref/systemoutputs.html). You can also use the Memory Copy block to access these timers (https://www.mathworks.com/help/ecoder/ref/memorycopy.html). Keep in mind that CPU Timer 1 is used by our profiler when enabled.
  • You don't have to use ePWM interrupts if you don't need them.
I hope it helps,
Antonin.
  3 Comments
Antonin
Antonin on 28 Apr 2019
Hi Ömer,
The fastest rate will execute first and then the slower rate executes. If the solwer rate is not completed before the next instance of the fast rate, it will be preempted. Timer 0 will be set to the fastest sample time in the model (base rate), in the example where you have 2 rates of 10kHz and 1kHz, it will be set to 10kHz. Every 10 instances, it will launch the 1kHz task, at that time it allows itself to be preempted (by itself), to allow new fast rates to preempt the slow rate. The result is that your 10kHz task will be running exactly at 10kHz, if the excution time of the 10kHz task is consistent, then the 1 kHz task will also be running exactly at 1kHz. The 1 kHz task may be affected by variation of the excution time of the 10kHz time, that's all, otherwise it's pretty accurate. The 1 kHz task can be preempted by multiple new instances of the 10 kHz task. The same principle applies to all subrates.
In the generated code, ert_main.c is the file where this logic is deployed, while MW_c28xx_csl.c is used to configure interrupts.
You can visualize the scheduling using our profiling example:
https://www.mathworks.com/help/releases/R2019a/supportpkg/texasinstrumentsc2000/ug/real-time-code-execution-profiling.html
This has been heavily used for more than a decade by many people ;-)
Also worth noting, it's important to keep all subrates in the model as an exact multiple of the base rate, to avoid having Simulink create a hidden subrate as a common denominator. For instance, if you have a model with 2 rates of 2 kHz and 3 kHz, Simulink will create a hidden base rate of 1kHz to schedule the 2 tasks. In this case it's not that bad but imagine how fast the hidden base rate would have to be if the 2 tasks are 2.333kHz and 1.334 kHz, in that case the base rate would have to be of 1MHz and kill your performance. I strongly encourage all users to enable sample time colors in their models and be in control of their sample time. The red color is used for the base rate, if you don't see it in your model, it probably means that you have a hidden base rate which may hurt performance. Ctrl+J brings the sample time legend for a mdoel.
I hope it helps,
Thanks,
Antonin.
omer cakmak
omer cakmak on 2 May 2019
Hi Antonin,
Thank you for these valuable informations. The answer you gave was extremely descriptive and clear so it will be very beneficial for us. Now we re-model our blocks as you suggest. In any problem case, I may inform you.
Thanks again;
Ömer Ç.

Sign in to comment.

More Answers (1)

Venkatesh Chilapur
Venkatesh Chilapur on 22 Apr 2019
Hi,
Use of Timer1 and Timer2 may not be possible directly from simulink using modelling approach.
Instead a custom code approach using custom code blocks can be used to configure the timer, setup the ISR routine and write the ISR logic. We have custom code blocks under simulink coder that can help.
Could you please share details on why ePWM module are not used for generating interrupts but CPU timers?
Regards,
Venkatesh C
  2 Comments
omer cakmak
omer cakmak on 26 Apr 2019
Hi Venkatesh,
Thank you for your quick response and interest. Actually there is no specific reason to use timer interrupts instead of ePWM module interrupts. Till now, in our projects, the only task whick is synchronized to ePWM is reading the ADC inputs. Other tasks are done via timer interrupts such as 10kHZ, 1kHz and 100Hz. So if we could use timers we prefer them but since if it not possible use them directly we may try ePWM blocks.
Best Regards;
Ömer Ç.
Burak Caykenari
Burak Caykenari on 23 Oct 2020
Edited: Burak Caykenari on 23 Oct 2020
Ömer Bey Merhaba ,
Bu konuda sormak istediğim sorular var size. Mümkünse yardımcı olup dönüş sağlar mısınız ?
caykenarib@hotmail.com
Çok teşekkürler.

Sign in to comment.

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!