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.

8052 Timer2 with serialInterrupt

Status
Not open for further replies.

IanP

Advanced Member level 7
Advanced Member level 7
Joined
Oct 5, 2004
Messages
7,929
Helped
2,311
Reputation
4,624
Reaction score
531
Trophy points
1,393
Location
West Coast
Activity points
66,416
8052 timer2

Here is the code I use for Timer2 interrupt:

T2Int: CLR T2CON.7
CLR T2CON.0
PUSH ACC
PUSH PSW
INC ScrollFreq
MOV A, ScrollFreq
CJNE A, #0Fh, T2_Exit
SETB Scroll1Right
T2_Exit: POP PSW
POP ACC
RETI

I want bit Scroll1Right to be set 50 times/s, 5/s .... but as it is now it is set every 10-12 secs.
With ScrollFreq set to 00h this interrupt occures about 3times/sec and that is the fastest.
The T2CON=00h.
Maybe someone fresh can have a look at the above code and find out why the execution is so slow..
 

8052 timer2 interrupt

Hi IanP,
I don't understand your question but it seems you forgot to clear ScrollFreq's value.
It starts with 00H, continue to 0FH and then continue to 10H, 11H, ... , FFH, 00H, ...
So it uses 256 times for setting Scroll1Right, not 15.
 

    V

    Points: 2
    Helpful Answer Positive Rating
t2mod register in 8052

Nope,

It is cleared outside the T2Int after the bit Scroll1Right is set/cleared.

The main problm is that the Timer2 should overflow within ms and not s.
Even if the ScrollFreq is 00h it overflows approx. 3!!!! times/sec.
 

8052 timer 2

How is T2MOD configured?

What is the contents of RCAP2L and RCAP2H as these values are loaded into T2 on an overflow in timer mode.

best regards
 

8052 timer 2 baud rate

Hi
U can use this calculator to get values for timer reload
 

timer2 interrupt

C_Man,

T2MOD is 00h.
Counter counts in a loop of FF FFh (16-bit autoreload) so an interrupt should be generated after 65536 counts.
Now, other matter is that it is not 8052 but 87C51FB and ALL other interrupts are active with serial port interrupt as the highest priority (bit PS set).
 

timer2 interrupt 5

Do u have other interrupts? such as serial interrupt or any.
 

51 timer2 rcap2h

Other 5 innterupts are active and OK.

Int0 - PS/2 keyboard
Int1 - RTC
Timer0 - Time-out interrupt
Timer1 - Baud rate
Serial Port Interrupt - Data from GPS/Data logger

Problem is with this one:
Timer2 - Interrupt to be used for scrolling text
 

reti 8052

If you set T2CON=00h, as you say, Timer2 wouldn't run at all, so I presume
you set T2CON.2=1 somewhere else in your code.

What is your clock frequency?
If it is 3,5 MHz and RCAP2L and RCAP2H are both set to 00h your interrupt
rate will be quite "slow".

The correct way to use a timer is to select a value for RCAP2L/RCAP2H that
gives a nice timer "tick" - e.g. 20 ms would give you an interrupt rate of 50/s.
Then you can count 10 interrupts to get 5/s.

Furthermore, you could simplify your interrupt routine by using the DJNZ instruction:

T2Int: CLR T2CON.7
CLR T2CON.0

DJNZ ScrollFreq, T2_Exit
SETB Scroll1Right

T2_Exit: RETI

ScrollFreq=1 will set Scroll1Right after 1 interrupt, ScrollFreq=2 will set it after 2 interrupts etc.

/Rambo
 

8052 interrupt 1 example

That is right.
TR2 is set in the very begining of the code to start timer2 and ET2 is set to enable timer2 interrupt.
Clock frequency is 11,095,200Hz.
What do you mean by "quite slow"???
 

t2mod 8052

OK, a 11 MHz clock shouldn't give such a slow interrupt rate.
I'm not familiar with 87C51FB but presuming it divides the clock by 12, as usual,
your shortest timer tick would be 1,08 us and you should load RCAP2L/RCAP2H
with B800h to get a 20 ms timer cycle.

Have you set the interrupt priority for Timer2 to be the highest?
Timer2 has a natural priority that is lower than e.g. Timer1, which is usually used
as a Baud rate generator, so it might be interfering with Timer2 interrupts.
The system timer interrupt should, in most cases, have the highest priority.

/Rambo
 

rcap2l rcap2h

The interrupt priority is set for serial port as this is the most important data that has to be collected.
As the timer2 subroutine is quite short I will try to set both priority bits: for Timer2 and for serial port.
I don't want to play with RCAP2 registers because the speed of the "running text" is controlled by ScrollFreq byte which is increased/decreased through PS/2 keyboard.
If it is 500ms, 200..... it really doesn't matter; I just want to have control on what s going on.
So, I will try with the priorities....

By the way, 87C51B is exactly the same as 8052 + 8kB of OTP.
 

serial port c code for 8052

I think maybe the other interrupts interfere Timer2.
You should check both external interrupt for sure they're not interrupt too frequently.
The other case is serial interrupt. Can you post your code about checking and clearing TI and RI?
 

timer2 8052 microcontroller

Here is part of Ser_Int subroutine:

Ser_Int: PUSH ACC
PUSH PSW

JB TI, Tx_Mit1
Recv_1: CLR RI
MOV A, RxBuffHead
INC A
CJNE A, #RxBuff+RxBuffSize, Recv_2
MOV A, #RxBuff
Recv_2: CJNE A, RxBuffTail, Recv_Ok
POP PSW
POP ACC
RETI

Recv_Ok: MOV RxBuffHead, A
XCH A, R0
PUSH ACC
MOV A, SBUF
MOV @R0, A
POP ACC
MOV R0, A

POP PSW
POP ACC
RETI

Tx_Mit1: CLR TI
MOV A, TxBuffTail
CJNE A, TxBuffHead, Tx_Mit2
MOV TxBuffHead, #00h
POP PSW
POP ACC
RETI
Tx_Mit2: INC A
CJNE A, #TxBuff+TxBuffSize, Tx_Mit3
MOV A, #TxBuff
Tx_Mit3: MOV TxBuffTail, A
XCH A, R0
MOV SBUF, @R0
MOV R0, A
POP PSW
POP ACC
RETI
 

using serial port 0f 8052 timer2

Sorry, I forgot u use assembly. Some problems that I think can occur from C, but less in assembly.
From your all information, I don't see anything wrong. But I still think your problems occur because your many interrupts interfere Timer2.
You should try to disable each interrupt and see what happen, or something like this.
Please post again if your result is good or not, or some more info if you have.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top