Unable to use one shot timer a second time for LED

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I am trying to have the LED stay on for 5 seconds after I push the button on the cy8ckit-049-42xx prototyping kit.Currently, it works the first time I push the button but the next time the LED stays on forever. I am using Win 7 and PSoC Creator 4.1.

   

Here is the relevant code.

   

int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

   

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    My_Timer_Enable();
    int Flag = 0;
    //LED_Write(1);
    for(;;)
    {
        LED_Write(0);
        if(!SW2_Read() && !Flag)
        {
            My_Timer_Start();
            Flag = 1;
        }
        
        while((My_Timer_ReadCounter()>0)&&Flag)
        {
            LED_Write(1);
            CyDelay(100);
        }
        
        if(My_Timer_ReadCounter()<1)
        {
            Flag=0;
           // My_Timer_Init(); // Makes no difference
        }
    }
}

   

 

   

I have attached the code bundle.

   

Thank you for your kind help.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

That does not work because the timer will be reloaded after TC.

   

See attached project (I used a different PSoC, please change it back.

   

 

   

Bob

View solution in original post

0 Likes
1 Reply
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

That does not work because the timer will be reloaded after TC.

   

See attached project (I used a different PSoC, please change it back.

   

 

   

Bob

0 Likes