Professional Documents
Culture Documents
Lab Work
Lab #11
Objective
To perform DC motor speed (uni-directional) control in open-loop using PWM
Theory
Uni-directional speed control refers to the speed controlling in one direction only. It means that DC motor supply polarity needs to be fixed. This is simpler than the bi-directional control where we have the choice of moving the motor in both (clockwise and anti-clockwise) directions by changing its supply voltage polarity. The controller may or may not actually measure the speed of the motor. If it does, it is called a Feedback Speed Controller or Closed Loop Speed Controller, if not it is called an Open Loop Speed Controller. Feedback speed control is better, but more complicated, and may not be required in simple designs. PWM for Motor The speed of a DC motor is directly proportional to the supply voltage, so if we reduce the supply voltage from 12 Volts to 6 Volts, the motor will run at half the speed. How can this be achieved when the battery is fixed at 12 Volts? The speed controller works by varying the average voltage sent to the motor. It could do this by simply adjusting the voltage sent to the motor, but this is quite inefficient to do. A better way is to switch the motor's supply on and off very quickly. If the switching is fast enough, the motor doesn't notice it, it only notices the average effect.This on-off switching is performed by transistors that can turn very large currents on and off under the control of a low signal level. The time that it takes a motor to speed up and slow down under switching conditions is dependant on the inertia of the rotor (basically how heavy it is), and how much friction and load torque there is. The graph in the figure 11.1 shows the speed of a motor that is being turned on and off fairly slowly:
You can see that the average speed is around 150, although it varies quite a bit. If the supply voltage is switched fast enough, it wont have time to change speed much, and the speed will be quite steady. This is the principle of switch mode speed control. Thus the speed is set by PWM Pulse Width Modulation.
VCC VCC D1 1N4007 12V S1 MOTOR 2 Q1
PWM Signal
R1 1k
1 BD139 0
Group Members:
Lab Work
Lab #11
Flow Chart
START
Return
Return
END
Figure 11.3: Flow chart for PWM motor speed control program
Group Members:
Lab Work
Lab #11
Source Code
LOC OBJ LINE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 SOURCE ;Lab-11 ;This program reads dutycycle from keypad ;for example digit 5 = 50%,digit 6 = 60%.... ;and generates PWM for motor speed control ORG 0000H LJMP MAIN ORG 000BH LJMP ISR_T0 ORG 001BH LJMP ISR_T1 DUTY EQU 0x50 ;ram location that stores duty-cycle TLBYTE EQU 0x51 ;ram location that stores Timer-0 LowTHBYTE EQU 0x52 ;ram location that stores Timer-0
0000 0000 02001E 000B 000B 0200DD 001B 001B 0200E8 0050 0051 byte 0052 High-byte 001E 001E 758911
;Initialize Timer-0 (Variable timer, for on-time) MOV TLBYTE,#94H MOV THBYTE,#0FFH MOV TL0,TLBYTE MOV TH0,THBYTE ;Initialize Timer-1 (Fixed timer, for PWM-wave period) MOV TL1,#66H ; Low-byte of Timer-1 MOV TH1,#0FCH ; High-byte of Timer-1, [FC66H = 1 ms] MOV IE,#8AH SETB TR1 ; Enable Timer-0,1 interrupts ; Start timer-1
0038 0038 003A 003D 0040 0043 0045 0045 0048 004B
;Scan Keypad for duty-cycle input SCAN: CALL IN_HEX ;get duty-cycle from keypad CJNE A,#01H,D20 ;if not 10% then check for 20% MOV TLBYTE,#94H MOV THBYTE,#0FFH SJMP SCAN D20: CJNE A,#02H,D30 ;if not 20% then check for 30% MOV TLBYTE,#48H MOV THBYTE,#0FFH
Group Members:
Lab Work
SJMP SCAN D30: CJNE A,#03H,D40 ;if not 30% then check MOV TLBYTE,#0ECH MOV THBYTE,#0FEH SJMP SCAN D40: CJNE A,#04H,D50 ;if not 40% then check MOV TLBYTE,#90H MOV THBYTE,#0FEH SJMP SCAN D50: CJNE A,#05H,D60 ;if not 50% then check MOV TLBYTE,#34H MOV THBYTE,#0FEH SJMP SCAN D60: CJNE A,#06H,D70 ;if not 60% then check MOV TLBYTE,#0D8H MOV THBYTE,#0FDH SJMP SCAN D70: CJNE A,#07H,D80 ;if not 70% then check MOV TLBYTE,#7BH MOV THBYTE,#0FDH SJMP SCAN D80: CJNE A,#08H,D90 ;if not 80% then check MOV TLBYTE,#1FH MOV THBYTE,#0FDH SJMP SCAN D90: CJNE A,#09H,SCAN ;if not 90% then scan MOV TLBYTE,#0C3H MOV THBYTE,#0FCH SJMP SCAN
Lab #11
for 40%
for 50%
for 60%
for 70%
for 80%
for 90%
again for a
009D 009D 009F 009F 00A1 00A3 00A5 00A7 00A7 00A9 00A9
;IN_HEX - input hex code from keypad with debouncing ;for key press and key release (50 repeats for each) IN_HEX: MOV R3,#50 ;debounce count BACK: CALL GET_KEY ;key pressed? JNC IN_HEX ;no: check again DJNZ R3,BACK ;yes: repeat 50 times PUSH ACC ;save hex code BACK2: MOV R3,#50 ;wait for key release BACK3: CALL GET_KEY ;key pressed?
Group Members:
Lab Work
JC BACK2 DJNZ R3,BACK3 POP ACC RET ;yes: keep checking ;no: repeat 50 times ;recover hex code ;return
Lab #11
;GET_KEY - get keypad status ; - returns C = 0 if no key is pressed ; - returns C = 1 and hex code in GET_KEY: MOV A,#0FEH ;start with column 0 by grounding it MOV R6,#4 ;use R6 as column counter TEST: MOV P1,A ;activate (ground) current column MOV R7,A ;save ACC (accumulator) MOV A,P1 ;read back port ANL A,#0F0H ;isolate rows by masking columns CJNE A,#0F0H,KEY_HIT ;any row active? MOV A,R7 ;no: move to RL A ;ground next column DJNZ R6,TEST CLR C ;no key pressed SJMP EXIT ;return with C = 0 KEY_HIT: MOV R7,A ;save in R7 MOV A,#4 ;prepare to calculate column CLR C ;clear carry flag SUBB A,R6 ;column number = 4 - R6 MOV R6,A ;save result in R6 MOV A,R7 ;restore rows scan result SWAP A ;put this in low nibble MOV R5,#4 ;use R5 as counter AGAIN: RRC A ;rotate-right in carry JNC DONE ;done when C = 0 INC R6 ;add 4 INC R6 ;until the row is detected INC R6 ;R6 finally INC R6 ;holds the hexcode of pressed key DJNZ R5,AGAIN ;repeat until all rows checked DONE: SETB C ;C = 1 (key press confirmed!) MOV A,R6 ;save key hex code in A EXIT: RET
ISR_T0: CLR TR0 CLR P3.0 ;pulse low ;Reload timer for next interrupt MOV TL0,TLBYTE
Group Members:
Lab Work
MOV TH0,THBYTE RETI
Lab #11
ISR_T1: CLR TR1 SETB P3.0 ;pulse high ;Reload timer for next interrupt MOV TL1,#66H MOV TH1,#0FCH SETB TR0 ;start timer-0 again SETB TR1 ;start timer-1 again RETI ;return from interrupt
END
;END of program
Code 11.1: ASM listing for PWM motor speed control program
Group Members: