Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/21/04 12:34
Read: times


 
#81609 - Timer 2 interrupt with keil.
Hi Friends,
I am stuck with a very strange problem. I am using P89V51RD2 @ 8MHz crystal in 6 clock/cycle mode. I am using a PCF8591 I2C ADC for getting current feedback from a CT. For getting current signal samples at a fixed interval I am using timer 2 interrupt in 16 bit autoreload mode. Here is how I initialize the timer.

RCAP2H=0xfa;			
RCAP2L=0xca;
TH2=RCAP2H;
TL2=RCAP2L;
T2CON=0x00;
EA=1;
ET2=1;
TR2=1;


Here is the interrupt service routine to get the samples from ADC with soft I2C. Before this interrupt start I am activating the appropriate channel of ADC and reading the dummy byte send the start bit and then leave it for continous read with acknowledge after each read.

void t2_isr(void) interrupt 5 using 1
{
    uchar it2=8, bt2;
	uint bsqr;
	TF2=0;

    PSDA = 1;
  do{
    I2CWAIT;
    PSCL = 1;
    I2CWAIT;
    bt2 <<= 1;		// shift 0 in
    if( PSDA )
      bt2++;		// set to 1
    PSCL = 0;
  }while( --it2 );

  PSDA = 0;
  I2CWAIT;
  PSCL = 1;
  I2CWAIT;
  PSCL = 0;
  
  bsqr=bt2*bt2;
  RMSSUM+=bsqr;
  samples++;
}


The problem is the program is getting stuck in very long time loop sort of. it doesn't hang but gets stuck for some seconds. When I comment out the do while() part in above ISR everthing works smoothly. I have tried putting this same ISR with another small program and measured the time required for executing ISR and it comes out to be 231 machine cycles i.e. approx 170us with my configuaration. With that small program comprising of lcd routines and interrupt 2 routine the same isr works fine but with my main program it is giving problem. What could be the reason for this?????

My entire program is too big to be posted here but if required I will post the link to it. If you guys need any further information I will post it.

Thanks & Regards,
Prahlad Purohit

List of 18 messages in thread
TopicAuthorDate
Timer 2 interrupt with keil.            01/01/70 00:00      
   Additional Information.            01/01/70 00:00      
   what is I2CWAIT;            01/01/70 00:00      
      I2CWAIT is not Function.            01/01/70 00:00      
   Remove            01/01/70 00:00      
      Already tried remove using 1            01/01/70 00:00      
         Timer2 interrupt            01/01/70 00:00      
            Tried making all ISR variables global.            01/01/70 00:00      
               Timer2 Interrupt            01/01/70 00:00      
      Why remove using?            01/01/70 00:00      
      removing using            01/01/70 00:00      
         Re: Remove Using.            01/01/70 00:00      
   int usage            01/01/70 00:00      
      int operations reentrant or not?            01/01/70 00:00      
         varify with asm            01/01/70 00:00      
   A couple of things            01/01/70 00:00      
      Re: A couple of things - Neil            01/01/70 00:00      
         A couple of things            01/01/70 00:00      

Back to Subject List