Free running timer

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User10969
Level 1
Level 1
Hello everyone,

I would like to set up a free running timer (16bits) with e. g. solutions of 100us on the XMC4 with/without Dave.
Could someone give me a hint how to do it with Dave (V4.2) ? Or there is an example which can be provided ?

Thanks in advance
Bluejay
0 Likes
4 Replies
User10215
Level 4
Level 4
First like received
Hi Bluejay,

as far as I know there is no direct way with Dave-Apps to achieve that. The easiest way would be a mixture of DAVE-App and XMCLib with the following procedure:

- add a PWM_CCU4-App to your project
- in the App-Configuration mark "Start during initialization"
- in the App-Configuration set your desired resolution
- right-click on the app and select "Manual Resource Assignment"
- in the drop-down-list for the resource group "cc4 config" choose "/ccu4/0/cc4/0"...this will tell DAVE to take CCU40_CC4 as the peripheral for the timer. If you select nothing DAVE will choose a timer for you, however the following code I post would have to be adjusted
- generate the code
- in the main-function before the last while-loop add the following two XMCLib-functions:

XMC_CCU4_SLICE_SetTimerPeriodMatch(PWM_CCU4_0.ccu4_slice_ptr, 0xFFFF);
XMC_CCU4_EnableShadowTransfer(PWM_CCU4_0.ccu4_module_ptr, XMC_CCU4_SHADOW_TRANSFER_SLICE_0);


- be aware that the structure "PWM_CCU4_0" resembles the name of your PWM_CCU4-App!
- compile the code and flash it to your controller

You got yourself a free-running 16-bit timer now!

- right-click on the App and select "APP Help" then "Usage" and see how an App can be used/configured (with exapmles!)
- select "APP Help" then "Methods" to see the functions you can use that are provided by the App. For instance the funtion "PWM_CCU4_GetTimerValue" can be used to read out the current value of the free-running timer at any point in your code

Regards,
Niclas
0 Likes
User10969
Level 1
Level 1
Hi Niclas,

thanks for your suggestion how to set up a free running timer !

Currently I am quite confused about the "Timer Settings" with Dave-App:
on the left side I can put the value I would like to set/get, as I understand with the "actual ..." Dave-App shows me the real value I will get, is it correct ?

My XMC4 system runs with 120MHz, I would like to get a quite exactly resolution of e. g.: n * 100ns (n = 1, 2...5).
It seems quite impossible to get such a setup, since I could not find how the 120MHz is derived by the App (Prescaler).

How do you do it if you like to get an exactly resolution ?

Thanks in advance for any hints.
0 Likes
User10215
Level 4
Level 4
First like received
Hi Bluejay,

the resolution you can get is dependend,for one, on the clock the CCU4-Module receives. If you didn't change something in the general clock settings this clock should be the system clock i.e. 120 MHz. That means your timer can run with max. 120 MHz i.e. a resolution of 1/120 MHz = 8.33 ns.
Then there is a prescaler that can divide the 120 MHz in powers of two. This means the prescaler in the Timer-Setting of the App Shows you the power of two by which the 120 MHz are divided. Example:

- the App shows a prescaler of 1 which means your timer now runs with 120 MHz/2^1 = 60 MHz which is a resolution of 16.67 ns
- the App shows a prescaler of 2 which means your timer now runs with 120 MHz/2^2 = 30 MHz which is a resolution of 33.33 ns

The resolution you type into the App helps DAVE to find the correct prescaler which is shown in the window labled "Prescaler:" (don't Forget...if this window shows e.g. a 2 then the 120 MHz will be divided by 2^2). The actual resolution you will get with this prescaler is then shown in the window labled with "Actual PWM Resolution [nsec]:".
I'm afraid that you can't get a resolution of exactly 100 ns. The closest resolution you can get is 133 ns.

Regards,
Niclas
0 Likes
User10969
Level 1
Level 1
Hi Niclas,

many thanks for your hints, it helps me quite much...


Best regards,
Bluejay
0 Likes