Change timer period while Timer is running.

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

cross mob
PAB
Level 2
Level 2
First like given Welcome!

Hello All

I am using timer component, while run time i want to change the timer period,

and as per this https://community.cypress.com/docs/DOC-12263

i wrote the code.

timer clock is 10Khz 

default period is 900 (90ms)

i want to change it to 3000ms.

        Timer_Start();

        Timer_WritePeriod(30000);

        Timer_WriteCounter(0);

        isr_timer_StartEx(timer_int_handler);

after this lines of code the timer interrupt is activated in isr i wrote code to reset PSOC device.

the task is i had to reset the PSOC device whenever the timer count is completed and interrupted.

the period of timer is user changeable.

Is there any way to successfully do this.

Thanks.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Attached is my trial, it seems that we need to use Timer_Enable() instead of Timer_Start() .

So my period setting function was

===============

void set_timer_period(int period)

{

    Timer_Stop() ;

    Timer_WriteCounter(0) ;

    Timer_WritePeriod(period) ;

    Timer_Enable() ;

}

===============

My TeraTerm log.

PSoC5LP_Timer_test.JPG

moto

View solution in original post

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

To be on the safe side you shoud stop the timer before changing period and resetting the actual count value to zero. After the changes start the timer again.

Bob

Hello BOB

This is what i wrote as you suggested but didn't work.

now i set the timer Period to 1000ms

but after this code the timing still not changed it is still 1000ms only.

        Timer_Stop();

        Timer_WritePeriod(30000);

        Timer_WriteCounter(0);

        isr_timer_StartEx(timer_int_handler);

        Timer_Start();

Thanks

Paras

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Attached is my trial, it seems that we need to use Timer_Enable() instead of Timer_Start() .

So my period setting function was

===============

void set_timer_period(int period)

{

    Timer_Stop() ;

    Timer_WriteCounter(0) ;

    Timer_WritePeriod(period) ;

    Timer_Enable() ;

}

===============

My TeraTerm log.

PSoC5LP_Timer_test.JPG

moto

0 Likes