Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

difference in timing

Status
Not open for further replies.
A good example of a ridiculous post!
 
sachin.kolkar said:
hi guys,
i m facing problem with timer

If it a boiled egg Timer, the sand has probably got damp..:rolleyes:
 
Pommie said:
Unbelievable.

Mike.
i m sending my code
Code:
unsigned short counter,second,m;
 void main()
{
TRISB=0x00;
PORTB=0x0F;
T1CON=0b00001001;
TMR1H=0x80;
TMR1L=0x0F;
T1CON.TMR1ON=1;
PIR1.TMR1IF=0;
PIE1.TMR1IE=1;
INTCON=0xC0;
d0
{
 if(counter==30)
{
 counter=0;
second++;
if(second==60)
{
m++;
second=0;
if(m==1)
{
m=0;
PORTB=~PORTB;

}
}
}

}while(1);
}

void interrupt()
{
counter++;
TMR1H=0x80;
TMR1L=0x04;
PIR1.TMR1IF=0;
}

when i burn this programme to PIC16F72, first cycle it toggles at near 2mins,
for next cycles it exactly toggles at 1min...

is it tkes that extra time for boot up or what?
how can i overcome by this problem?
Plz help me .....:confused:
 
That is because you don't initialise counter or seconds in your code. Try setting them to zero at the start of your main routine.

Mike.
 
The lack of initialisation was fairly obvious. The really confusing thing is the D0 (zero) instead of DO and the spurious closing braces. I assume this was introduced while copying.

Mike.
 
Pommie said:
That is because you don't initialise counter or seconds in your code. Try setting them to zero at the start of your main routine.

Mike.
do you mean that making TMR1L=0x00; TMR1H=0x00; is initializing the counter right ..........
What do you mean by initialize the second?
PLZ send me some example code of initializing the second.
 
Pommie said:
That is because you don't initialise counter or seconds in your code. Try setting them to zero at the start of your main routine.

Mike.
do you mean that making TMR1L=0x00; TMR1H=0x00; is initializing the counter right ..........
What do you mean by initialize the second?
PLZ send me some example code of initializing the second.
 
Just set them to zero,
Code:
unsigned short counter,second,m;
void main()
{
[COLOR="Blue"]    counter=0;
    second=0;[/COLOR]
    TRISB=0x00;
    PORTB=0x0F;
    T1CON=0b00001001;
    TMR1H=0x80;

You might also consider setting m=0 as well.

Mike.
 
Pommie said:
Just set them to zero,
Code:
unsigned short counter,second,m;
void main()
{
[COLOR="Blue"]    counter=0;
    second=0;[/COLOR]
    TRISB=0x00;
    PORTB=0x0F;
    T1CON=0b00001001;
    TMR1H=0x80;

You might also consider setting m=0 as well.

Mike.

Thanx it working fine....
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top