Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18f4550 Timer calculation problem inside an Interrupt Routine

Status
Not open for further replies.

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!

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:

What is the source of the system clock, crystal, oscillator, etc?

What is the frequency of the system clock (Fosc)?

What are the current configuration register settings of the device?

The PIC18F4550 has a fairly complex clocking system, the PLL in particular, which often results in the device operating at an unexpected clockrate.

Also, are you using the Proteus simulation clock to determine these stated clock intervals?

I have yet to examine your code, however the above issues are quite common when dealing with the PIC18F4550.

BigDog
 

Unfortunately Kripton, the links on the webarchive page appear to be no longer valid as well.



BigDog
 

The crystal oscillator attached is of 10MHz frequency. Also, I'm using Proteus' virtual oscilloscope to get the simulations. I having a feeling that getting exactly double the time has some sort of simple but hidden thing going own.
 

Besides the crystal frequency, the current configuration register settings are needed to determine the actual system clock frequency (Fosc).

The PIC18F4550 has a Phase Lock Loop (PLL) which can often be a source of confusion concerning the actual Fosc.

You can easily have a PIC18F4550 operating at a frequency several times that of the attached crystal.



BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top