Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

SimulIDE and Timer1 flag TMR1IF in PIC16F887

2 posters

Go down  Message [Page 1 of 1]

jaltiti



Timer1 flag TMR1IF does not get detected when TMR1H and TMR1L reaches 65536 (overflow). as the statement below does not get recognized by SimulIDE. the code is written in MikroC PRO. SimulIDE does not get out of the statement
while (TMR1IF_BIT == 0);

void main()
{
int i;
TRISD = 0;
PORTD = 0x55;
TMR1CS_BIT = 0;
T1CKPS0_BIT = 0;
T1CKPS1_BIT = 0;
TMR1GE_BIT = 0;
TMR1ON_BIT = 0;
TMR1IF_BIT = 0;
while(1)
{
for(i = 0; i <153; i++)
{
TMR1L = 0x00;
TMR1H = 0x00;
TMR1ON_BIT = 1 ;
while (TMR1IF_BIT == 0); // THE PROBLEM IS HERE
PIR1.TMR1IF = 0;
TMR1ON_BIT = 0;
}
PORTD = ~PORTD;
}
}

arcachofo

arcachofo

Hi.
I will have a look.

jaltiti likes this post

jaltiti



Thank you for looking into it. I tried to work around the issue (should not be a solution) by replacing
while (TMR1IF_BIT == 0); by while ((TMR1H & TMR1L) != 0xFF) and preceding the statement by PORTC.RC7 =  0; now why PORTC.RC7 no logic behind it. I tried all other ports and it works. I tried PORTB.RB0 = 0, PORTA = 0, PORTA_RA0 = 0, ..........etc. and the timer worked !!!!!!!!!. By the way if you do not precede while ((TMR1H & TMR1L) != 0xFF) with what is mentioned above, the timer will not work.
void main()
{
int i;
TRISD = 0;
PORTD = 0x55;
TMR1CS_BIT = 0;
T1CKPS0_BIT = 0;
T1CKPS1_BIT = 0;
TMR1GE_BIT = 0;
TMR1ON_BIT = 0;
TMR1IF_BIT = 0;
while(1)
{
for(i = 0; i <153; i++)
{
TMR1L = 0x00;
TMR1H = 0x00;
TMR1ON_BIT = 1 ;
PORTC.RC7 = 0; // BY LUCK AND RAMDOMLY WITHOUT ANY LOGIC BEHIND IT. IT WORKS. IT CAN BE ANY PORT      
while ((TMR1H & TMR1L) != 0xFF); // TESTING TO SEE IF TIMER1 REACHES 65536
PIR1.TMR1IF = 0;
TMR1ON_BIT = 0;
}
PORTD = ~PORTD;
}
}

jaltiti



I should mention that the above work around (not a solution) only applies for the above specific timer1 code. If you change the prescaler values or the TMR1H and TMR1L values it will not work. I believe that SimulIDE simulator code does not set TMR1IF that is bit 0 of the PIR1 register when the counter value TMR1H/TMR1L (16 bit value) overflow to 65536.

arcachofo

arcachofo

Yes, looks like the interrupt flag is not set in PIC16F887.

I will solve it.

jaltiti likes this post

jaltiti



Is this issue solved?

arcachofo

arcachofo

Not sure about this one.
Have you tried with last version?

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum