Flash Magic Forum
September 09, 2010, 07:34:30 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Need help for Programming a Timer 1 in P89V51RD2BN  (Read 1298 times)
Nvidia
Newbie
*
Posts: 1


View Profile
« on: November 28, 2009, 11:21:37 AM »

Aim : To generate a pulse of 4ms using a Timer1.(50% duty cycle) i.e. 4ms ON time and 4ms OFF time

Using Timer 1 the reload values calculated are  as follows

4ms*11.0592M = (FFFF- Reload value)*6
so there fore Reload value = E333.

This was the value I loaded into the program and when I saw output on P1.1 the ociloscope showed 8ms.

Now Problem : is (FFFF-Reloadvalue)*12 instead of 6.But data sheet shows osc/6.Here is my program : Please help me.

Code:
sbit port = P1^1;
   void main(void)
   {
    WDTC = 0x00;
CMOD = 0x00;
PCON = 0x00;
P1 = 0xFF;
TMOD = 0x10;
TCON = 0x00;
TL1 = 0x33;
TH1 = 0xE3;

TR1 = 1; // Start the Timer1
EA = 1;
ET1 = 1;
while(1)
{
TL1 = 0x33;
TH1 = 0xEE;
TR1 = 1;
}
}
}

void TIMER1_ISR(void) interrupt 3
{
TF1 = 0;
TR1 = 0;

port = ~ port;
}


Please help me.Is there any mistake in my Code or the Data sheet is wrong.
Logged
Mucter
Newbie
*
Posts: 20


View Profile
« Reply #1 on: November 30, 2009, 03:05:26 AM »

I have some questions.

1. Why Do You set TL1,TH1 in infinite loop.
If you intend to set initial value of TL1,TL2 , You must set values only one time.
TL1,TL2 can be overwriten by 0x33, 0xEE before interrupt occurs.

2. Do you intend to operate in timer 1 mode 1 [16-bit Timer/counter ‘THx’ and ‘TLx' are cascaded;
there is no prescaler]
in datesheet Fig 9.[Timer/counter 0 or 1 in mode 1 (16-bit counter)] ?
If so , why don't you set TL1 and TH1 to next values in interrupt rootine TIMER1_ISR.

3.in your sample code, there are 3 {s and 4 }s. Is A } after TR1=1; not needed?

I didn't understand your intention in your sample code.
regards, Mucter.

Logged
Jan Waclawek
Full Member
***
Posts: 211


View Profile WWW
« Reply #2 on: December 04, 2009, 10:52:09 PM »

As this is not FlashMagic relevant, you might want to consider coming to the 8052.com forum with your question.

JW
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!