Mithun_K_Das
Advanced Member level 3
- Joined
- Apr 24, 2010
- Messages
- 899
- Helped
- 24
- Reputation
- 48
- Reaction score
- 26
- Trophy points
- 1,318
- Location
- Dhaka, Bangladesh, Bangladesh
- Activity points
- 8,254
Hello everyone,
I was trying to generate a timing pulse which is related with INT hardware interrupt. Like Timer0, Timer1 is not mask-able. That is why here I'm using a variable to count per 0.25mS. And that counter is compared with preset value. When there is a hardware interrupt, the counter is reset to zero.
Normally it works in circuit. But problem is very small fluctuation in timing. How can I improve this fluctuation ?
Here is the Video:
Code:
Proteus file: Please check attachment.
MikroC file: Please check attachment.
Attachments. Proteus file and mikroC file.
I was trying to generate a timing pulse which is related with INT hardware interrupt. Like Timer0, Timer1 is not mask-able. That is why here I'm using a variable to count per 0.25mS. And that counter is compared with preset value. When there is a hardware interrupt, the counter is reset to zero.
Normally it works in circuit. But problem is very small fluctuation in timing. How can I improve this fluctuation ?
Here is the Video:
Code:
Code:
#define Trigger GP4_bit
void InitTimer1()
{
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0xFF;
TMR1L = 0x06;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
bit trigger_mask;
int Trigger_cnt=0;
int Firing_cnt=0;
void Interrupt() iv 0x0004 ics ICS_AUTO
{
if(INTF_bit)
{
INTF_bit=0;
Trigger_cnt=0;
Trigger = 0;
trigger_mask=0;
INTEDG_bit=~INTEDG_bit;
}
if (TMR1IF_bit)
{
TMR1IF_bit = 0;
TMR1H = 0xFF;
TMR1L = 0x06;
Trigger_cnt++;
if(Trigger_cnt>=Firing_cnt && !trigger_mask)
{
Trigger = 1;
Delay_us(100);
Trigger = 0;
trigger_mask = 1;
}
}
}
void main()
{
TRISIO=0b00001100;
GPIO=0x00;
ANSEL=0x00;
ADCON0=0x00;
CMCON=0x07;
InitTimer1();
GIE_bit = 1;
PEIE_bit = 1;
INTE_bit = 1;
INTF_bit=0;
INTEDG_bit=0;
while(1)
{
}
}
Proteus file: Please check attachment.
MikroC file: Please check attachment.
--- Updated ---
Attachments. Proteus file and mikroC file.