Tutorial
Microcontroller 8051 |
||||||
![]() |
||||||
DC Motor Speed Regulation with A PWM Feed Back System Basic PWM 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. 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
|
Lesson 1: Lesson 2: |
|||||