component bldc_hall3 """3-wire BLDC motor driver using Hall sensors and trapezoidal commutation. The functionality of this component is now included in the generic "bldc" component. This component is likely to be removed in a future release"""; pin in bit hall1 "Hall sensor signal 1"; pin in bit hall2 "Hall sensor signal 2"; pin in bit hall3 "Hall sensor signal 3"; pin in float value "PWM master amplitude input"; pin in bit dir """Forwards / reverse selection. Negative PWM amplitudes will also reverse the motor and there will generally be a pattern that runs the motor in each direction too."""; pin out float A-value "Output amplitude for phase A"; pin out float B-value "Output amplitude for phase B"; pin out float C-value "Output amplitude for phase C"; param rw unsigned pattern=25 """Commutation pattern to use, from 0 to 47. Default is type 25. Every plausible combination is included. The table shows the excitation pattern along the top, and the pattern code on the left hand side. The table entries are the hall patterns in H1, H2, H3 order. Common patterns are: 0 (30 degree commutation) and 26, its reverse. 17 (120 degree). 18 (alternate 60 degree). 21 (300 degree, Bodine). 22 (240 degree). 25 (60 degree commutation). Note that a number of incorrect commutations will have non-zero net torque which might look as if they work, but don't really. If your motor lacks documentation it might be worth trying every pattern. .ie '\*[.T]'html' \\{\\ .HTML \\ \\ \\ \\
 Phases, Source - Sink \\
patB-AC-AC-BA-BA-CB-C \\
0000001011111110100 \\
1001000010110111101 \\
2000010011111101100 \\
3001011010110100101 \\
4010011001101100110 \\
5011010000100101111 \\
6010000001101111110 \\
7011001000100110111 \\
8000001101111110010 \\
9001000100110111011 \\
10000010110111101001 \\
11001011111110100000 \\
12010011111101100000 \\
13011010110100101001 \\
14010000100101111011 \\
15011001101100110010 \\
16000100101111011010 \\
17001101100110010011 \\
18000100110111011001 \\
19001101111110010000 \\
20010110111101001000 \\
21011111110100000001 \\
22010110100101001011 \\
23011111101100000010 \\
24100101111011010000 \\
25101100110010011001 \\
26100110111011001000 \\
27101111110010000001 \\
28110111101001000010 \\
29111110100000001011 \\
30110100101001011010 \\
31111101100000010011 \\
32100101001011010110 \\
33101100000010011111 \\
34100110010011001101 \\
35101111011010000100 \\
36110111011001000100 \\
37111110010000001101 \\
38110100000001011111 \\
39111101001000010110 \\
40100000001011111110 \\
41101001000010110111 \\
42100000010011111101 \\
43101001011010110100 \\
44110010011001101100 \\
45111011010000100101 \\
46110010000001101111 \\
47111011001000100110 \\
\\} .el \\{\\ .TS box tab(;); cb s s s s s s cb|cb cb cb cb cb cb c | c c c c c r. Phases, Source - Sink _ pat;B-A;C-A;C-B;A-B;A-C;B-C _ 0;000;001;011;111;110;100 1;001;000;010;110;111;101 2;000;010;011;111;101;100 3;001;011;010;110;100;101 4;010;011;001;101;100;110 5;011;010;000;100;101;111 6;010;000;001;101;111;110 7;011;001;000;100;110;111 8;000;001;101;111;110;010 9;001;000;100;110;111;011 10;000;010;110;111;101;001 11;001;011;111;110;100;000 12;010;011;111;101;100;000 13;011;010;110;100;101;001 14;010;000;100;101;111;011 15;011;001;101;100;110;010 16;000;100;101;111;011;010 17;001;101;100;110;010;011 18;000;100;110;111;011;001 19;001;101;111;110;010;000 20;010;110;111;101;001;000 21;011;111;110;100;000;001 22;010;110;100;101;001;011 23;011;111;101;100;000;010 24;100;101;111;011;010;000 25;101;100;110;010;011;001 26;100;110;111;011;001;000 27;101;111;110;010;000;001 28;110;111;101;001;000;010 29;111;110;100;000;001;011 30;110;100;101;001;011;010 31;111;101;100;000;010;011 32;100;101;001;011;010;110 33;101;100;000;010;011;111 34;100;110;010;011;001;101 35;101;111;011;010;000;100 36;110;111;011;001;000;100 37;111;110;010;000;001;101 38;110;100;000;001;011;111 39;111;101;001;000;010;110 40;100;000;001;011;111;110 41;101;001;000;010;110;111 42;100;000;010;011;111;101 43;101;001;011;010;110;100 44;110;010;011;001;101;100 45;111;011;010;000;100;101 46;110;010;000;001;101;111 47;111;011;001;000;100;110 .TE \\} """; description """ This component produces a 3-wire bipolar output. This suits upstream drivers that interpret a negative input as a low-side drive and positive as a high-side drive. This includes the Hostmot2 3pwmgen function, which is likely to be the most common application of this component. """; see_also """ bldc_hall6 6-wire unipolar driver for BLDC motors. """; license "GPL"; author "Andy Pugh"; function _ "Interpret Hall sensor patterns and set 3-phase amplitudes"; ;; /*dir H1 H2 H3 pattern 000 001 010 011 100 101 110 111 */ static unsigned int P[]={ 024, 014, 000, 012, 021, 000, 041, 042, 014, 024, 012, 000, 000, 021, 042, 041, 024, 000, 014, 012, 021, 041, 000, 042, 000, 024, 012, 014, 041, 021, 042, 000, 000, 012, 024, 014, 041, 042, 021, 000, 012, 000, 014, 024, 042, 041, 000, 021, 014, 012, 024, 000, 000, 042, 021, 041, 012, 014, 000, 024, 042, 000, 041, 021, 024, 014, 021, 000, 000, 012, 041, 042, 014, 024, 000, 021, 012, 000, 042, 041, 024, 021, 014, 000, 000, 041, 012, 042, 021, 024, 000, 014, 041, 000, 042, 012, 021, 000, 024, 014, 041, 042, 000, 012, 000, 021, 014, 024, 042, 041, 012, 000, 014, 000, 024, 021, 012, 042, 000, 041, 000, 014, 021, 024, 042, 012, 041, 000, 024, 000, 021, 041, 014, 012, 000, 042, 000, 024, 041, 021, 012, 014, 042, 000, 024, 021, 000, 041, 014, 000, 012, 042, 021, 024, 041, 000, 000, 014, 042, 012, 021, 041, 024, 000, 000, 042, 014, 012, 041, 021, 000, 024, 042, 000, 012, 014, 000, 041, 024, 021, 012, 042, 014, 000, 041, 000, 021, 024, 042, 012, 000, 014, 021, 000, 041, 042, 024, 014, 000, 012, 000, 021, 042, 041, 014, 024, 012, 000, 021, 041, 000, 042, 024, 000, 014, 012, 041, 021, 042, 000, 000, 024, 012, 014, 041, 042, 021, 000, 000, 012, 024, 014, 042, 041, 000, 021, 012, 000, 014, 024, 000, 042, 021, 041, 014, 012, 024, 000, 042, 000, 041, 021, 012, 014, 000, 024, 000, 012, 041, 042, 024, 014, 021, 000, 012, 000, 042, 041, 014, 024, 000, 021, 000, 041, 012, 042, 024, 021, 014, 000, 041, 000, 042, 012, 021, 024, 000, 014, 041, 042, 000, 012, 021, 000, 024, 014, 042, 041, 012, 000, 000, 021, 014, 024, 012, 042, 000, 041, 014, 000, 024, 021, 042, 012, 041, 000, 000, 014, 021, 024, 014, 012, 000, 042, 024, 000, 021, 041, 012, 014, 042, 000, 000, 024, 041, 021, 014, 000, 012, 042, 024, 021, 000, 041, 000, 014, 042, 012, 021, 024, 041, 000, 000, 042, 014, 012, 021, 041, 024, 000, 042, 000, 012, 014, 041, 021, 000, 024, 012, 042, 014, 000, 000, 041, 024, 021, 042, 012, 000, 014, 041, 000, 021, 024}; FUNCTION(_){ int i; double V; if (pattern > 47){ rtapi_print_msg(RTAPI_MSG_ERR, "Only step patterns 0-47 are allowed, you have requested pattern %i\n", pattern); pattern = 0; return; } i = (pattern << 3) + (hall1 << 2) + (hall2 << 1) + hall3; if (dir) V = -value; else V = value; if (P[i] & 040) A_value =V; else if (P[i] & 004) A_value = -V; else A_value = 0; if (P[i] & 020) B_value = V; else if (P[i] & 002) B_value = -V; else B_value = 0; if (P[i] & 010) C_value = V; else if (P[i] & 001) C_value = -V; else C_value = 0; }