Saturday, April 30, 2016

8051 program – pwm

Pulse width modulation is basically a square wave with a varying high and low time.
On-Time (Ton): Duration of time signal is high
Off-Time (Toff): Duration of time signal is low
Period (Ttotal): It is represented as the sum of on-time and off-time of PWM signal
Duty cycle: It is represented as percentage of time signal remains on during the period of the PWM signal. Duty cycle is calculated as on-time to the period of time.
D = Ton / Ttotal
; pwm generation
; standard 8051, 12MHz XTAL
; 1KHz square wave with 50% duty cycle on P1.0
; Timer 0, 16-bit mode
ORG 0H
MOV P1,#00000000B
MOV TMOD,#00000001B
PWM:
SETB P1.0
ACALL DELAY
CLR P1.0
ACALL DELAY
SJMP PWM
DELAY: ; 500us
MOV TH0,#0FEH
MOV TL0,#00CH
SETB TR0
HERE:
JNB TF0,HERE
CLR TR0
CLR TF0
SETB P1.0
RET
END

; pwm generation
; standard 8051, 12MHz XTAL
; 1KHz square wave with 10% duty cycle on P1.0
; Timer 0, 16-bit mode
ORG 0H
MOV P1,#00000000B
MOV TMOD,#00000001B
PWM:
SETB P1.0
MOV R0, #0FFH
MOV R1, #9CH
ACALL DELAY ; 100us
CLR P1.0
MOV R0, #0FCH
MOV R1, #7CH
ACALL DELAY ; 900us
SJMP PWM
DELAY:
MOV TH0,R0
MOV TL0,R1
SETB TR0
HERE:
JNB TF0,HERE
CLR TR0
CLR TF0
SETB P1.0
RET
END

; pwm generation
; standard 8051, 12MHz XTAL
; 1KHz square wave with 70% duty cycle on P1.0
; Timer 0, 16-bit mode
ORG 0H
MOV P1,#00000000B
MOV TMOD,#00000001B
PWM:
SETB P1.0
MOV R0, #0FDH
MOV R1, #44H
ACALL DELAY ; 700us
CLR P1.0
MOV R0, #0FEH
MOV R1, #0D4H
ACALL DELAY ; 300us
SJMP PWM
DELAY:
MOV TH0,R0
MOV TL0,R1
SETB TR0
HERE:
JNB TF0,HERE
CLR TR0
CLR TF0
SETB P1.0
RET
END



Related topics:
8051 Program - 1khz square wave   |   8051 Program - 2khz square wave   |   8051 Program - 10khz square wave   |   8051 Program - sine wave   |   8051 Program - triangular wave   |   8051 Program - sawtooth wave   |   8051 Program - stair wave   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment