umery2k75
Advanced Member level 1
pic 16f877a timer1 c program
I'm happy with the code, the code works fine and I know the simple logical working of interrupts and how to set the values to get desired response, but the thing which bothers me is that, why Timer 1 starts it's operation very late? I have looked for this thing in it's data sheet too, but I couldn't find anything. If you people know about this, then tell me, but I don't hope that this problem can be answered. I think in this way, because I couldn't find anything on the PIC16F877A datasheet that has a factor which has its effect on Timer1 operation.
I have two codes one that was made around Timer0 8-bit and other was built around Timer1 16-bit.
TIMER 0(8-BIT)
==========
As soon as the PIC is power on, I can see the output of PIN_B0 attached by LED turning ON/OFF immediately afterpowering up. I'm happy with it's output.
TIMER 1(16-BIT)
==========
When PIC is powered on, The ouput PIN_B0 having LED on it, turns ON and it remain On for around 63-64 seconds.After this begins its normal LED blinking work,I don't understand why the interrupt response is getting started too late, why delay is there?
Timer1 seems like a old Diesel engine to me, which is kept at some place in North Pole, which is trying to start on in intense cold.
The time is precise, it takes around somewhere 63-64 seconds to turn on
Added after 1 minutes:
Please don't care about the values in the diagram like 109mS and 18.30mS. I made that diagram for some other work.
I'm happy with the code, the code works fine and I know the simple logical working of interrupts and how to set the values to get desired response, but the thing which bothers me is that, why Timer 1 starts it's operation very late? I have looked for this thing in it's data sheet too, but I couldn't find anything. If you people know about this, then tell me, but I don't hope that this problem can be answered. I think in this way, because I couldn't find anything on the PIC16F877A datasheet that has a factor which has its effect on Timer1 operation.
I have two codes one that was made around Timer0 8-bit and other was built around Timer1 16-bit.
TIMER 0(8-BIT)
==========
Code:
#include<16F877A.H>
#include<string.h>
#use delay (clock=03579545)
#fuses NODEBUG,XT,NOWDT,PUT,NOPROTECT,NOLVP
#use rs232 (baud=2400,xmit=PIN_C6,rcv=PIN_C7)
#define INTS_PER_SECOND 6
int8 int_counts;
int8 ledstate=0;
int8 Hun_Milli_Seconds_Count=0;
#int_rtcc
void clock_isr()
{
if(--int_counts==0)
{
++Hun_Milli_Seconds_Count;
int_counts=INTS_PER_SECOND;
}
}
void main()
{
set_tris_b(0x00);
output_low(PIN_B0);
setup_counters(RTCC_INTERNAL,RTCC_DIV_64);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
while(1)
{
if(Hun_Milli_Seconds_Count==0) //Makes up approx. a sec
{
output_high(PIN_B0);
}
if(Hun_Milli_Seconds_Count==1) //Makes up approx. a sec
{
output_low(PIN_B0);
}
if(Hun_Milli_Seconds_Count==2) //Makes up approx. a sec
Hun_Milli_Seconds_Count=0;
}
}
As soon as the PIC is power on, I can see the output of PIN_B0 attached by LED turning ON/OFF immediately afterpowering up. I'm happy with it's output.
TIMER 1(16-BIT)
==========
Code:
#include<16F877A.H>
#include<string.h>
#use delay (clock=03579545)
#fuses NODEBUG,XT,NOWDT,NOPUT,NOPROTECT,NOLVP
#use rs232 (baud=2400,xmit=PIN_C6,rcv=PIN_C7)
#define INTS_PER_SECOND 1
int8 int_counts;
int8 ledstate=0;
int8 Hun_Milli_Seconds_Count=0;
#int_TIMER1
void clock_isr()
{
if(--int_counts==0)
{
++Hun_Milli_Seconds_Count;
int_counts=INTS_PER_SECOND;
}
}
void main()
{
set_tris_b(0x00);
output_low(PIN_B0);
set_timer1(0);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // setup interrupts
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(1)
{
if(Hun_Milli_Seconds_Count==0) //Makes up approx. a sec
{
output_high(PIN_B0);
}
if(Hun_Milli_Seconds_Count==1) //Makes up approx. a sec
{
output_low(PIN_B0);
}
if(Hun_Milli_Seconds_Count==2) //Makes up approx. a sec
Hun_Milli_Seconds_Count=0;
}
}
When PIC is powered on, The ouput PIN_B0 having LED on it, turns ON and it remain On for around 63-64 seconds.After this begins its normal LED blinking work,I don't understand why the interrupt response is getting started too late, why delay is there?
Timer1 seems like a old Diesel engine to me, which is kept at some place in North Pole, which is trying to start on in intense cold.
The time is precise, it takes around somewhere 63-64 seconds to turn on
Added after 1 minutes:
Please don't care about the values in the diagram like 109mS and 18.30mS. I made that diagram for some other work.