This Question is Possibly Answered

1 "correct" answer available (4 pts)
433 Views 9 Replies Last post: Nov 23, 2009 6:58 AM by ckgrier RSS
kuttanda navin Newbie 8 posts since
Nov 19, 2009
Currently Being Moderated

Nov 19, 2009 10:45 PM

R8C27 TIMER INTRRUPT

HELLO;

 

COULD YOU PLEASE SUGGEST ME A SOLUTION FOR A PROBLEM ON TIMER B, TIMER MODE  INTRRUPT.

 

ACTUALLY I AM USING THIS IS FOR A SITUATION .ie  WHERE SENSOR2 HAS TO BE  SENSED SOON AFTER , SENSOR 1 GETS SENSED. SUPPOSE IF SENSOR2 HAS NOT SENSED , AFTER SENSOR1 GOT SENSED ,THE OPERATION HAS TO BE STOPPED.MEANWHILE CONTROLLER IS DOING SOME OTHER JOB

PARALLELLY.

 

 

 

 

 

TIMER B SET AT TIMER MODE , AND TRBIC IS SET TO 0X02 , (INTRRUPT CONTROL REGISTER)

 

THE TIMER INTRRUPT GETS RAISED FOR EVERY 25MSEC , AND INCREMENTS THE VARIABLE. THIS IS WORKING FINE.INTRUUPTS GETS RAISED FOR EVERY 25MSEC.

 

 

 

TIMERB_ISR( )                                    // INTRRUPT SERVICE ROUTINE

{

    IR_TRBIC = 0;

    VARIABLE ++;

 

      IF (VARIABLE == 100)

       {

           FUNCTION1( );

      }

 

}

 

 

 

 

MAIN( )

{

-----

----

----

          FUNCTION( );

 

 

 

WHILE(1);

 

}

 

 

 

VOID FUNCTION(VOID)

{

 

TIMER START FLAG = 0;

 

     WHIE( SENSOR1 == 0) ;

 

      IR_TRBIC = 0;

      TRBPR = 200 ;   // THE TIMER B IS STARTED

      TRBP  = 200;

     TRBIC = 0X02;

     TIMER START FLAG = 1;

 

 

OTHER_OPERTION( );

 

}

 

 

ATER VARIABLE GETS EQUAL TO 100 , THE FUNCTION( )  IS CALLED AND AGAIN ITS CHECKS FOR SENSOR1, IF IT IS ONE , THEN AGAIN TIMER IS SWITCHED ON,

 

PROBLEM:  AT THIS POINT THE INTRRUPT IS NOT RAISED FOR EVERY 25MSEC AND THE ,INTRRUPT SERVICE ROUTINE IS NOT SERVICED. THIS IS THE PROBLEM.

 

 

 

 

could you please help me out,

thanking you

naveen

Tags: intrrupt, timerb
FrankL Apprentice 1,100 posts since
Mar 16, 2009
Currently Being Moderated
Nov 20, 2009 1:11 AM in response to: kuttanda navin
Re: R8C27 TIMER INTRRUPT

First, you don't need to reset any interrupt request flag in the interrupt routine (IR_TRBIC=0). The interrupt request flag is reset automatically when an interrupt is accepted and the software jumps to the interrupt routine.

Is only the timer interrupt not executed any more, or does the software stop?

Are FUNCTION and FUNCTION1 the same?

If not, the function at the end should be FUNCTION1 I believe?

If so, you should try to reduce the code executed in the interrupt routine. I think best would be if you only increment VARIABLE in Timer RB interrupt, and do the test  "if (VARIABLE==100)" in main(). Otherwise, you have to be careful which functions are called in the interrupt routine and make sure all of them are re-entrant.

FrankL Apprentice 1,100 posts since
Mar 16, 2009
Currently Being Moderated
Nov 20, 2009 1:14 AM in response to: kuttanda navin
Re: R8C27 TIMER INTRRUPT

What means "// calling  ISR FROM HERE"? timer_rb IS the ISR, isn't it?

FrankL Apprentice 1,100 posts since
Mar 16, 2009
Currently Being Moderated
Nov 20, 2009 3:26 AM in response to: kuttanda navin
Re: R8C27 TIMER INTRRUPT

Could it simply be that there is no

     VARIABLE=0;

in FUNCTION? In this case you only have to wait a little longer until VARIABLE overflows and reaches again 100.

ckgrier Apprentice 840 posts since
Mar 16, 2009
Currently Being Moderated
Nov 20, 2009 2:39 PM in response to: kuttanda navin
Re: R8C27 TIMER INTRRUPT

Don't branch to FUNCTION1 from inside the ISR. This means you never return from the ISR after you get to 100.

ckgrier Apprentice 840 posts since
Mar 16, 2009
Currently Being Moderated
Nov 23, 2009 7:03 AM in response to: kuttanda navin
Re: R8C27 TIMER INTRRUPT

Set a flag in a global variable to signal the ISR has happened. Then branch to FUNCTION1 inside of the "interrupted program". This is the way a forwground/background application is written - ISRs mainly change variables or flags, and the main functions do all the work.

 

If you want to look a way to do this with "threads" or tasks, then an RTOS or simple threading might be in order.

http://en.wikipedia.org/wiki/Protothreads

 

There's an R8C example here:

http://www.renesasrulz.com/docs/DOC-1187

More Like This

  • Retrieving data ...

Bookmarked By (0)