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.

[SOLVED] PIC doesn't rise its timer0 interrupt flag.

Status
Not open for further replies.

mig29fulcrum

Junior Member level 1
Joined
Sep 29, 2011
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,391
Hi...
I have written code for timer0 in which every time TMR0 overflows,it toggles RC0,but i used TMR0IF to indicate that TMR0L and TMR0H are overflow,but when overflow occurs pic doesn't rise its TMR0IF flag and TMR0L resets to 00(TMR0H stays on 0xff). I will appreciate if you help me with this.
Thank you:-D
Code:
#include<P18F2550.h>
#pragma config FOSC=INTOSC_EC
#pragma config WDT=OFF
void main()
{
	TRISCbits.TRISC0=0;
	OSCCON=0x02;
	OSCTUNE=0X80;
	while(1)
        {
		T0CON=0x08;
		TMR0L=0XF0;
		TMR0H=0XFF;
		INTCONbits.TMR0IF=0;
		T0CONbits.TMR0ON=1;
		while(INTCONbits.TMR0IF==0);
		PORTCbits.RC0^=1;
		T0CONbits.TMR0ON=0;
	}
}
I also have same problem with the following code when i use timer0 as 16-bit one(in 8-bit mode everything is ok).
Code:
			LIST P=PIC18F4550
	#INCLUDE P18F4550.INC 
	CONFIG FOSC=INTOSC_EC
	CONFIG IESO=ON
	CONFIG WDT=ON
	ORG   0H
	BCF   TRISC,0
	MOVLW 0X02
	MOVWF OSCCON
	MOVLW 0X08
	MOVWF T0CON
AGAIN
	MOVLW 0XF0
	MOVWF TMR0L
	MOVLW 0XFF
	MOVWF TMR0H
	BCF   INTCON,TMR0IF
	BSF   T0CON,TMR0ON
CHECK
	BTFSS INTCON,TMR0IF
	BRA   CHECK
	BCF   T0CON,TMR0ON
	BTG   LATC,0
	BRA   AGAIN
	END
 

Reference PIC18F2455/2550/4455/4550 Data Sheet, pg 128, Section 11.2 Timer0 Reads and Writes in 16-Bit Mode

TMR0H is not the actual high byte of Timer0 in 16-bit
mode. It is actually a buffered version of the real high
byte of Timer0 which is not directly readable nor
writable (refer to Figure 11-2). TMR0H is updated with
the contents of the high byte of Timer0 during a read of
TMR0L. This provides the ability to read all 16 bits of
Timer0 without having to verify that the read of the high
and low byte were valid, due to a rollover between
successive reads of the high and low byte.

Similarly, a write to the high byte of Timer0 must also
take place through the TMR0H Buffer register. The high
byte is updated with the contents of TMR0H when a
write occurs to TMR0L. This allows all 16 bits of Timer0
to be updated at once.

The above section indicates that to store a 16-bit value in the TIMER0 registers you must first write the TMR0H followed by the write to TMR0L which triggers both values to be written into the timer module. When reading the TIMER0 16-bit value you must perform the reads exactly opposite, first read TMR0L followed by a read of TMR0H.

Therefore make the following code changes:

Code:
#include<P18F2550.h>
#pragma config FOSC=INTOSC_EC
#pragma config WDT=OFF
void main()
{
	TRISCbits.TRISC0=0;
	OSCCON=0x02;
	OSCTUNE=0X80;
	while(1)
        {
		T0CON=0x08;
		[COLOR="#FF0000"]TMR0H=0XFF;   //switch the TMR0H and TMR0L writes as shown here
		TMR0L=0XF0;[/COLOR]
		INTCONbits.TMR0IF=0;
		T0CONbits.TMR0ON=1;
		while(INTCONbits.TMR0IF==0);
		PORTCbits.RC0^=1;
		T0CONbits.TMR0ON=0;
	}
}

Perform a similar switch in your assembly code version.

Hope the info helps,

BigDog
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top