Blink LED with timer

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

cross mob
Anonymous
Not applicable

Hello everybody,

I am trying to blink a led using a timer. My configuration is very simple:

On timer component

clock: 32Khz

period: 32000

trigger mode: node

capture:

enable mode: software

run mode: continuous.

The problem is that after uploading the led lights but is not blinking.

Here is the c code:

The commented lines is what i tried. Thank you in advance.

/* ========================================

*

* Copyright YOUR COMPANY, THE YEAR

* All Rights Reserved

* UNPUBLISHED, LICENSED SOFTWARE.

*

* CONFIDENTIAL AND PROPRIETARY INFORMATION

* WHICH IS THE PROPERTY OF your company.

*

* ========================================

*/

#include "project.h"

int array[4]={1,2,4,8};

volatile _Bool state=0;

CY_ISR(TMR_ISR_HANDLER){

    if(state==1){

        state=0;

        LED_1_Write(1);

       

    }

    else{

        state=1;

        LED_1_Write(0);

    }

    //TMR_WritePeriod(32000);

    //TMR_Stop();

    //TMR_WritePeriod(5000);

    //TMR_Start();  

};

int main(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

   

    TMR_ISR_StartEx(TMR_ISR_HANDLER);

    TMR_Start();

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    for(;;)

    {

   

        /* Place your application code here. */

    }

}

/* [] END OF FILE */

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You did not clear the interrupt in the TMR component. Depending on what kind of timer you use (UDB or TCPWM) you need to read the TMR status or explicitly clear the interrupt in your handler.

Next time  will you please post your complete project so that we all can have a look at all of your settings. To do so, use

Creator->File->Create Workspace Bundle (minimal)

and attach the resulting file.

Bob

View solution in original post

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

You did not clear the interrupt in the TMR component. Depending on what kind of timer you use (UDB or TCPWM) you need to read the TMR status or explicitly clear the interrupt in your handler.

Next time  will you please post your complete project so that we all can have a look at all of your settings. To do so, use

Creator->File->Create Workspace Bundle (minimal)

and attach the resulting file.

Bob

0 Likes
Anonymous
Not applicable

Thank you it works!!!!

Forgot about it.

I will attach the complete code next time.

0 Likes