Continue to Site

# generation of square wave

Status
Not open for further replies.

#### soh m

##### Newbie level 6
hey i have a problem regarding generation of square wave of 50 hz on P2.3 using intel 80C51BH device and the target ESA51E.... anyone can help me how to write this program is assembly language????
p.s-- how can i check that the square wave is generated without using CRO???

Dear try to write a liitle programm
Then ask us that this is the problem,
Try it you can everything.

i have written this.....
MOV TMOD,#10H ;timer 1,mode1
AGAIN: MOV TL1,#00H ;low byte of timer
MOV TH1,#0DCH ;high byte of timer
SETB TR1 ;start timer1
BACK: JNB TF1,BACK
CLR TR1 ;stop timer1
CPL P2.3 ;P2.3 to get high,low
CLR TF1 ;stop timer flag

MCU crystal frequency?

Checking the output without CRO:
Duty cycle: By a DC voltmeter, the reading should be 1/2 V_high.
Frequency: By a counter to divide it by N (if 8-bit counter, N=256), and LED is added at the output (with a current limiting resistor in series)

If I am not wrong your crystal frequency is 12 MHz
This means the unit of the instruction cycle time is 12 / 12e6 = 1us (I assumed 1 cycle = 12 clocks)
As you know, TH1 and TL1 should be loaded (re-loaded) with the value 65536 - x
x (in sec) = 1/50Hz/2 (since it is half period) = 0.01 sec
x (in cu, cycle unit) = x (in sec) / cycle unit = 0.01/1e-6 = 10,000 cu
But...
But since the TH1/TL1 reloading must be preceded and followed by CLR TR1 and SETB TR1 respectively, 10,000 must be decreased a bit.
The reloading takes 4 cu and SETB TR1 takes 1 cu (CLR TR1 is not counted since the counter will stop after its execution).
We may call 4+1 = 5 cu as offset_t.
So x (final) = x (original) - offset_t = 10000 - 5 = 9995 cu
Therefore TH1 and TL1 should be loaded with:
TH1 = high (65536 - x) = high (65536 - 9995) = high (55541) = 0D8h
TL1 = low (65536 - x) = high (65536 - 9995) = high (55541) = 0F5h

see comment below.

======================================
======================================

MOV TMOD,#10H ;timer 1,mode1
CLR TR1 ;stop timer1

AGAIN:
MOV TL1,#0F9H ;low byte of timer , [2 cu]
MOV TH1,#0D8H ;high byte of timer , [2 cu]
SETB TR1 ;start timer1 , [1 cu]

BACK:
JNB TF1,BACK

CLR TR1 ;stop timer1 , [not in the offset_t because the counter will stop after it]
CPL P2.3 ;P2.3 to get high,low , [1 cu]
CLR TF1 ;clear timer flag , [1 cu]
SJMP AGAIN ;reload timer1 , [2 cu]

======================================
======================================

I think the offset_t should be recalculated... since I usually use the timer interrupt unlike here.
For the above code it should be 9.

TH1 = 0D8h
TL1 = 0F9h

Note: The entry delay time (before looping) is obviously not accurate.

Kerim

Edited:
MOV TL1,#F9H ;low byte of timer , [2 cu]
to
MOV TL1,#0F9H ;low byte of timer , [2 cu]

Last edited:
soh m

### soh m

Points: 2
MOV TMOD,#10H ;timer 1,mode1
AGAIN: MOV TL1,#00H ;low byte of timer
MOV TH1,#0DCH ;high byte of timer
SETB TR1 ;start timer1
%here(1)
BACK: JNB TF1,BACK
CLR TR1 ;stop timer1
CPL P2.3 ;P2.3 to get high,low %whre you have started timer again from here, copy this line to here(1)
CLR TF1 ;stop timer flag

---------- Post added at 07:53 ---------- Previous post was at 07:52 ----------

I wrote copy it should be cut.

kamranravian

Points: 2
Does it worked ?

kamranravian

### kamranravian

Points: 2
sorryyy... i would try it tomorrow... dnt have the software and kit right now....

but how can i check whether square wave is generated or not in the REGISTER and DISASSEMBLY windows of software WIN51E for ESA51E trainer only???!!!

First, I just read the manual of ESA51E.
Its crystal seems to be 11.0592 MHz and not 12 MHz as I guessed.
Therefore 'x' on my post #4 needs to be recalculated.

Second, I don't have any idea on WIN51E and searching didn't give any reference for it, sorry.

cu (in sec) = 12 / 11.0592e+6 = 1 / 921600
x (in cu) = 0.01 / (1 / 921600) = 0.01*921600 = 9216 cu
x (final) = x (original) - offset_t = 9216 - 9 = 9207 cu

Therefore TH1 and TL1 should be loaded with (for 50Hz):
TH1 = high (65536 - x) = high (65536 - 9207) = high (56329) = 0DCH
TL1 = low (65536 - x) = high (65536 - 9207) = high (56329) = 009H

Last edited:

Status
Not open for further replies.