P. 1


|Views: 0|Likes:
Published by Ammar Naveed Bajwa

More info:

Published by: Ammar Naveed Bajwa on Jun 04, 2013
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less





Embedded Systems – IE403

Lab Work

Lab #11

To perform DC motor speed (uni-directional) control in open-loop using PWM

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:

Figure 11.1: Motor speed response for PWM Voltage

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 won’t 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

Figure 11.2: Power transistor to drive motor

Group Members:

Ali Asad (1936)


Safdar Abbasi (1926)

Pulse High Initialize Timer-1(interrupt) for fixed PWM period Return Return Call Keypad routines(lab10) to get duty-cycle Change Timer-0 On-time as per duty-cycle END Figure 11.Embedded Systems – IE403 Lab Work Lab #11 Flow Chart START Interrupt Routine Timer-0 Interrupt Routine Timer-1 Initialize Time-0(interrupt) for variable on-time On-time is over. Pulse Low Total period is over.3: Flow chart for PWM motor speed control program Group Members: Ali Asad (1936) Safdar Abbasi (1926) .

Initialize Timer-1 (Fixed timer.if not 10% then check for 20% MOV TLBYTE.#66H .get duty-cycle from keypad CJNE A.ram location that stores duty-cycle TLBYTE EQU 0x51 .ram location that stores Timer-0 0000 0000 02001E 000B 000B 0200DD 001B 001B 0200E8 0050 0051 byte 0052 High-byte 001E 001E 758911 MAIN: MOV TMOD.if not 20% then check for 30% MOV TLBYTE.Initialize Timer-0 (Variable timer.. .THBYTE .for example digit 5 = 50%.#0FFH Group Members: Ali Asad (1936) Safdar Abbasi (1926) .#01H. Low-byte of Timer-1 MOV TH1.TLBYTE MOV TH0. High-byte of Timer-1.#94H MOV THBYTE.ram location that stores Timer-0 LowTHBYTE EQU 0x52 .1 interrupts .D20 .#48H MOV THBYTE. for on-time) MOV TLBYTE.D30 .Embedded Systems – IE403 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 .#8AH SETB TR1 .This program reads dutycycle from keypad .Lab-11 .and generates PWM for motor speed control ORG 0000H LJMP MAIN ORG 000BH LJMP ISR_T0 ORG 001BH LJMP ISR_T1 DUTY EQU 0x50 .#11H . for PWM-wave period) MOV TL1.Timer-0.digit 6 = 60%.1 both in mode-1 0021 0024 0027 002A 755194 7552FF 85518A 85528C .#0FCH . [FC66H = 1 ms] MOV IE. Enable Timer-0. Start timer-1 002D 758B66 0030 758DFC 0033 75A88A 0036 D28E 0038 0038 003A 003D 0040 0043 0045 0045 0048 004B 119D B40108 755194 7552FF 80F3 B40208 755148 7552FF .#02H..#94H MOV THBYTE.#0FFH MOV TL0.Scan Keypad for duty-cycle input SCAN: CALL IN_HEX .#0FFH SJMP SCAN D20: CJNE A..

if not 50% then check MOV TLBYTE.D90 .input hex code from keypad with debouncing .if not 70% then check MOV TLBYTE.for key press and key release (50 repeats for each) IN_HEX: MOV R3.if not 90% then scan MOV TLBYTE.#0FDH SJMP SCAN D90: CJNE A.IN_HEX .#0FEH SJMP SCAN D50: CJNE A.#09H.BACK .#08H.debounce count BACK: CALL GET_KEY .wait for key release BACK3: CALL GET_KEY .SCAN .key pressed? Group Members: Ali Asad (1936) Safdar Abbasi (1926) .#7BH MOV THBYTE.#1FH MOV THBYTE.if not 80% then check MOV TLBYTE.#06H.D80 .D70 .D60 .#50 .#90H MOV THBYTE.#0C3H MOV THBYTE.Embedded Systems – IE403 004E 80E8 0050 0050 B40308 0053 7551EC 0056 7552FE 0059 80DD 005B 005B B40408 005E 755190 0061 7552FE 0064 80D2 0066 0066 B40508 0069 755134 006C 7552FE 006F 80C7 0071 0071 B40608 0074 7551D8 0077 7552FD 007A 80BC 007C 007C B40708 007F 75517B 0082 7552FD 0085 80B1 0087 0087 B40808 008A 75511F 008D 7552FD 0090 80A6 0092 0092 B409A3 valid duty-cycle 0095 7551C3 0098 7552FC 009B 809B 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 Lab Work SJMP SCAN D30: CJNE A.save hex code BACK2: MOV R3.if not 40% then check MOV TLBYTE.#0FEH SJMP SCAN D60: CJNE A.repeat scanning until interrupted 009D 009D 009F 009F 00A1 00A3 00A5 00A7 00A7 00A9 00A9 7B32 11B2 50FA DBFA C0E0 7B32 11B2 .#34H MOV THBYTE.#07H.if not 60% then check MOV TLBYTE.#05H.#04H.#0FEH SJMP SCAN D40: CJNE A.D40 .yes: repeat 50 times PUSH ACC .#0ECH MOV THBYTE.#0D8H MOV THBYTE.#0FDH SJMP SCAN D70: CJNE A.#50 .#03H.D50 .key pressed? JNC IN_HEX .no: check again DJNZ R3.#0FCH SJMP SCAN Lab #11 for 40% for 50% for 60% for 70% for 80% for 90% again for a .if not 30% then check MOV TLBYTE.#0FDH SJMP SCAN D80: CJNE A.

done when C = 0 INC R6 .A .restore rows scan result SWAP A .ground next column DJNZ R6.return with C = 0 KEY_HIT: MOV R7.KEY_HIT .R7 .rotate-right in carry JNC DONE .#4 .R6 MOV R6.use R6 as column counter TEST: MOV P1.return Lab #11 .Reload timer for next interrupt MOV TL0.#0FEH .read back port ANL A.activate (ground) current column MOV R7.A .GET_KEY .start with column 0 by grounding it MOV R6.save result in R6 MOV A.holds the hexcode of pressed key DJNZ R5.P1 .use R5 as counter AGAIN: RRC A .0 .#0F0H.#4 .add 4 INC R6 .R6 .put this in low nibble MOV R5.#0F0H .isolate rows by masking columns CJNE A.any row active? MOV A.returns C = 0 if no key is pressed .A .R6 .TLBYTE Group Members: Ali Asad (1936) Safdar Abbasi (1926) .R6 finally INC R6 .column number = 4 .no: move to RL A .save in R7 MOV A.R7 .returns C = 1 and hex code in GET_KEY: MOV A.no: repeat 50 times .Embedded Systems – IE403 00AB 00AD 00AF 00B1 98 99 100 101 102 103 104 105 Accumulator if pressed 00B2 106 00B2 74FE 107 00B4 7E04 108 00B6 109 00B6 F590 110 00B8 FF 111 00B9 E590 112 00BB 54F0 113 00BD B4F007 114 00C0 EF 115 00C1 23 116 00C2 DEF2 117 00C4 C3 118 00C5 8015 119 00C7 120 00C7 FF 121 00C8 7404 122 00CA C3 123 00CB 9E 124 00CC FE 125 00CD EF 126 00CE C4 127 00CF 7D04 128 00D1 129 00D1 13 130 00D2 5006 131 00D4 0E 132 00D5 0E 133 00D6 0E 134 00D7 0E 135 00D8 DDF7 136 00DA 137 00DA D3 138 00DB EE 139 00DC 140 00DC 22 141 142 143 00DD 144 00DD C28C 145 00DF C2B0 146 147 00E1 85518A 148 40FA DBFA D0E0 22 Lab Work JC BACK2 DJNZ R3.repeat until all rows checked DONE: SETB C .save ACC (accumulator) MOV A.C = 1 (key press confirmed!) MOV A.prepare to calculate column CLR C .A .no key pressed SJMP EXIT . .pulse low .clear carry flag SUBB A.AGAIN .#4 .save key hex code in A EXIT: RET ISR_T0: CLR TR0 CLR P3.yes: keep checking .BACK3 POP ACC RET .get keypad status .TEST CLR C .until the row is detected INC R6 .recover hex code . .

1: ASM listing for PWM motor speed control program Group Members: Ali Asad (1936) Safdar Abbasi (1926) .THBYTE RETI Lab #11 .Embedded Systems – IE403 00E4 85528C 00E7 32 00E8 00E8 C28E 00EA D2B0 00EC 00EF 00F2 00F4 00F6 758B66 758DFC D28C D28E 32 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 Lab Work MOV TH0.END of program Code 11.start timer-1 again RETI .return from interrupt END .0 .return from interrupt ISR_T1: CLR TR1 SETB P3.Reload timer for next interrupt MOV TL1.start timer-0 again SETB TR1 .#66H MOV TH1.#0FCH SETB TR0 .pulse high .

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->