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.

How to calculate/get the -200 = 0.2ms in the code below?

Status
Not open for further replies.

Help

Advanced Member level 2
Joined
Feb 15, 2005
Messages
617
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Activity points
7,065
0.2m Sec

Hi,

Anyone know how to calculate/get the -200 = 0.2ms?? Is it the -200 is the dec number??

TMOD = 0x02; /* TIMER0 at Mode 2 */
TH0 = -200; /* 0.2ms (200us) */
TL0 = -200;
TR0 = 1; /* start timer */

Thank You.
 

Re: 0.2m Sec

Timer0(1) in MODE2 is a 8-bit counter (TL0(1), fed from clock/12) and at 11.0952MHz clock you need ≈184d reload value in TH0(1) to achieve 0.2ms ..
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: 0.2m Sec

Hi,

What is ~184d reload?? how to calculate the value? -200??

Thank You..
 

Re: 0.2m Sec

In assembly language sometimes negative values, such as -200, are represented by FF38 (65536-200)..

Reload value of 184d is calculated as follows:
11059200/12=921600 - clock frequency to TIMER0 in MODE2

1/(921600*X)=0.0002s
X=184.32 ≈ 184d
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: 0.2m Sec

Hi

Reload value of 184d is calculated as follows:
11059200/12=921600 - clock frequency to TIMER0 in MODE2

1/(921600*X)=0.0002s
X=184.32 ≈ 184d

How do you know is 0.2ms?? Can you explain mare what is X value for what??

Thank You
 

Re: 0.2m Sec

X is just a sumbol used to solve an equasion; you can use A, B, C or Z, but it is still the reload value for TH1.

If the input pulse to TIMER0 equals to 1/ 921600 = 1.085µs then if you multiply this value by 184 the resultant time will be 1.085µs * 184 ≈ 0.2ms
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: 0.2m Sec

Hi,

I still not understand the "reload value for TH1", the mode 2 have related to T1??

Thanks..
 

Re: 0.2m Sec

Both timers, TIMER0 and TIMER1 are identical in modes 0, 1 and 2;
So for Timer0 the reload value will be for TL0 and TH0,
for TIMER1: TL1 and TH1 ..
Sorry for confusion ..
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: 0.2m Sec

Hi,

Nvm, so..

TMOD = 0x02; /* TIMER0 at Mode 2 */
TH0 = -200; /* 0.2ms (200us) */
TL0 = -200;
TR0 = 1; /* start timer */

Now i setting is Timer0, so the you mean reload value is for TH0 is it??

Thanks..
 

Re: 0.2m Sec

Initially you have to reload both TL0 and TH0 and after first overflow fromTL0 it will set TF0 and also reloads TL0 with TH0 ..
And the reload value of TH0 remains unchanged ..
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: 0.2m Sec

Ya.. Is true the TH0 still remains unchanged at 0x38 because we already set it. So how about the 184 value?? for what??

Thanks..
 

Re: 0.2m Sec

200 is the value for clock frequency of 12MHz;
184 is the value for clock frequency of 11,0592MHz ..
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: 0.2m Sec

Oh.........,
Now i already understand, very thk u!!

Why use 11,0592MHz standard they use 12MHz is it??

Thank
 

Re: 0.2m Sec

It look like that, as the input frequency to TIMER0 will be 1MHz (1µs) @ 12MHz crystal .. multiplied by 200 gives you 200µs ..
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: 0.2m Sec

Hi,

Thank You vary much now i really understand already.

Do you have any web side, or reference book for explaining this type of code (timer, counter, interrupt, overflow and so on) and give some simple code... ??

Thank You..
 

Re: 0.2m Sec

What I use as reference is a hard copy of "80C51-Based 8-bit Microcontrollers - Data Handbook" from Philips Semiconductors .. It is about 1400 pages ..
I'm not sure if you can download something like this from the net ..
 

Re: 0.2m Sec

Hi,

So, do you have any simple sample program for you own experience because now i like studying theory and no have practice... hai.. very hard.... :cry: ...

Thanks...

Added after 2 hours 5 minutes:

IanP said:
What I use as reference is a hard copy of "80C51-Based 8-bit Microcontrollers - Data Handbook" from Philips Semiconductors .. It is about 1400 pages ..
I'm not sure if you can download something like this from the net ..

Hi,

I already try to search for this data handbook but still get it. Inside the book have alot of sample is it?? Can you send it to me?? I hope this book can help me.... :) ...

Thank You
 

Re: 0.2m Sec

Help said:
Hi,

So, do you have any simple sample program for you own experience because now i like studying theory and no have practice... hai.. very hard.... :cry: ...

Thanks...

Added after 2 hours 5 minutes:

IanP said:
What I use as reference is a hard copy of "80C51-Based 8-bit Microcontrollers - Data Handbook" from Philips Semiconductors .. It is about 1400 pages ..
I'm not sure if you can download something like this from the net ..

Hi,

I already try to search for this data handbook but still get it. Inside the book have alot of sample is it?? Can you send it to me?? I hope this book can help me.... :) ...

Thank You

Straight from Philips :

**broken link removed**
**broken link removed**
**broken link removed**

or you can get the genuine Intel MCS(R) 51 Microcontroller Family User's Manual
from here:
http://www.intel.com/design/mcs51/manuals/272383.htm

If you have spare time you can take a look at the all MCS51 INTEL's documentation:
http://www.intel.com/design/mcs51/docs_mcs51.htm
 

Re: 0.2m Sec

MCU operates with cycles , each cycle equal to clock_freq/12(12 clock pulses for one cycle)
if u use a 12MHZ crystal then each cycle equal (1/12000000 )*12=1us

the timer increment its value at each cycle.

since the timer increment not decrement then u use the 2's complement of 200( -200 will be intepreted to be the 2's comlement of 200), so after 200 increment for every 200 cycle and each cycle equal 1us(12MHZ crystal)
then u get a delay of 200us or .2ms.

but remember to enable the dedicted interrupt and remember the to take care how the int handler wil work.
 

Re: 0.2m Sec

Hi silvio & wolfheart_2001,

Do you have any idea where can i get the information that can teach me how to write a C-code in 8051 application note??

Thanks...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top