styx1.618
Junior Member level 3
- Joined
- Oct 1, 2011
- Messages
- 27
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,283
- Activity points
- 1,492
I have a C code in which i'm finding difficulty to get precise timing according to my need.I'm using PIC18f4550
Calculation that i did is :
FFFF-3500 = CAFF = 51967 +1 (due to FFFF to 0000 count) = 51968(decimal)
51968*0.4usec = 20.78msec
So i should get both high and low portions of 20.78ms i.e.>> Time period = 41.57msec
but in proteus simulation i'm getting double of this value i.e. 41.57msec in both high and low portions(82.78msec as a whole).
View attachment Code+hex file.zip
Please Help is this regard!
Calculation that i did is :
FFFF-3500 = CAFF = 51967 +1 (due to FFFF to 0000 count) = 51968(decimal)
51968*0.4usec = 20.78msec
So i should get both high and low portions of 20.78ms i.e.>> Time period = 41.57msec
but in proteus simulation i'm getting double of this value i.e. 41.57msec in both high and low portions(82.78msec as a whole).
View attachment Code+hex file.zip
Please Help is this regard!
Code:
#include p18F4550.h
#define myPB7bit PORTBbits.RB7
#define myPB6bit PORTBbits.RB6
void T0_ISR(void);
void T1_ISR(void);
#pragma interrupt chk_isr
void chk_isr (void)
{
if (INTCONbits.TMR0IF==1)
T0_ISR();
if(PIR1bits.TMR1IF==1)
T1_ISR();
}
#pragma code My_HiPrio_Int=0x08
void My_HiPrio_Int (void)
{
_asm
GOTO chk_isr
_endasm
}
#pragma code
void main(void)
{
TRISBbits.TRISB7=0;
TRISBbits.TRISB6=0;
T0CON=0x0;
TMR0H=0x35;
TMR0L=0x00;
T1CON=0x88;
TMR1H=0x35;
TMR1L=0x00;
INTCONbits.TMR0IF=0;
PIR1bits.TMR1IF=0;
INTCONbits.TMR0IE=1;
INTCONbits.TMR0IE=1;
T0CONbits.TMR0ON=1;
T1CONbits.TMR1ON=1;
INTCONbits.PEIE=1;
INTCONbits.GIE=1;
while(1) ;
}
void T0_ISR(void)
{
myPB7bit=~myPB7bit;
TMR0H=0x35;
TMR0L=0x00;
INTCONbits.TMR0IF=0;
}
void T1_ISR(void)
{
myPB6bit=~myPB6bit;
TMR1H=0x35;
TMR1L=0x00;
PIR1bits.TMR1IF=0;
}
Last edited by a moderator: