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