Tuesday, November 22, 2011

WAP To generate frequencies of 2khz on pin P0.0 crystal frequency 12Mhz

calculations

2khz frequency means 2000 cycles / sec
2000 cycles     -    1 sec
1 cycle        -    ? secs
        -    1/2000
        =    .0005 secs
crystal frequency 12mhz
therefore used frequency 12/12 = 1 mhz
1000 cycles    -    1 sec
1 cycle        -    ? secs
        =    1/1000 secs
        =    1 usec

so each half cycle in 2khz will have a .00025 sec or 250 ms delay
so we need to create a 250ms delay using crystal frequency

DELAY SUBROUTINE

DELAY :

MOV R7, #DATA    ; 2 MACHINE CYCLE
DJNZ R7, $    ; 2 MACHINE CYCLE
RET        ; 1 MACHINE CYCLE

let x be our data
(2 + 2*x + 1)*1us = 500 us
2*x = 500 - 3
x = 497/2 = 249

DATA = 249 for 500 us but we needed for half its cycle that is 250 us
DATA = 125 for 250 us

SO PROGRAM

ORG 0000H    ;

BACK :
SETB P0.0    ;
ACALL DELAY    ;
CLR P0.0    ;
ACALL DELAY    ;
SJMP BACK    ;

DELAY :
MOV R7, #125    ;
DJNZ R7, $    ;
RET        ;


END        ;

No comments:

Post a Comment