First pulse is not counting

Status
Not open for further replies.

ADGAN

Full Member level 5
Joined
Oct 9, 2013
Messages
295
Helped
4
Reputation
8
Reaction score
4
Trophy points
18
Visit site
Activity points
1,837
Hi! I wrote a program to count the pulses coming from an energy measurement IC. But I observed that the first pulse is not counted both in Proteus and in hardware. So I'm assuming that something must be wrong in the software. I'm using the timer1 for this task of PIC16F887. What I suspect is the T1CON. What is the mistake I have done?

Code:
void main()
{
     ANSEL = 0;
     ANSELH = 0;
     TRISA = 0;
     C1ON_bit = 0;                      // Disable comparators
     C2ON_bit = 0;
     PORTA.RA0 = 1;
     TRISB = 0;
     PORTB = 0;
     PORTC = 0;
     TRISC = 0x99;
     INTCON = 0xC0;

     PIE1.TMR1IE = 1;
     PIR1.TMR1IF = 0;

     T1CON = 0x03;
     TMR1L = 0;
     TMR1H = 0;
     I2C1_Init(100000);
     Lcd_Init();
     Delay_ms(100);                  // Delay 100ms
     Lcd_Cmd(_LCD_CURSOR_OFF);
     Lcd_Cmd(_LCD_CLEAR);
     
 

      while(1){

      pulses = (count*65536)+ (TMR1H<<8 | TMR1L);
     
      LongToStr(pulses,txt);
      Lcd_out(1,9,txt);



      }
   }
 

Yes all the other pulses are counting correctly. How do I correct this?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…