bldc_hall3.comp
1 component bldc_hall3 2 """3-wire BLDC motor driver using Hall sensors and trapezoidal commutation. 3 The functionality of this component is now included in the generic "bldc" 4 component. This component is likely to be removed in a future release"""; 5 6 pin in bit hall1 "Hall sensor signal 1"; 7 pin in bit hall2 "Hall sensor signal 2"; 8 pin in bit hall3 "Hall sensor signal 3"; 9 pin in float value "PWM master amplitude input"; 10 pin in bit dir 11 """Forwards / reverse selection. Negative PWM amplitudes will also 12 reverse the motor and there will generally be a pattern that runs the motor in 13 each direction too."""; 14 15 pin out float A-value "Output amplitude for phase A"; 16 pin out float B-value "Output amplitude for phase B"; 17 pin out float C-value "Output amplitude for phase C"; 18 19 param rw unsigned pattern=25 20 """Commutation pattern to use, from 0 to 47. Default is type 25. 21 Every plausible combination is included. The table shows the excitation pattern 22 along the top, and the pattern code on the left hand side. The table entries 23 are the hall patterns in H1, H2, H3 order. 24 Common patterns are: 25 0 (30 degree commutation) and 26, its reverse. 26 17 (120 degree). 27 18 (alternate 60 degree). 28 21 (300 degree, Bodine). 29 22 (240 degree). 30 25 (60 degree commutation). 31 32 Note that a number of incorrect commutations will have non-zero net torque 33 which might look as if they work, but don't really. 34 35 If your motor lacks documentation it might be worth trying every pattern. 36 37 .ie '\*[.T]'html' \\{\\ 38 .HTML \\ 39 <STYLE> \\ 40 #pattern TD { text-align: center; padding-left: .5ex; padding-right: .5ex } \\ 41 #pattern TH { text-align: center; padding-left: .5ex; padding-right: .5ex } \\ 42 #pattern TD.W { text-align: right; } \\ 43 </STYLE> \\ 44 <TABLE ID="pattern" STYLE="border: 1px solid black; border-collapse: collapse"> \\ 45 <COL SPAN=7 STYLE="margin: .2ex"><COL SPAN=1 STYLE="border-left: 1px solid black"> \\ 46 <TR><TD> <TH COLSPAN=6 CLASS=W>Phases, Source - Sink \\ 47 <TR><TH CLASS=W>pat<TH CLASS=W>B-A<TH CLASS=W>C-A<TH CLASS=W>C-B<TH CLASS=W>A-B<TH CLASS=W>A-C<TH CLASS=W>B-C \\ 48 <TR><TH>0<TD>000<TD>001<TD>011<TD>111<TD>110<TD>100 \\ 49 <TR><TH>1<TD>001<TD>000<TD>010<TD>110<TD>111<TD>101 \\ 50 <TR><TH>2<TD>000<TD>010<TD>011<TD>111<TD>101<TD>100 \\ 51 <TR><TH>3<TD>001<TD>011<TD>010<TD>110<TD>100<TD>101 \\ 52 <TR><TH>4<TD>010<TD>011<TD>001<TD>101<TD>100<TD>110 \\ 53 <TR><TH>5<TD>011<TD>010<TD>000<TD>100<TD>101<TD>111 \\ 54 <TR><TH>6<TD>010<TD>000<TD>001<TD>101<TD>111<TD>110 \\ 55 <TR><TH>7<TD>011<TD>001<TD>000<TD>100<TD>110<TD>111 \\ 56 <TR><TH>8<TD>000<TD>001<TD>101<TD>111<TD>110<TD>010 \\ 57 <TR><TH>9<TD>001<TD>000<TD>100<TD>110<TD>111<TD>011 \\ 58 <TR><TH>10<TD>000<TD>010<TD>110<TD>111<TD>101<TD>001 \\ 59 <TR><TH>11<TD>001<TD>011<TD>111<TD>110<TD>100<TD>000 \\ 60 <TR><TH>12<TD>010<TD>011<TD>111<TD>101<TD>100<TD>000 \\ 61 <TR><TH>13<TD>011<TD>010<TD>110<TD>100<TD>101<TD>001 \\ 62 <TR><TH>14<TD>010<TD>000<TD>100<TD>101<TD>111<TD>011 \\ 63 <TR><TH>15<TD>011<TD>001<TD>101<TD>100<TD>110<TD>010 \\ 64 <TR><TH>16<TD>000<TD>100<TD>101<TD>111<TD>011<TD>010 \\ 65 <TR><TH>17<TD>001<TD>101<TD>100<TD>110<TD>010<TD>011 \\ 66 <TR><TH>18<TD>000<TD>100<TD>110<TD>111<TD>011<TD>001 \\ 67 <TR><TH>19<TD>001<TD>101<TD>111<TD>110<TD>010<TD>000 \\ 68 <TR><TH>20<TD>010<TD>110<TD>111<TD>101<TD>001<TD>000 \\ 69 <TR><TH>21<TD>011<TD>111<TD>110<TD>100<TD>000<TD>001 \\ 70 <TR><TH>22<TD>010<TD>110<TD>100<TD>101<TD>001<TD>011 \\ 71 <TR><TH>23<TD>011<TD>111<TD>101<TD>100<TD>000<TD>010 \\ 72 <TR><TH>24<TD>100<TD>101<TD>111<TD>011<TD>010<TD>000 \\ 73 <TR><TH>25<TD>101<TD>100<TD>110<TD>010<TD>011<TD>001 \\ 74 <TR><TH>26<TD>100<TD>110<TD>111<TD>011<TD>001<TD>000 \\ 75 <TR><TH>27<TD>101<TD>111<TD>110<TD>010<TD>000<TD>001 \\ 76 <TR><TH>28<TD>110<TD>111<TD>101<TD>001<TD>000<TD>010 \\ 77 <TR><TH>29<TD>111<TD>110<TD>100<TD>000<TD>001<TD>011 \\ 78 <TR><TH>30<TD>110<TD>100<TD>101<TD>001<TD>011<TD>010 \\ 79 <TR><TH>31<TD>111<TD>101<TD>100<TD>000<TD>010<TD>011 \\ 80 <TR><TH>32<TD>100<TD>101<TD>001<TD>011<TD>010<TD>110 \\ 81 <TR><TH>33<TD>101<TD>100<TD>000<TD>010<TD>011<TD>111 \\ 82 <TR><TH>34<TD>100<TD>110<TD>010<TD>011<TD>001<TD>101 \\ 83 <TR><TH>35<TD>101<TD>111<TD>011<TD>010<TD>000<TD>100 \\ 84 <TR><TH>36<TD>110<TD>111<TD>011<TD>001<TD>000<TD>100 \\ 85 <TR><TH>37<TD>111<TD>110<TD>010<TD>000<TD>001<TD>101 \\ 86 <TR><TH>38<TD>110<TD>100<TD>000<TD>001<TD>011<TD>111 \\ 87 <TR><TH>39<TD>111<TD>101<TD>001<TD>000<TD>010<TD>110 \\ 88 <TR><TH>40<TD>100<TD>000<TD>001<TD>011<TD>111<TD>110 \\ 89 <TR><TH>41<TD>101<TD>001<TD>000<TD>010<TD>110<TD>111 \\ 90 <TR><TH>42<TD>100<TD>000<TD>010<TD>011<TD>111<TD>101 \\ 91 <TR><TH>43<TD>101<TD>001<TD>011<TD>010<TD>110<TD>100 \\ 92 <TR><TH>44<TD>110<TD>010<TD>011<TD>001<TD>101<TD>100 \\ 93 <TR><TH>45<TD>111<TD>011<TD>010<TD>000<TD>100<TD>101 \\ 94 <TR><TH>46<TD>110<TD>010<TD>000<TD>001<TD>101<TD>111 \\ 95 <TR><TH>47<TD>111<TD>011<TD>001<TD>000<TD>100<TD>110 \\ 96 </TABLE> 97 \\} 98 .el \\{\\ 99 100 .TS 101 box tab(;); 102 cb s s s s s s 103 cb|cb cb cb cb cb cb 104 c | c c c c c r. 105 Phases, Source - Sink 106 _ 107 pat;B-A;C-A;C-B;A-B;A-C;B-C 108 _ 109 0;000;001;011;111;110;100 110 1;001;000;010;110;111;101 111 2;000;010;011;111;101;100 112 3;001;011;010;110;100;101 113 4;010;011;001;101;100;110 114 5;011;010;000;100;101;111 115 6;010;000;001;101;111;110 116 7;011;001;000;100;110;111 117 8;000;001;101;111;110;010 118 9;001;000;100;110;111;011 119 10;000;010;110;111;101;001 120 11;001;011;111;110;100;000 121 12;010;011;111;101;100;000 122 13;011;010;110;100;101;001 123 14;010;000;100;101;111;011 124 15;011;001;101;100;110;010 125 16;000;100;101;111;011;010 126 17;001;101;100;110;010;011 127 18;000;100;110;111;011;001 128 19;001;101;111;110;010;000 129 20;010;110;111;101;001;000 130 21;011;111;110;100;000;001 131 22;010;110;100;101;001;011 132 23;011;111;101;100;000;010 133 24;100;101;111;011;010;000 134 25;101;100;110;010;011;001 135 26;100;110;111;011;001;000 136 27;101;111;110;010;000;001 137 28;110;111;101;001;000;010 138 29;111;110;100;000;001;011 139 30;110;100;101;001;011;010 140 31;111;101;100;000;010;011 141 32;100;101;001;011;010;110 142 33;101;100;000;010;011;111 143 34;100;110;010;011;001;101 144 35;101;111;011;010;000;100 145 36;110;111;011;001;000;100 146 37;111;110;010;000;001;101 147 38;110;100;000;001;011;111 148 39;111;101;001;000;010;110 149 40;100;000;001;011;111;110 150 41;101;001;000;010;110;111 151 42;100;000;010;011;111;101 152 43;101;001;011;010;110;100 153 44;110;010;011;001;101;100 154 45;111;011;010;000;100;101 155 46;110;010;000;001;101;111 156 47;111;011;001;000;100;110 157 .TE 158 \\} 159 """; 160 161 description """ 162 This component produces a 3-wire bipolar output. This suits upstream drivers 163 that interpret a negative input as a low-side drive and positive as a high-side 164 drive. This includes the Hostmot2 3pwmgen function, which is likely to be the 165 most common application of this component. 166 """; 167 168 see_also """ 169 bldc_hall6 6-wire unipolar driver for BLDC motors. 170 """; 171 172 license "GPL"; 173 174 author "Andy Pugh"; 175 176 function _ "Interpret Hall sensor patterns and set 3-phase amplitudes"; 177 178 ;; 179 180 /*dir H1 H2 H3 pattern 181 000 001 010 011 100 101 110 111 */ 182 static unsigned int P[]={ 183 024, 014, 000, 012, 021, 000, 041, 042, 184 014, 024, 012, 000, 000, 021, 042, 041, 185 024, 000, 014, 012, 021, 041, 000, 042, 186 000, 024, 012, 014, 041, 021, 042, 000, 187 000, 012, 024, 014, 041, 042, 021, 000, 188 012, 000, 014, 024, 042, 041, 000, 021, 189 014, 012, 024, 000, 000, 042, 021, 041, 190 012, 014, 000, 024, 042, 000, 041, 021, 191 024, 014, 021, 000, 000, 012, 041, 042, 192 014, 024, 000, 021, 012, 000, 042, 041, 193 024, 021, 014, 000, 000, 041, 012, 042, 194 021, 024, 000, 014, 041, 000, 042, 012, 195 021, 000, 024, 014, 041, 042, 000, 012, 196 000, 021, 014, 024, 042, 041, 012, 000, 197 014, 000, 024, 021, 012, 042, 000, 041, 198 000, 014, 021, 024, 042, 012, 041, 000, 199 024, 000, 021, 041, 014, 012, 000, 042, 200 000, 024, 041, 021, 012, 014, 042, 000, 201 024, 021, 000, 041, 014, 000, 012, 042, 202 021, 024, 041, 000, 000, 014, 042, 012, 203 021, 041, 024, 000, 000, 042, 014, 012, 204 041, 021, 000, 024, 042, 000, 012, 014, 205 000, 041, 024, 021, 012, 042, 014, 000, 206 041, 000, 021, 024, 042, 012, 000, 014, 207 021, 000, 041, 042, 024, 014, 000, 012, 208 000, 021, 042, 041, 014, 024, 012, 000, 209 021, 041, 000, 042, 024, 000, 014, 012, 210 041, 021, 042, 000, 000, 024, 012, 014, 211 041, 042, 021, 000, 000, 012, 024, 014, 212 042, 041, 000, 021, 012, 000, 014, 024, 213 000, 042, 021, 041, 014, 012, 024, 000, 214 042, 000, 041, 021, 012, 014, 000, 024, 215 000, 012, 041, 042, 024, 014, 021, 000, 216 012, 000, 042, 041, 014, 024, 000, 021, 217 000, 041, 012, 042, 024, 021, 014, 000, 218 041, 000, 042, 012, 021, 024, 000, 014, 219 041, 042, 000, 012, 021, 000, 024, 014, 220 042, 041, 012, 000, 000, 021, 014, 024, 221 012, 042, 000, 041, 014, 000, 024, 021, 222 042, 012, 041, 000, 000, 014, 021, 024, 223 014, 012, 000, 042, 024, 000, 021, 041, 224 012, 014, 042, 000, 000, 024, 041, 021, 225 014, 000, 012, 042, 024, 021, 000, 041, 226 000, 014, 042, 012, 021, 024, 041, 000, 227 000, 042, 014, 012, 021, 041, 024, 000, 228 042, 000, 012, 014, 041, 021, 000, 024, 229 012, 042, 014, 000, 000, 041, 024, 021, 230 042, 012, 000, 014, 041, 000, 021, 024}; 231 232 FUNCTION(_){ 233 int i; 234 double V; 235 if (pattern > 47){ 236 rtapi_print_msg(RTAPI_MSG_ERR, 237 "Only step patterns 0-47 are allowed, you have requested pattern %i\n", 238 pattern); 239 pattern = 0; 240 return; 241 } 242 243 i = (pattern << 3) + (hall1 << 2) + (hall2 << 1) + hall3; 244 245 if (dir) V = -value; 246 else V = value; 247 248 if (P[i] & 040) A_value =V; 249 else if (P[i] & 004) A_value = -V; 250 else A_value = 0; 251 252 if (P[i] & 020) B_value = V; 253 else if (P[i] & 002) B_value = -V; 254 else B_value = 0; 255 256 if (P[i] & 010) C_value = V; 257 else if (P[i] & 001) C_value = -V; 258 else C_value = 0; 259 } 260