CAP001_GetPeriod function. How to convert the Period to seconds ?

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

cross mob
Not applicable
Hi All,

I am using the CAP001 App to generate a Period interrupt. In the interrupt service routine I read the Period using the following App function...

CAP001_GetPeriod((CAP001_HandleType*)&CAP001_Handle0, &Period);


My question is how to convert the Period count into seconds. The App help suggests the Period count should be multiplied by the Timer resolution / 10.

The CAP001 configuration is shown below with a timer resolution of 500nS (266.66nS actual)

795.attach

With a 10Hz (0.1 sec period) interrupt the Period Count = 11999010

794.attach

With a 100Hz (0.01 sec period) interrupt the Period Count = 1199078

793.attach

So the Period count is 10 times bigger at 10Hz compared to 100Hz so this is correct. However, multiplying the Period count by the timer resolution of 500nS / 10 or even 266.66nS / 10 gives an incorrect period in seconds...

10Hz (period should be 0.1 seconds)
11999010 * 500nS / 10 = 0.59995 seconds
11999010 * 266.66nS / 10 = 0.31998 seconds

100Hz (period should be 0.01 seconds)
1199078 * 500nS / 10 = 0.059995 seconds
1199078 * 266.66nS / 10 = 0.031998 seconds


I guess I'm doing something wrong here so any help or suggestions would be greatly appreciated.

Best regards
Aaron
0 Likes
5 Replies
Not applicable
Hey Aaron,

I had the same Problem in the beginning. I recognized that you have to multiply the value you get from the CAP001_GetPeriod-Function with 8.33ns.
I do not really no why the factor doesn´t depend on your timer Resolution you adjust in the app-config, but that works very well in my case!

So you get:
10Hz -> 0.1s = 100 000 000 ns
11999010 * 8.33ns = 99 951 753ns ~ 100 000 000ns


100Hz -> 0.01s = 10 000 000ns
1199078 * 8.33ns = 9 988 319 ~ 10 000 000ns

The relative error is not more than 0,1% from 1Hz to 5kHz in my case.

Greets
Stefan
0 Likes
Not applicable
Hey Stefan,

Thank you for your suggestion. It works perfectly for me. Seems like a mistake in the help documentation though I am concerned that if it is a bug then a future change to the App may stop my code from working.

Best regards
Aaron
0 Likes
Not applicable
Hi Aaron,

Thank you very much for the feedback. I'm clarifying with the developer. Will update you once get reply.

Best regards,
Sophia
0 Likes
Not applicable
Hi Aaron,

When use CAP001[1.0.24] in “Floating Prescalar” Mode, whatever the resolution selected prescalar configured will be ZERO. The reason is because this approach will give more accuracy compared to setting the calculated prescalar value. Hence, the time calculation is to just to multiply 8.33ns.

A change request was submitted (eTicket 402025956) to set the resolution to the least in UI and make it as read only if “Floating Prescalar” mode is selected.

Best regards,
Sophia
0 Likes
Not applicable
Hi Sophia,

Thank you for the update.

Best regards
Aaron
0 Likes