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.

pulse width modulation

Status
Not open for further replies.

cai2

Member level 2
Member level 2
Joined
Nov 30, 2006
Messages
50
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,618
how can i implement pulse width modulation in an 89c4051/2051 mcu?...please help...
 

as u know there is no built in PWM generator in side the 4051 or 2051

u have to use both timer T0 T1 to generate pulse width modulation
 

If we use both timer also , how could i generate the PWM output. if we one timer also we can generate the PWM with constant Duty cycle. So Ashad can u explain me how we can generate the PWM with duty cycle can be varied from 0 to 100 % .
 

search google for "how to implement PWM using microcontroller timer" probably you will find what you are looking for

Mr.Cool
 

C code
Code:
void pwmTask(unsigned int pulse_width,unsigned int period)
{
unsigned int time_on = pulse_width;
unsigned int time_off = period - pulse_width;
	while(1)
	{
	pwm_output = 1;		//pwm_output = signal connected to FET
	sleep(time_on);
	pwm_output = 0;
	sleep(time_off);
	}
}
 

Prabakaran said:
If we use both timer also , how could i generate the PWM output. if we one timer also we can generate the PWM with constant Duty cycle. So Ashad can u explain me how we can generate the PWM with duty cycle can be varied from 0 to 100 % .

basically if u use only one timer then the duty cycle is fixed (called pulse rate mdultation)

in PWM the freq is fixed only duty cyle varies..... so use one timer for generate fixed freq and use another timer for generate only high pulse
 

hi,
the coding of asm

;---------------------- Memory Allocate -------------------------------------
;*****************************************************************
;* *
;* unlimited PWM Subroutines for the 8051 microcontroller *
;* to add more pwm signal. just add memory value and port map *
;*****************************************************************
;---------------------- memory map -----------------------------------------
PWM_swap equ 7fh
PWM_skn equ 7eh ;speed value of right motor
PWM_skr equ 7dh ;speed value of left motor
;---------------------- port map -------------------------------------------
pwmkr bit p0.0
pwmkn bit p0.1
;---------------------- Zero Page ----------------------------------------

org 0H ; Reset
ljmp Begin
; org 03H ; INT 0
; reti
org 0BH ; Timer 0
ljmp PWM_msac
; org 13H ; INT 1
; reti
; org 1BH ; Timer 1
; reti
; org 23H ; Port I/O Serial
; reti


;---------------------- Begin -----------------------------------------------


org 100H
begin: mov TMOD,#22h

mov IE,#10010010b
setb TR0
setb TR1
mov P0,#0h

clr pwmkr
clr pwmkr
start:
mov PWM_skr,#0ddh ;speed value of left motor
mov PWM_skn,#0ffh ;speed value of right motor


sjmp start

;---------------------- PWM Service --------------------------------

PWM_msac: mov PWM_swap,A
mov TH0,#0dch ;cc 60hz, dc 100hz xtall 11.059
djnz R7,Check
setb pwmkn
setb pwmkr
reti
Check: xch A,R7
cjne A,PWM_skn,Check1
clr pwmkn
Check1: cjne A,PWM_skr,PWM_Ret
clr pwmkr
PWM_Ret: xch A,R7
mov A,PWM_swap
reti


end
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top