Tutorial Microcontroller 8051
 
 
 
 
 
   

BACK

DC Motor Speed Regulation with A PWM Feed Back System

Basic PWM
One of the easiest ways of generating an analog voltage from a digital value is by pulse-width modulation ( PWM ). I PWM a high frequency square wave is generated as a digital output. For example, a port bit continuously swiched on and off at a reltive high frequency. The signal is fed to a low pass filter. The voltage at the otuput of filter is equal to ther Roo Mean Squeare ( RMS ) of the squeare wave signal. The RMS of the square wave signal may then be varied by changing the duty cycle of the signal. A cycle is initiated by a low to high transition of the signal and terminates at the next such transition. During one cycle if the time the signal stays high is equal to the time the signal stays low, then the duty cycle is said to be 50 percent.

Figure 1. Duty Cycle 30 %

The following circuit shows a DAC constructed with PWM. The Program controls the speed of a DC motor by pulse widht modulation ( PWM ). Bit P3.0 Drives a switching transistor as shown in the circuit diagram. Motor is swiched on for a period of time, and then off. The fraction of time the motor is on is call the duty cycle.

Microcontroller Motor Speed Control

Figure 2. Pulse widht modulation to Control Motor Speed

This program uses a byte to store the time the motor is on, that is the number of cycles out of 256 cycles while the motor is on. a value of 10 means that the motor is on 10 cycles and off 246 cycles.The duty cycle value is stored in the internal register labeled dCycle. The complement of the duty cycle is similarly stored in register labeled dCycleC. ( Download File : motor.zip )

dCycle   equ 30h
dCycleC  equ 31h
count    equ 32h
Analog0  equ 33h
Analog1  equ 34h
PWM      bit P3.0
Channel  bit P3.1
PortADC  equ P0
DCLB     equ 000h
DCUB     equ 0F0h
MotorCondition bit 20h
;
         org 0h
         ljmp start
         org 0bh
         ljmp Timer_Interrupt0
start:   call Init_Interrupt_Timer0
         clr PWM ; Turn off motor
;==================
; Main Routine
;==================
Forever: call ADC
         call Update
         sjmp Forever
;
;======================
;Subrutine Timer Interruption
;======================
Timer_Interrupt0:
         JB MotorCondition,MotoroFF
         Setb PWM
         Mov TH0,dCycle
         Setb MotorCondition
         reti 
;
Motoroff:clr PWM
         mov TH0,dcycleC
         clr MotorCondition 
         reti 
;
;=========================
;Subrutine Initialize Timer Interrupt
;timer 0 as counter 8 bit mode 2
;========================
Init_interrupt_Timer0:
         mov TH0,#dCycle
         Mov TMOD,#00000010b ;
         setb ET0 ; Enable Timer 0 Interrupt
         Setb EA ; Master Interrupt Enable 
         setb TR0 ; start rock and roll timer 0
         Setb MotorCondition
         mov count,#50
         mov dCycle,#0
         mov dCycleC,#0FFh
         ret
; ;======================== ;Subrutine Update - Update duty cycle ;========================= Update: djnz count,upDone mov A,analog1; reference voltage mov b,analog0; tachometer voltage clr c subb a,b jnz update1 ret Update1: jc decrease call higherDC ret Decrease: call lowerDC UpDone: ret ; ;==================== ;Subrutine lowerDC ;==================== LowerDC: mov a,dCycle cjne a,#DCLB,DecDC ret DecDC: dec dCycle inc dCycleC ret ; ;=================== ;Subrutine HigherDC ;=================== HigherDC: mov a,dCycle cjne a,#DCUB,IncDC ret IncDC: Inc dCycle dec dCycleC ret ; ;============= ;Subrutine ADC ;============= ADC: Clr channel ; Pick channel X0 from multiplexer 4051 mov Analog0,PortADC Setb channel ;Pick channel X1 from multiplexer 4051 mov Analog1,PortADC ret ; end
Best Link

 


 

Lesson 1:
T o o l
1.1. Programmer
1.2.
Edsim 51
1.3. MIDE-51
1.4. ATMEL ISP

Lesson 2:
Input Output
2.1.LED
2.2.Swicht
2.3.7 Segmen
2.4.LCD Character
2.5.ADC
2.6.DAC
2.7.Motor Stepper
2.8.Keypad

Lesson 3:

Timer Counter

3.1.Basic
3.2.Mode 0
3.3.Mode 1
3.4.Mode 2
3.5.Mode 3

Lesson 4:

Serial Comm.

4.1.Basic
4.2.LED
4.3.Rotate LED
4.2 ADC
4.3.LCD

Lesson 5:
Interuption

5.1.Basic
5.2.Timer
5.2.External