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

PSoC™ 4 Forum Discussions

YoIs_1298666
Level 5
Level 5
250 sign-ins 100 replies posted 100 sign-ins

Hello,

I would like to change period and compare value directly in TC interrupt handler with API during running Timer/Counter of PSoC4000S.

Is there no problem?

Or can we only use swap of PWM instead of Timer/Counter?

Best regards,

Yocchi

0 Likes
1 Solution

Yocchi,

This KBA might be helpful:

Best Practices to Reload the Compare and Period Values of Timer/PWM/TCPWM/Counter Component - KBA905...

Basically, in running Timer/Counter or PWM, a new value value will take effect after tc overflow (next period).

/odissey1

View solution in original post

0 Likes
7 Replies
LinglingG_46
Moderator
Moderator
Moderator
10 questions asked 5 questions asked 250 sign-ins

Hi Yocchi,

First question:

Yes, there is no problem to change the period and compare value in the TC interrupt handler.

Second question:

I think you should describe which function you want to achieve.

Could you offer us more information to decide whether it could be achieve.

0 Likes

Hello,

Thank you very much for your reply.

About first question, I am concerned about making a misjudgment when the comparison with the counter value occurs at the moment of writing the period and compare value.

Do you still think there is no problem?

Best regards,

Yocchi

0 Likes

Yocchi,

This KBA might be helpful:

Best Practices to Reload the Compare and Period Values of Timer/PWM/TCPWM/Counter Component - KBA905...

Basically, in running Timer/Counter or PWM, a new value value will take effect after tc overflow (next period).

/odissey1

0 Likes

Hello,

In conculsion, I will use swap function.

I set switch enable of Timer_1 in hardware. and enable the swap with API in software.

Timer_1_SetPeriodSwap(1);

It can run well.

pastedImage_0.png

Best regards,

Yocchi

0 Likes

Hello,

In KBA90554 ​, it is written that the period or compare value is larger or smaller than counter value.

If the period/compare register of the timer/counter(PWM) is asynchronous clocking, the malunction should occur

like "In the case of asynchronous clocking".

pastedImage_1.png

If it is synchronous clocking, there is no malfuncion like "In the case of synchronous clocking"

pastedImage_2.png

Which type it was made?

Best regards,

Yocchi

0 Likes

Hi Yocchi,

The TCPWM  runs in the asynchronous clock like you described in the previous response (first figure).

We don't recommend you change the period value and let it act in the current cycle.

You can call the API: void PWM_1_WritePeriodBuf(uint32 periodBuf) to change the period. If you use this way, it will take effect after TC event.

Thanks,

Lingling

0 Likes

Hello Lingling-san,

It became clear.

I really appreciate your help.

Best regards,

Yocchi

0 Likes