cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

Contributor II

 I am using the code below (copied from an example on the web) to provide a timeout feature for a routine.

   

However, whatever value I use when calling the routine (100, 1000, 5000), the timeout seems to happen immediatly and not at 100ms or 1000 ms or 5000 ms.

   

The timer component is set up as 32 bit timer with 24MHz clock and interrupt on TC.

   

Help much appreciated

   

 

   

CY_ISR(TimerINT){

   

    Timer_ReadStatusRegister();

   

    Timer_Flag = 1;

   

}

   

 

   

void ms_delay (uint32 ms) {

   

    Timer_Init(); // config but don't start the timeout counter

   

    isr_Timer_StartEx(TimerINT);

   

    uint32 period = 24000000/1000*ms;

   

    Timer_WritePeriod(period);

   

    Timer_Enable(); // start the timeout counter

   

    while(!Timer_Flag){};

   

    Timer_Stop();

   

        Timer_Flag = 0;

   

}

0 Likes
Reply
1 Solution
Esteemed Contributor II

Some corrections: volatile for the flag is mandantory, program will fail when compiled with "Release" setting

   

INT should be "Rising Edge" for UDBs

   

Flag was not initialized.

   

Period was set, but counter has value from initialization or last stop

   

_StartEx() for interrupt was called within loop, same for Timer_Init()

   

 

   

Happy coding

   

Bob

   

PS: I changed the target to PSoC5, please reverse to PSoC4 4247

View solution in original post

0 Likes
Reply
14 Replies
Esteemed Contributor II

It is always advisable to upload a complete project showing the error, there are a bunch of settings that may influence the timer's behaving. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.



Bob

0 Likes
Reply
Contributor II

 Good Point, I have attached the bundle.

0 Likes
Reply
Contributor II

 Note: I did also try with Timer-Flag set as volatile

0 Likes
Reply
Esteemed Contributor II

Some corrections: volatile for the flag is mandantory, program will fail when compiled with "Release" setting

   

INT should be "Rising Edge" for UDBs

   

Flag was not initialized.

   

Period was set, but counter has value from initialization or last stop

   

_StartEx() for interrupt was called within loop, same for Timer_Init()

   

 

   

Happy coding

   

Bob

   

PS: I changed the target to PSoC5, please reverse to PSoC4 4247

View solution in original post

0 Likes
Reply
Esteemed Contributor II

Took me some time to find that "counter-bug", but I'd like you to tell how:

   

When you start the debug-session and the program stops at the first executable instruction of your program

   

Debug -> Windows -> Components -> Check the timer and watch relevant timer registers.

   

When setting a BP at the right place you will see that the counter of the timer runs amok.

   

 

   

Bob

Honored Contributor II

Your "ms_delay" function is blocking. It already has standard implementation in Creator:

   

CyDelayUs( 1000*ms);

   

 

   

odissey1

Contributor II

 No, I am not using it as blocking timer in my application. The project uploaded only contains the timer part.

   

In the actualy project it does this

   

Start Timer();

   

while(!Timeout){

   

  do stuff;

   

}

0 Likes
Reply
Contributor II

 Thanks Bob,

   

The code works fine. I could not determine from the datasheet that you have to set up the counter and timer registers to reset count.

   

Also, the rising edge on the interrupt was something I was not aware of.

   

By the way, how to you see if the Interrupts are enabled? Is there a register you can watch.

   

Regards

   

David

0 Likes
Reply
Esteemed Contributor II

There is an icon in the Creator menu to switch interrupts on and off. The Icon always shows the current state.

   

 

   

Bob

   

PS: When do you sleep???

Contributor II

 Bob,

   

I was just about to ask you when you sleep.

   

Thanks again.

   

I know this question is regarding a different issue than this thread but I am hoping you could help while I "have you" here.

   

I have a PSOC 4 project with digital inputs on P4[2] and P4[0] that I want to set up interrupt on rising edge.

   

However, it appears these pins cannot be "used for routed connections". Referring to the PINS technical guide I see you can access the pins directly but I am not sure how you attach interrupt to them.

   

A while ago I had a similar issue and tech support advised to change the Input Synch mode. This time it does not appear to make any difference. Would using the Pins own INTERRUPT method solve the issue?

   

At the moment I enabled hardware connection and attached isr component

0 Likes
Reply
Esteemed Contributor II

I cannot get that to run, too. Best for you is to try to call the technical support again.

   

 

   

Bob (Local Time 10:15 pm)

0 Likes
Reply
Contributor II

 Will do thanks Bob,

   

The night is but young in your neck of the woods.

   

Local time here is 8:30 am

   

 

   

David

0 Likes
Reply
Honored Contributor II

I think you need to set the input sync mode to "transparent". The default of "double-sync" needs an UDB which is not available on port 4.

0 Likes
Reply
Contributor II

 Yes, I have tried transparent node also.

   

I have looked at the incoming waveform on a scope and it is correct but I cannot seem to properly read the pins.

   

After not being able to detect high going, I tried the cypins_readpin and can detect the clock going high but not data

   

Attached is the waveform. It is fairly slow (clock period is 2ms), data is supposed to be read on high clock.

0 Likes
Reply