Change timer to 19.2Mhz

Discussion and questions about programming with Ultibo.
johan
Posts: 3
Joined: Thu Sep 13, 2018 2:37 am

Change timer to 19.2Mhz

Postby johan » Tue Apr 16, 2019 8:13 am

I use raspberry pi 3 model.
I know that there are two usable timers per core and they are set at 1Mhz.
But I am not enough 1Mhz. So I want to change timer to 19.2Mhz.
How can I do that?
User avatar
Ultibo
Site Admin
Posts: 2261
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: Change timer to 19.2Mhz

Postby Ultibo » Wed Apr 17, 2019 10:52 am

johan wrote:I use raspberry pi 3 model.
I know that there are two usable timers per core and they are set at 1Mhz.
But I am not enough 1Mhz. So I want to change timer to 19.2Mhz.
How can I do that?

Hello,

We originally designed Ultibo to work with any available clock speed but your question made us realize we have never actually tested it so we've done some basic testing to confirm that it works.

In order to change the speed of the clock used for the generic timers you need to modify these three values in the PlatformRPi3 unit as follows and then rebuild your RTL:

Code: Select all

const
 {Core Timer Prescaler}
 RPI3_CORE_TIMER_PRESCALER    = $80000000; //$06AAAAAB; {Divide the Crystal Clock by 19.2 to give a 1MHz Core Timer}
 RPI3_CORE_TIMER_FREQUENCY    = 19200000; //1000000;   {The Core Timer frequency from the prescaler setting above}
 RPI3_GENERIC_TIMER_FREQUENCY = 19200000; //1000000;   {The ARM Generic Timer frequency from the prescaler setting above}

That will set the divider for the core timer during boot and configure all of the internal values of Ultibo so that they are calculated on a 19.2MHz clock instead.

Our testing was only quite brief but the only thing so far that seems to be slightly incorrect after making that change is the CPU utilization is off by a small amount, that may be to do with the fact that 19.2MHz doesn't give an integer value for the number of clock ticks per microsecond (19.2) so the rounded down value of 19 gives a slight error in the delay calculations.

I should also point out that of the two available timers per core Ultibo uses both of them on CPU0 and one of them on each of the other CPUs, there is an option in the RTL to switch the clock to the system timer instead which would free up one timer on CPU0 but at least one is needed per CPU to run the scheduler.

Let us know if this is useful and we'll add a conditional define to the RTL to allow using it when required.

EDIT: We've now added this as a permanent option in the Ultibo RTL, you can use the RPI2_MAX_CLOCK_RATE or RPI3_MAX_CLOCK_RATE defines in the GlobalDefines.inc file to enable this option as needed.
Ultibo.org | Make something amazing
https://ultibo.org

Return to “General”

Who is online

Users browsing this forum: No registered users and 0 guests