A simple way to determine the configured frequency of a given clock at build time?

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

cross mob
MaGa_1759861
Level 2
Level 2
First solution authored 5 replies posted 5 questions asked

I am using a clock component to set the frequency of a UDB based I2C component (external clock mode). The frequency setting of this clock component can change from design to design.

I also have a timeout in my code that is dependent on the bus clock frequency - I currently have a manually configured #define for a scaling value for the timeout  ... which is ugly as changing the clock frequency in the top level design and missing changing the scaling value in the source code my timeout can fail at run time.

I was hoping that the the generated code for the clock component would include a #define indicating the configured clock frequency however this does not appear to be the case.

Is there a simple way to determine the configured frequency of a given clock at build time? The IDE cetainly has an awareness of this as it indicates the Actual Data Rate of the I2C module when I change the input clock frequency.

I would also be happy to read it at runtime too, the clock API seems only to have the following appropriate API calls:

uint16 Clock_2_GetDividerRegister(void) ;

uint8 Clock_2_GetSourceRegister(void) ;

Currently the clock is sourced from the IMO (XTAL) ... is there an easy way to determine the frequency of this clock even.

FYI I am also running this code on PSOC4.

0 Likes
1 Solution
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

I am afraid there is no easy way. Take a look on SAR_ADC stock component, particularly the customizer code included. You would have to write your own customizer, which is daunting task.

View solution in original post

0 Likes
2 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

I am afraid there is no easy way. Take a look on SAR_ADC stock component, particularly the customizer code included. You would have to write your own customizer, which is daunting task.

0 Likes

Thanks for that. I will certainly take a look at the customiser code; it is

a shame really as the info is obviously available in the project

configuration.

As an alternative, I'm considering using a hardware timer for the timeout

base clocked from the same clock as the I2C so it should all simply scale

in hardware.

Martyn Gallop

Senior Electronics Engineer

PPS

Tel: +44 (0)1415597150

Email: martyn.gallop@pressureprofile.com

Registered Office:

Inovo, Suite-H.

121 George St.

Glasgow

G1 1RD

Registration Number: SC509380

VAT Number: 225278605

On 5 October 2017 at 20:08, user_342122993 <community-manager@cypress.com>

0 Likes