Need help for Programming a Timer 1 in P89V51RD2BN

Started by Nvidia, November 28, 2009, 02:21:37 AM

Previous topic - Next topic

Nvidia

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.

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.

Mucter

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.


Jan Waclawek

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

JW