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

cross mob
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hi,

I wonder how the clock frequencies used in a design can be calculated during runtime in general (design uses a clock component) and especially for clocks which are internal to a component, e.g. UART.

For example, using Clock_GetSourceRegister() returns CYCLK_SRC_SEL_SYNC_DIG which equals the (un)divided PLL output. So, I know the source, but I don't know the source frequency. I assume I've to calculate backwards through the clock tree, right? I couldn't locate any APIs or at least fixed preprocessor definitions to get the corresponding values.

For component internal clocks like UART, it seems to be even more complicated because the clock (API) can't be accessed.

Any help is appreciated.

Regards

0 Likes
1 Solution
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hello @Ekta_N 

okay, thank you for pointing me to the ClockSetup() function, I'll go through it. If all clock related setup is done here it should be easily possible to extract the steps needed to get each and every clock setup.

Thank you.

Regards

View solution in original post

0 Likes
10 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

@RaAl_264636 ,


... I assume I've to calculate backwards through the clock tree, right? I couldn't locate any APIs or at least fixed preprocessor definitions to get the corresponding values.

Yes.  You need to backwards-parse the clock tree.

I don't believe APIs exist to parse the clock tree other than a few to determine the source but not the frequency.

I assume you are already aware that to determine an accurate clock frequency, you need to start with an even more accurate clock reference to compare measured results against.

If you're interested, I've included the following link to a project for the 059 kit to trim ILO and IMO frequencies.   It assumes you are using an external frequency measuring source as your reference:

PSoC5-IMO-and-ILO-clock-trimming-Project 

 

 

 

 

 

 

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Frequencies in the clock tree IMO->PLL->MASTER_CLK->Clock_1 etc. can be calculated by reading dividers. Attached is an example of reading (calculating)  PLL frequency, assuming that IMO is already known (3.0 MHz). Also, frequencies of a couple of the derived clocks: Clock_1, derived from IMO, and Clock_2, derived from the MASTER_CLK are calculated and printed by UART.  This, however, sort of trivial. 

ClockDividers_01a_UART.PNG

 

Another possibility is provided by the customizer, is to read the frequency of the clock to the component. An example of such clock reader could be found in the SAR_ADC customizer file. It checks that the user-provided clock is within the ADC specs. It is more complicated, and is useful, probably, only for custom component creation. Note that it returns the nominal (calculated) clock frequency, while the actual one may deviate few percent from that value due to IMO or XTAL offset. So it is better not to rely on such value, but explicitly set the actual clock frequency in the Dialog settings.

 

If the clock is internal to the stock component (like UART), I believe that there is no way to read it back, unless one has a source code of the component and can access the clock registers. But I can't imagine where such  reading might be useful.  

 

 

 

Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hi @RaAl_264636 

Could you let me know which clock do you want to measure during runtime?

As mentioned by odissey, if you know the clock path for the final clock, you can read the clock dividers along the path to get the final clock frequency.

The below appnote provides details of the clocking resources for PSoC 5LP, which can be used to understand the different clock paths: PSoC(R) 3 and PSoC 5LP Clocking Resources – AN60631

Best Regards
Ekta




RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hello,

thank you for your answers.

@Len_CONSULTRON
Thank you for pointing me to your project. It sounds interesting. And I'm curious about the terminal component - my current project is based on a DEC video terminal parser. Really interesting to dig deeper into those escape and control sequences, etc.
I don't want to measure the clocks (currently), it would be enough to know the used frequencies so that I can tune some settings depending on the used clocks during runtime without using fixed values in code which must be redefined otherwise.

@odissey1 
How do you ensure that the IMO frequency is known? The only way I see is to use the CyIMO_SetTrimValue() function from CyLib.c in the opposite direction: comparing the current trim value against the values from the flash trim value table.

As already mentioned, currently I don't want to measure it, I just want my software to know the value. Regarding the usefulness of knowing the frequency of an component internal clock, my current design uses some timeout after a character has been received on UART. This timeout should equal approximately five character units. The UART component doesn't provide a definition of either the configured frequency or bitrate as far as I can see, otherwise I could use this value in my software. So I've to calculate the timeout value manually each time I change the bitrate. I'm pretty sure there are other scenarios where informations about internal clock settings might be helpful for any component.

Regarding the customizer, unfortunately there isn't much information provided for writing or changing customizers. I know there's an example project, but it's just a skeleton if I remember correctly.

@Ekta_N 
Thank you for the application note. I'll check if it contains more in-depth information than the reference manual. I'll also check if I can make some functions to retrieve the path of a given clock. As mentioned above, I want to automatically calculate a timeout based on the UART bitrate. Therefore it would've been nice if the UART component would provide a header definition of either the frequency used or the bitrate. Interestingly, the generated UART header file has a definition of UART_1_CLK_FREQ, but it's always zero regardless if internal or external component clock is used.

Regards

0 Likes
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hi @RaAl_264636 

Just to give you an idea:

Given the baud rate for UART is 115200, and the oversampling is set to 8x. This would imply that the required clock is baud rate * ovesampling = 115200 *8 = 921600 Hz.

Ekta_0-1705401379908.png

The UART component clock is sourced from Masterclock. You can view the master clock frequency by clicking clocks tab in design wide resources. Say, the master clock is 24Mhz. Therefore a bus divider of 26 would be required to get the clock of frequency 921.6Khz. This clock divider is set automatically and can also be seen under the clocks tab (see the image below).

Ekta_2-1705401621532.png

I noticed that in the UART_IntClock.c file there is function to get the clock divider values. You can try using this function to get the clock frequency during runtime.

Best Regards
Ekta

 

 

0 Likes

Hello @Ekta_N 

thank you for that explanation. You're starting from a given baudrate, but this information is missing - it can't be retrieved by software. As I wrote, the component doesn't place the bitrate value into the header file. So the only way would be to use an external clock to the component and calculate the values starting from the IMO.

Regards

0 Likes
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hi @RaAl_264636 

I guess I didn't understand your question properly.

Can you please help me to understand what information are you finally looking for? It would be good if you could provide some block diagram for the same.

The IMO frequency should be fixed based on your configuration in the project. Why do you want to measure the IMO frequency using an external clock?

Best Regards
Ekta

0 Likes

Hello @Ekta_N 

I repeat it again: I don't want to measure, I just want my software to know the frequency of a component. For example, the bitrate of an UART or SPI component. Or DAC or whatelse. Of course I know the bitrate because I've feed that information to the component - but there is no (easy) way to let my software know the value (automatically). Currently I've to use a manually placed

#define UART_BITRATE 115200
#define UART_CLOCK8 921600
#define UART_CLOCK16 1843200

or something like that. I think I'll have to extend the component API with the functions to get the frequency. As mentioned by you UART_IntClock.c already contains a function for getting the divider, but not the source.

Regards

0 Likes
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hi @RaAl_264636 

ohh, I got your question now. 

You are right, there is no where where the frequency fed to the component is directly fed.

Therefore you would need to read the divider values in order to get the final frequency fed to the component. 

FYI: All the clock registers and there dividers are configured based on the DWR settings made by the user. This configuration is performed in the ClockSetup function present in the cyfitter_cfg.c file.

Best Regards
Ekta

0 Likes
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hello @Ekta_N 

okay, thank you for pointing me to the ClockSetup() function, I'll go through it. If all clock related setup is done here it should be easily possible to extract the steps needed to get each and every clock setup.

Thank you.

Regards

0 Likes