Test
FermeStepper.cpp@0:5ec996c00568, 2021-01-11 (annotated)
- Committer:
- fermedicius
- Date:
- Mon Jan 11 10:56:36 2021 +0000
- Revision:
- 0:5ec996c00568
Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fermedicius | 0:5ec996c00568 | 1 | #include "FermeStepper.h" |
fermedicius | 0:5ec996c00568 | 2 | |
fermedicius | 0:5ec996c00568 | 3 | #include "mbed.h" |
fermedicius | 0:5ec996c00568 | 4 | |
fermedicius | 0:5ec996c00568 | 5 | int fermemotorSpeed; // Stepper speed |
fermedicius | 0:5ec996c00568 | 6 | |
fermedicius | 0:5ec996c00568 | 7 | fermeMotor::fermeMotor(PinName A0, PinName A1, PinName A2, PinName A3, PinName B0, PinName B1, PinName B2, PinName B3) : _A0(A0), _A1(A1), _A2(A2), _A3(A3), _B0(B0), _B1(B1), _B2(B2), _B3(B3) { // Defenition of motor pins |
fermedicius | 0:5ec996c00568 | 8 | _A0=0; // recepticle conveyor Pin 1 |
fermedicius | 0:5ec996c00568 | 9 | _A1=0; // recepticle conveyor Pin 2 |
fermedicius | 0:5ec996c00568 | 10 | _A2=0; // recepticle conveyor Pin 3 |
fermedicius | 0:5ec996c00568 | 11 | _A3=0; // recepticle conveyor Pin 4 |
fermedicius | 0:5ec996c00568 | 12 | _B0=0; // microtrack conveyor Pin 1 |
fermedicius | 0:5ec996c00568 | 13 | _B1=0; // microtrack conveyor Pin 2 |
fermedicius | 0:5ec996c00568 | 14 | _B2=0; // microtrack conveyor Pin 3 |
fermedicius | 0:5ec996c00568 | 15 | _B3=0; // microtrack conveyor Pin 4 |
fermedicius | 0:5ec996c00568 | 16 | } |
fermedicius | 0:5ec996c00568 | 17 | |
fermedicius | 0:5ec996c00568 | 18 | void fermeMotor::anticlockwise(int flag1, int flag2, int motorspeed) // flag1 for recepticle conveyor, flag2 for microtrack conveyor |
fermedicius | 0:5ec996c00568 | 19 | { |
fermedicius | 0:5ec996c00568 | 20 | for(int i = 0; i<8; i++) |
fermedicius | 0:5ec996c00568 | 21 | { |
fermedicius | 0:5ec996c00568 | 22 | if(flag1 == 1) |
fermedicius | 0:5ec996c00568 | 23 | { |
fermedicius | 0:5ec996c00568 | 24 | switch(i) |
fermedicius | 0:5ec996c00568 | 25 | { |
fermedicius | 0:5ec996c00568 | 26 | case 0: |
fermedicius | 0:5ec996c00568 | 27 | _A0=0; |
fermedicius | 0:5ec996c00568 | 28 | _A1=0; |
fermedicius | 0:5ec996c00568 | 29 | _A2=1; |
fermedicius | 0:5ec996c00568 | 30 | _A3=0; |
fermedicius | 0:5ec996c00568 | 31 | break; |
fermedicius | 0:5ec996c00568 | 32 | |
fermedicius | 0:5ec996c00568 | 33 | case 1: |
fermedicius | 0:5ec996c00568 | 34 | _A0=0; |
fermedicius | 0:5ec996c00568 | 35 | _A1=0; |
fermedicius | 0:5ec996c00568 | 36 | _A2=0; |
fermedicius | 0:5ec996c00568 | 37 | _A3=0; |
fermedicius | 0:5ec996c00568 | 38 | break; |
fermedicius | 0:5ec996c00568 | 39 | |
fermedicius | 0:5ec996c00568 | 40 | case 2: |
fermedicius | 0:5ec996c00568 | 41 | _A0=0; |
fermedicius | 0:5ec996c00568 | 42 | _A1=0; |
fermedicius | 0:5ec996c00568 | 43 | _A2=0; |
fermedicius | 0:5ec996c00568 | 44 | _A3=1; |
fermedicius | 0:5ec996c00568 | 45 | break; |
fermedicius | 0:5ec996c00568 | 46 | |
fermedicius | 0:5ec996c00568 | 47 | case 3: |
fermedicius | 0:5ec996c00568 | 48 | _A0=0; |
fermedicius | 0:5ec996c00568 | 49 | _A1=1; |
fermedicius | 0:5ec996c00568 | 50 | _A2=0; |
fermedicius | 0:5ec996c00568 | 51 | _A3=1; |
fermedicius | 0:5ec996c00568 | 52 | break; |
fermedicius | 0:5ec996c00568 | 53 | |
fermedicius | 0:5ec996c00568 | 54 | case 4: |
fermedicius | 0:5ec996c00568 | 55 | _A0=0; |
fermedicius | 0:5ec996c00568 | 56 | _A1=1; |
fermedicius | 0:5ec996c00568 | 57 | _A2=1; |
fermedicius | 0:5ec996c00568 | 58 | _A3=1; |
fermedicius | 0:5ec996c00568 | 59 | break; |
fermedicius | 0:5ec996c00568 | 60 | |
fermedicius | 0:5ec996c00568 | 61 | case 5: |
fermedicius | 0:5ec996c00568 | 62 | _A0=1; |
fermedicius | 0:5ec996c00568 | 63 | _A1=1; |
fermedicius | 0:5ec996c00568 | 64 | _A2=1; |
fermedicius | 0:5ec996c00568 | 65 | _A3=1; |
fermedicius | 0:5ec996c00568 | 66 | break; |
fermedicius | 0:5ec996c00568 | 67 | |
fermedicius | 0:5ec996c00568 | 68 | case 6: |
fermedicius | 0:5ec996c00568 | 69 | _A0=1; |
fermedicius | 0:5ec996c00568 | 70 | _A1=0; |
fermedicius | 0:5ec996c00568 | 71 | _A2=1; |
fermedicius | 0:5ec996c00568 | 72 | _A3=1; |
fermedicius | 0:5ec996c00568 | 73 | break; |
fermedicius | 0:5ec996c00568 | 74 | |
fermedicius | 0:5ec996c00568 | 75 | case 7: |
fermedicius | 0:5ec996c00568 | 76 | _A0=1; |
fermedicius | 0:5ec996c00568 | 77 | _A1=0; |
fermedicius | 0:5ec996c00568 | 78 | _A2=1; |
fermedicius | 0:5ec996c00568 | 79 | _A3=0; |
fermedicius | 0:5ec996c00568 | 80 | break; |
fermedicius | 0:5ec996c00568 | 81 | } |
fermedicius | 0:5ec996c00568 | 82 | wait_us(motorspeed); // wait time defines the speed |
fermedicius | 0:5ec996c00568 | 83 | } |
fermedicius | 0:5ec996c00568 | 84 | |
fermedicius | 0:5ec996c00568 | 85 | else if(flag1 == 0) |
fermedicius | 0:5ec996c00568 | 86 | { |
fermedicius | 0:5ec996c00568 | 87 | switch(i) |
fermedicius | 0:5ec996c00568 | 88 | { |
fermedicius | 0:5ec996c00568 | 89 | case 0: |
fermedicius | 0:5ec996c00568 | 90 | _A0=0; |
fermedicius | 0:5ec996c00568 | 91 | _A1=0; |
fermedicius | 0:5ec996c00568 | 92 | _A2=0; |
fermedicius | 0:5ec996c00568 | 93 | _A3=0; |
fermedicius | 0:5ec996c00568 | 94 | break; |
fermedicius | 0:5ec996c00568 | 95 | |
fermedicius | 0:5ec996c00568 | 96 | case 1: |
fermedicius | 0:5ec996c00568 | 97 | _A0=0; |
fermedicius | 0:5ec996c00568 | 98 | _A1=0; |
fermedicius | 0:5ec996c00568 | 99 | _A2=0; |
fermedicius | 0:5ec996c00568 | 100 | _A3=0; |
fermedicius | 0:5ec996c00568 | 101 | break; |
fermedicius | 0:5ec996c00568 | 102 | |
fermedicius | 0:5ec996c00568 | 103 | case 2: |
fermedicius | 0:5ec996c00568 | 104 | _A0=0; |
fermedicius | 0:5ec996c00568 | 105 | _A1=0; |
fermedicius | 0:5ec996c00568 | 106 | _A2=0; |
fermedicius | 0:5ec996c00568 | 107 | _A3=0; |
fermedicius | 0:5ec996c00568 | 108 | break; |
fermedicius | 0:5ec996c00568 | 109 | |
fermedicius | 0:5ec996c00568 | 110 | case 3: |
fermedicius | 0:5ec996c00568 | 111 | _A0=0; |
fermedicius | 0:5ec996c00568 | 112 | _A1=0; |
fermedicius | 0:5ec996c00568 | 113 | _A2=0; |
fermedicius | 0:5ec996c00568 | 114 | _A3=0; |
fermedicius | 0:5ec996c00568 | 115 | break; |
fermedicius | 0:5ec996c00568 | 116 | |
fermedicius | 0:5ec996c00568 | 117 | case 4: |
fermedicius | 0:5ec996c00568 | 118 | _A0=0; |
fermedicius | 0:5ec996c00568 | 119 | _A1=0; |
fermedicius | 0:5ec996c00568 | 120 | _A2=0; |
fermedicius | 0:5ec996c00568 | 121 | _A3=0; |
fermedicius | 0:5ec996c00568 | 122 | break; |
fermedicius | 0:5ec996c00568 | 123 | |
fermedicius | 0:5ec996c00568 | 124 | case 5: |
fermedicius | 0:5ec996c00568 | 125 | _A0=0; |
fermedicius | 0:5ec996c00568 | 126 | _A1=0; |
fermedicius | 0:5ec996c00568 | 127 | _A2=0; |
fermedicius | 0:5ec996c00568 | 128 | _A3=0; |
fermedicius | 0:5ec996c00568 | 129 | break; |
fermedicius | 0:5ec996c00568 | 130 | |
fermedicius | 0:5ec996c00568 | 131 | case 6: |
fermedicius | 0:5ec996c00568 | 132 | _A0=0; |
fermedicius | 0:5ec996c00568 | 133 | _A1=0; |
fermedicius | 0:5ec996c00568 | 134 | _A2=0; |
fermedicius | 0:5ec996c00568 | 135 | _A3=0; |
fermedicius | 0:5ec996c00568 | 136 | break; |
fermedicius | 0:5ec996c00568 | 137 | |
fermedicius | 0:5ec996c00568 | 138 | case 7: |
fermedicius | 0:5ec996c00568 | 139 | _A0=0; |
fermedicius | 0:5ec996c00568 | 140 | _A1=0; |
fermedicius | 0:5ec996c00568 | 141 | _A2=0; |
fermedicius | 0:5ec996c00568 | 142 | _A3=0; |
fermedicius | 0:5ec996c00568 | 143 | break; |
fermedicius | 0:5ec996c00568 | 144 | } |
fermedicius | 0:5ec996c00568 | 145 | wait_us(motorspeed); // wait time defines the speed |
fermedicius | 0:5ec996c00568 | 146 | } |
fermedicius | 0:5ec996c00568 | 147 | |
fermedicius | 0:5ec996c00568 | 148 | if(flag2 == 1) |
fermedicius | 0:5ec996c00568 | 149 | { |
fermedicius | 0:5ec996c00568 | 150 | switch(i) |
fermedicius | 0:5ec996c00568 | 151 | { |
fermedicius | 0:5ec996c00568 | 152 | case 0: |
fermedicius | 0:5ec996c00568 | 153 | _B0=1; |
fermedicius | 0:5ec996c00568 | 154 | _B1=0; |
fermedicius | 0:5ec996c00568 | 155 | _B2=0; |
fermedicius | 0:5ec996c00568 | 156 | _B3=1; |
fermedicius | 0:5ec996c00568 | 157 | break; |
fermedicius | 0:5ec996c00568 | 158 | |
fermedicius | 0:5ec996c00568 | 159 | case 1: |
fermedicius | 0:5ec996c00568 | 160 | _B0=1; |
fermedicius | 0:5ec996c00568 | 161 | _B1=0; |
fermedicius | 0:5ec996c00568 | 162 | _B2=0; |
fermedicius | 0:5ec996c00568 | 163 | _B3=0; |
fermedicius | 0:5ec996c00568 | 164 | break; |
fermedicius | 0:5ec996c00568 | 165 | |
fermedicius | 0:5ec996c00568 | 166 | case 2: |
fermedicius | 0:5ec996c00568 | 167 | _B0=1; |
fermedicius | 0:5ec996c00568 | 168 | _B1=1; |
fermedicius | 0:5ec996c00568 | 169 | _B2=0; |
fermedicius | 0:5ec996c00568 | 170 | _B3=0; |
fermedicius | 0:5ec996c00568 | 171 | break; |
fermedicius | 0:5ec996c00568 | 172 | |
fermedicius | 0:5ec996c00568 | 173 | case 3: |
fermedicius | 0:5ec996c00568 | 174 | _B0=0; |
fermedicius | 0:5ec996c00568 | 175 | _B1=1; |
fermedicius | 0:5ec996c00568 | 176 | _B2=0; |
fermedicius | 0:5ec996c00568 | 177 | _B3=0; |
fermedicius | 0:5ec996c00568 | 178 | break; |
fermedicius | 0:5ec996c00568 | 179 | |
fermedicius | 0:5ec996c00568 | 180 | case 4: |
fermedicius | 0:5ec996c00568 | 181 | _B0=0; |
fermedicius | 0:5ec996c00568 | 182 | _B1=1; |
fermedicius | 0:5ec996c00568 | 183 | _B2=1; |
fermedicius | 0:5ec996c00568 | 184 | _B3=0; |
fermedicius | 0:5ec996c00568 | 185 | break; |
fermedicius | 0:5ec996c00568 | 186 | |
fermedicius | 0:5ec996c00568 | 187 | case 5: |
fermedicius | 0:5ec996c00568 | 188 | _B0=0; |
fermedicius | 0:5ec996c00568 | 189 | _B1=0; |
fermedicius | 0:5ec996c00568 | 190 | _B2=1; |
fermedicius | 0:5ec996c00568 | 191 | _B3=0; |
fermedicius | 0:5ec996c00568 | 192 | break; |
fermedicius | 0:5ec996c00568 | 193 | |
fermedicius | 0:5ec996c00568 | 194 | case 6: |
fermedicius | 0:5ec996c00568 | 195 | _B0=0; |
fermedicius | 0:5ec996c00568 | 196 | _B1=0; |
fermedicius | 0:5ec996c00568 | 197 | _B2=1; |
fermedicius | 0:5ec996c00568 | 198 | _B3=1; |
fermedicius | 0:5ec996c00568 | 199 | break; |
fermedicius | 0:5ec996c00568 | 200 | |
fermedicius | 0:5ec996c00568 | 201 | case 7: |
fermedicius | 0:5ec996c00568 | 202 | _B0=0; |
fermedicius | 0:5ec996c00568 | 203 | _B1=0; |
fermedicius | 0:5ec996c00568 | 204 | _B2=0; |
fermedicius | 0:5ec996c00568 | 205 | _B3=1; |
fermedicius | 0:5ec996c00568 | 206 | break; |
fermedicius | 0:5ec996c00568 | 207 | } |
fermedicius | 0:5ec996c00568 | 208 | wait_us(motorspeed); // wait time defines the speed |
fermedicius | 0:5ec996c00568 | 209 | } |
fermedicius | 0:5ec996c00568 | 210 | |
fermedicius | 0:5ec996c00568 | 211 | else if(flag2 == 0) |
fermedicius | 0:5ec996c00568 | 212 | { |
fermedicius | 0:5ec996c00568 | 213 | switch(i) |
fermedicius | 0:5ec996c00568 | 214 | { |
fermedicius | 0:5ec996c00568 | 215 | case 0: |
fermedicius | 0:5ec996c00568 | 216 | _B0=0; |
fermedicius | 0:5ec996c00568 | 217 | _B1=0; |
fermedicius | 0:5ec996c00568 | 218 | _B2=0; |
fermedicius | 0:5ec996c00568 | 219 | _B3=0; |
fermedicius | 0:5ec996c00568 | 220 | break; |
fermedicius | 0:5ec996c00568 | 221 | |
fermedicius | 0:5ec996c00568 | 222 | case 1: |
fermedicius | 0:5ec996c00568 | 223 | _B0=0; |
fermedicius | 0:5ec996c00568 | 224 | _B1=0; |
fermedicius | 0:5ec996c00568 | 225 | _B2=0; |
fermedicius | 0:5ec996c00568 | 226 | _B3=0; |
fermedicius | 0:5ec996c00568 | 227 | break; |
fermedicius | 0:5ec996c00568 | 228 | |
fermedicius | 0:5ec996c00568 | 229 | case 2: |
fermedicius | 0:5ec996c00568 | 230 | _B0=0; |
fermedicius | 0:5ec996c00568 | 231 | _B1=0; |
fermedicius | 0:5ec996c00568 | 232 | _B2=0; |
fermedicius | 0:5ec996c00568 | 233 | _B3=0; |
fermedicius | 0:5ec996c00568 | 234 | break; |
fermedicius | 0:5ec996c00568 | 235 | |
fermedicius | 0:5ec996c00568 | 236 | case 3: |
fermedicius | 0:5ec996c00568 | 237 | |
fermedicius | 0:5ec996c00568 | 238 | _B0=0; |
fermedicius | 0:5ec996c00568 | 239 | _B1=0; |
fermedicius | 0:5ec996c00568 | 240 | _B2=0; |
fermedicius | 0:5ec996c00568 | 241 | _B3=0; |
fermedicius | 0:5ec996c00568 | 242 | break; |
fermedicius | 0:5ec996c00568 | 243 | |
fermedicius | 0:5ec996c00568 | 244 | case 4: |
fermedicius | 0:5ec996c00568 | 245 | _B0=0; |
fermedicius | 0:5ec996c00568 | 246 | _B1=0; |
fermedicius | 0:5ec996c00568 | 247 | _B2=0; |
fermedicius | 0:5ec996c00568 | 248 | _B3=0; |
fermedicius | 0:5ec996c00568 | 249 | break; |
fermedicius | 0:5ec996c00568 | 250 | |
fermedicius | 0:5ec996c00568 | 251 | case 5: |
fermedicius | 0:5ec996c00568 | 252 | _B0=0; |
fermedicius | 0:5ec996c00568 | 253 | _B1=0; |
fermedicius | 0:5ec996c00568 | 254 | _B2=0; |
fermedicius | 0:5ec996c00568 | 255 | _B3=0; |
fermedicius | 0:5ec996c00568 | 256 | break; |
fermedicius | 0:5ec996c00568 | 257 | |
fermedicius | 0:5ec996c00568 | 258 | case 6: |
fermedicius | 0:5ec996c00568 | 259 | _B0=0; |
fermedicius | 0:5ec996c00568 | 260 | _B1=0; |
fermedicius | 0:5ec996c00568 | 261 | _B2=0; |
fermedicius | 0:5ec996c00568 | 262 | _B3=0; |
fermedicius | 0:5ec996c00568 | 263 | break; |
fermedicius | 0:5ec996c00568 | 264 | |
fermedicius | 0:5ec996c00568 | 265 | case 7: |
fermedicius | 0:5ec996c00568 | 266 | _B0=0; |
fermedicius | 0:5ec996c00568 | 267 | _B1=0; |
fermedicius | 0:5ec996c00568 | 268 | _B2=0; |
fermedicius | 0:5ec996c00568 | 269 | _B3=0; |
fermedicius | 0:5ec996c00568 | 270 | break; |
fermedicius | 0:5ec996c00568 | 271 | } |
fermedicius | 0:5ec996c00568 | 272 | wait_us(motorspeed); // wait time defines the speed |
fermedicius | 0:5ec996c00568 | 273 | } |
fermedicius | 0:5ec996c00568 | 274 | } |
fermedicius | 0:5ec996c00568 | 275 | } |
fermedicius | 0:5ec996c00568 | 276 | |
fermedicius | 0:5ec996c00568 | 277 | void fermeMotor::clockwise(int flag1, int flag2, int motorspeed) |
fermedicius | 0:5ec996c00568 | 278 | { |
fermedicius | 0:5ec996c00568 | 279 | for (int i = 7; i >= 0; i--) |
fermedicius | 0:5ec996c00568 | 280 | { |
fermedicius | 0:5ec996c00568 | 281 | if(flag1 == 1) |
fermedicius | 0:5ec996c00568 | 282 | { |
fermedicius | 0:5ec996c00568 | 283 | switch(i) |
fermedicius | 0:5ec996c00568 | 284 | { |
fermedicius | 0:5ec996c00568 | 285 | case 0: |
fermedicius | 0:5ec996c00568 | 286 | _A0=0; |
fermedicius | 0:5ec996c00568 | 287 | _A1=0; |
fermedicius | 0:5ec996c00568 | 288 | _A2=0; |
fermedicius | 0:5ec996c00568 | 289 | _A3=1; |
fermedicius | 0:5ec996c00568 | 290 | break; |
fermedicius | 0:5ec996c00568 | 291 | |
fermedicius | 0:5ec996c00568 | 292 | case 1: |
fermedicius | 0:5ec996c00568 | 293 | _A0=0; |
fermedicius | 0:5ec996c00568 | 294 | _A1=0; |
fermedicius | 0:5ec996c00568 | 295 | _A2=1; |
fermedicius | 0:5ec996c00568 | 296 | _A3=1; |
fermedicius | 0:5ec996c00568 | 297 | break; |
fermedicius | 0:5ec996c00568 | 298 | |
fermedicius | 0:5ec996c00568 | 299 | case 2: |
fermedicius | 0:5ec996c00568 | 300 | _A0=0; |
fermedicius | 0:5ec996c00568 | 301 | _A1=0; |
fermedicius | 0:5ec996c00568 | 302 | _A2=1; |
fermedicius | 0:5ec996c00568 | 303 | _A3=0; |
fermedicius | 0:5ec996c00568 | 304 | break; |
fermedicius | 0:5ec996c00568 | 305 | |
fermedicius | 0:5ec996c00568 | 306 | case 3: |
fermedicius | 0:5ec996c00568 | 307 | _A0=0; |
fermedicius | 0:5ec996c00568 | 308 | _A1=1; |
fermedicius | 0:5ec996c00568 | 309 | _A2=1; |
fermedicius | 0:5ec996c00568 | 310 | _A3=0; |
fermedicius | 0:5ec996c00568 | 311 | break; |
fermedicius | 0:5ec996c00568 | 312 | |
fermedicius | 0:5ec996c00568 | 313 | case 4: |
fermedicius | 0:5ec996c00568 | 314 | _A0=0; |
fermedicius | 0:5ec996c00568 | 315 | _A1=1; |
fermedicius | 0:5ec996c00568 | 316 | _A2=0; |
fermedicius | 0:5ec996c00568 | 317 | _A3=0; |
fermedicius | 0:5ec996c00568 | 318 | break; |
fermedicius | 0:5ec996c00568 | 319 | |
fermedicius | 0:5ec996c00568 | 320 | case 5: |
fermedicius | 0:5ec996c00568 | 321 | _A0=1; |
fermedicius | 0:5ec996c00568 | 322 | _A1=1; |
fermedicius | 0:5ec996c00568 | 323 | _A2=0; |
fermedicius | 0:5ec996c00568 | 324 | _A3=0; |
fermedicius | 0:5ec996c00568 | 325 | break; |
fermedicius | 0:5ec996c00568 | 326 | |
fermedicius | 0:5ec996c00568 | 327 | case 6: |
fermedicius | 0:5ec996c00568 | 328 | _A0=1; |
fermedicius | 0:5ec996c00568 | 329 | _A1=0; |
fermedicius | 0:5ec996c00568 | 330 | _A2=0; |
fermedicius | 0:5ec996c00568 | 331 | _A3=0; |
fermedicius | 0:5ec996c00568 | 332 | break; |
fermedicius | 0:5ec996c00568 | 333 | |
fermedicius | 0:5ec996c00568 | 334 | case 7: |
fermedicius | 0:5ec996c00568 | 335 | _A0=1; |
fermedicius | 0:5ec996c00568 | 336 | _A1=0; |
fermedicius | 0:5ec996c00568 | 337 | _A2=0; |
fermedicius | 0:5ec996c00568 | 338 | _A3=1; |
fermedicius | 0:5ec996c00568 | 339 | break; |
fermedicius | 0:5ec996c00568 | 340 | } |
fermedicius | 0:5ec996c00568 | 341 | wait_us(motorspeed); // wait time defines the speed |
fermedicius | 0:5ec996c00568 | 342 | } |
fermedicius | 0:5ec996c00568 | 343 | |
fermedicius | 0:5ec996c00568 | 344 | else if(flag1 == 0) |
fermedicius | 0:5ec996c00568 | 345 | { |
fermedicius | 0:5ec996c00568 | 346 | switch(i) |
fermedicius | 0:5ec996c00568 | 347 | { |
fermedicius | 0:5ec996c00568 | 348 | case 0: |
fermedicius | 0:5ec996c00568 | 349 | _A0=0; |
fermedicius | 0:5ec996c00568 | 350 | _A1=0; |
fermedicius | 0:5ec996c00568 | 351 | _A2=0; |
fermedicius | 0:5ec996c00568 | 352 | _A3=0; |
fermedicius | 0:5ec996c00568 | 353 | break; |
fermedicius | 0:5ec996c00568 | 354 | |
fermedicius | 0:5ec996c00568 | 355 | case 1: |
fermedicius | 0:5ec996c00568 | 356 | _A0=0; |
fermedicius | 0:5ec996c00568 | 357 | _A1=0; |
fermedicius | 0:5ec996c00568 | 358 | _A2=0; |
fermedicius | 0:5ec996c00568 | 359 | _A3=0; |
fermedicius | 0:5ec996c00568 | 360 | break; |
fermedicius | 0:5ec996c00568 | 361 | |
fermedicius | 0:5ec996c00568 | 362 | case 2: |
fermedicius | 0:5ec996c00568 | 363 | _A0=0; |
fermedicius | 0:5ec996c00568 | 364 | _A1=0; |
fermedicius | 0:5ec996c00568 | 365 | _A2=0; |
fermedicius | 0:5ec996c00568 | 366 | _A3=0; |
fermedicius | 0:5ec996c00568 | 367 | break; |
fermedicius | 0:5ec996c00568 | 368 | |
fermedicius | 0:5ec996c00568 | 369 | case 3: |
fermedicius | 0:5ec996c00568 | 370 | _A0=0; |
fermedicius | 0:5ec996c00568 | 371 | _A1=0; |
fermedicius | 0:5ec996c00568 | 372 | _A2=0; |
fermedicius | 0:5ec996c00568 | 373 | _A3=0; |
fermedicius | 0:5ec996c00568 | 374 | break; |
fermedicius | 0:5ec996c00568 | 375 | |
fermedicius | 0:5ec996c00568 | 376 | case 4: |
fermedicius | 0:5ec996c00568 | 377 | _A0=0; |
fermedicius | 0:5ec996c00568 | 378 | _A1=0; |
fermedicius | 0:5ec996c00568 | 379 | _A2=0; |
fermedicius | 0:5ec996c00568 | 380 | _A3=0; |
fermedicius | 0:5ec996c00568 | 381 | break; |
fermedicius | 0:5ec996c00568 | 382 | |
fermedicius | 0:5ec996c00568 | 383 | case 5: |
fermedicius | 0:5ec996c00568 | 384 | _A0=0; |
fermedicius | 0:5ec996c00568 | 385 | _A1=0; |
fermedicius | 0:5ec996c00568 | 386 | _A2=0; |
fermedicius | 0:5ec996c00568 | 387 | _A3=0; |
fermedicius | 0:5ec996c00568 | 388 | break; |
fermedicius | 0:5ec996c00568 | 389 | |
fermedicius | 0:5ec996c00568 | 390 | case 6: |
fermedicius | 0:5ec996c00568 | 391 | _A0=0; |
fermedicius | 0:5ec996c00568 | 392 | _A1=0; |
fermedicius | 0:5ec996c00568 | 393 | _A2=0; |
fermedicius | 0:5ec996c00568 | 394 | _A3=0; |
fermedicius | 0:5ec996c00568 | 395 | break; |
fermedicius | 0:5ec996c00568 | 396 | |
fermedicius | 0:5ec996c00568 | 397 | case 7: |
fermedicius | 0:5ec996c00568 | 398 | _A0=0; |
fermedicius | 0:5ec996c00568 | 399 | _A1=0; |
fermedicius | 0:5ec996c00568 | 400 | _A2=0; |
fermedicius | 0:5ec996c00568 | 401 | _A3=0; |
fermedicius | 0:5ec996c00568 | 402 | break; |
fermedicius | 0:5ec996c00568 | 403 | } |
fermedicius | 0:5ec996c00568 | 404 | wait_us(motorspeed); // wait time defines the speed |
fermedicius | 0:5ec996c00568 | 405 | } |
fermedicius | 0:5ec996c00568 | 406 | |
fermedicius | 0:5ec996c00568 | 407 | if(flag2 == 1) |
fermedicius | 0:5ec996c00568 | 408 | { |
fermedicius | 0:5ec996c00568 | 409 | switch(i) |
fermedicius | 0:5ec996c00568 | 410 | { |
fermedicius | 0:5ec996c00568 | 411 | case 0: |
fermedicius | 0:5ec996c00568 | 412 | _B0=1; |
fermedicius | 0:5ec996c00568 | 413 | _B1=0; |
fermedicius | 0:5ec996c00568 | 414 | _B2=1; |
fermedicius | 0:5ec996c00568 | 415 | _B3=0; |
fermedicius | 0:5ec996c00568 | 416 | break; |
fermedicius | 0:5ec996c00568 | 417 | |
fermedicius | 0:5ec996c00568 | 418 | case 1: |
fermedicius | 0:5ec996c00568 | 419 | _B0=1; |
fermedicius | 0:5ec996c00568 | 420 | _B1=0; |
fermedicius | 0:5ec996c00568 | 421 | _B2=1; |
fermedicius | 0:5ec996c00568 | 422 | _B3=1; |
fermedicius | 0:5ec996c00568 | 423 | break; |
fermedicius | 0:5ec996c00568 | 424 | |
fermedicius | 0:5ec996c00568 | 425 | case 2: |
fermedicius | 0:5ec996c00568 | 426 | _B0=1; |
fermedicius | 0:5ec996c00568 | 427 | _B1=1; |
fermedicius | 0:5ec996c00568 | 428 | _B2=1; |
fermedicius | 0:5ec996c00568 | 429 | _B3=1; |
fermedicius | 0:5ec996c00568 | 430 | break; |
fermedicius | 0:5ec996c00568 | 431 | |
fermedicius | 0:5ec996c00568 | 432 | case 3: |
fermedicius | 0:5ec996c00568 | 433 | _B0=0; |
fermedicius | 0:5ec996c00568 | 434 | _B1=1; |
fermedicius | 0:5ec996c00568 | 435 | _B2=1; |
fermedicius | 0:5ec996c00568 | 436 | _B3=1; |
fermedicius | 0:5ec996c00568 | 437 | break; |
fermedicius | 0:5ec996c00568 | 438 | |
fermedicius | 0:5ec996c00568 | 439 | case 4: |
fermedicius | 0:5ec996c00568 | 440 | _B0=0; |
fermedicius | 0:5ec996c00568 | 441 | _B1=1; |
fermedicius | 0:5ec996c00568 | 442 | _B2=0; |
fermedicius | 0:5ec996c00568 | 443 | _B3=1; |
fermedicius | 0:5ec996c00568 | 444 | break; |
fermedicius | 0:5ec996c00568 | 445 | |
fermedicius | 0:5ec996c00568 | 446 | case 5: |
fermedicius | 0:5ec996c00568 | 447 | _B0=0; |
fermedicius | 0:5ec996c00568 | 448 | _B1=0; |
fermedicius | 0:5ec996c00568 | 449 | _B2=0; |
fermedicius | 0:5ec996c00568 | 450 | _B3=1; |
fermedicius | 0:5ec996c00568 | 451 | break; |
fermedicius | 0:5ec996c00568 | 452 | |
fermedicius | 0:5ec996c00568 | 453 | case 6: |
fermedicius | 0:5ec996c00568 | 454 | _B0=0; |
fermedicius | 0:5ec996c00568 | 455 | _B1=0; |
fermedicius | 0:5ec996c00568 | 456 | _B2=0; |
fermedicius | 0:5ec996c00568 | 457 | _B3=0; |
fermedicius | 0:5ec996c00568 | 458 | break; |
fermedicius | 0:5ec996c00568 | 459 | |
fermedicius | 0:5ec996c00568 | 460 | case 7: |
fermedicius | 0:5ec996c00568 | 461 | _B0=0; |
fermedicius | 0:5ec996c00568 | 462 | _B1=0; |
fermedicius | 0:5ec996c00568 | 463 | _B2=1; |
fermedicius | 0:5ec996c00568 | 464 | _B3=0; |
fermedicius | 0:5ec996c00568 | 465 | break; |
fermedicius | 0:5ec996c00568 | 466 | } |
fermedicius | 0:5ec996c00568 | 467 | wait_us(motorspeed); // wait time defines the speed |
fermedicius | 0:5ec996c00568 | 468 | } |
fermedicius | 0:5ec996c00568 | 469 | |
fermedicius | 0:5ec996c00568 | 470 | else if(flag2 == 0) |
fermedicius | 0:5ec996c00568 | 471 | { |
fermedicius | 0:5ec996c00568 | 472 | switch(i) |
fermedicius | 0:5ec996c00568 | 473 | { |
fermedicius | 0:5ec996c00568 | 474 | case 0: |
fermedicius | 0:5ec996c00568 | 475 | _B0=0; |
fermedicius | 0:5ec996c00568 | 476 | _B1=0; |
fermedicius | 0:5ec996c00568 | 477 | _B2=0; |
fermedicius | 0:5ec996c00568 | 478 | _B3=0; |
fermedicius | 0:5ec996c00568 | 479 | break; |
fermedicius | 0:5ec996c00568 | 480 | |
fermedicius | 0:5ec996c00568 | 481 | case 1: |
fermedicius | 0:5ec996c00568 | 482 | _B0=0; |
fermedicius | 0:5ec996c00568 | 483 | _B1=0; |
fermedicius | 0:5ec996c00568 | 484 | _B2=0; |
fermedicius | 0:5ec996c00568 | 485 | _B3=0; |
fermedicius | 0:5ec996c00568 | 486 | break; |
fermedicius | 0:5ec996c00568 | 487 | |
fermedicius | 0:5ec996c00568 | 488 | case 2: |
fermedicius | 0:5ec996c00568 | 489 | _B0=0; |
fermedicius | 0:5ec996c00568 | 490 | _B1=0; |
fermedicius | 0:5ec996c00568 | 491 | _B2=0; |
fermedicius | 0:5ec996c00568 | 492 | _B3=0; |
fermedicius | 0:5ec996c00568 | 493 | break; |
fermedicius | 0:5ec996c00568 | 494 | |
fermedicius | 0:5ec996c00568 | 495 | case 3: |
fermedicius | 0:5ec996c00568 | 496 | _B0=0; |
fermedicius | 0:5ec996c00568 | 497 | _B1=0; |
fermedicius | 0:5ec996c00568 | 498 | _B2=0; |
fermedicius | 0:5ec996c00568 | 499 | _B3=0; |
fermedicius | 0:5ec996c00568 | 500 | break; |
fermedicius | 0:5ec996c00568 | 501 | |
fermedicius | 0:5ec996c00568 | 502 | case 4: |
fermedicius | 0:5ec996c00568 | 503 | _B0=0; |
fermedicius | 0:5ec996c00568 | 504 | _B1=0; |
fermedicius | 0:5ec996c00568 | 505 | _B2=0; |
fermedicius | 0:5ec996c00568 | 506 | _B3=0; |
fermedicius | 0:5ec996c00568 | 507 | break; |
fermedicius | 0:5ec996c00568 | 508 | |
fermedicius | 0:5ec996c00568 | 509 | case 5: |
fermedicius | 0:5ec996c00568 | 510 | _B0=0; |
fermedicius | 0:5ec996c00568 | 511 | _B1=0; |
fermedicius | 0:5ec996c00568 | 512 | _B2=0; |
fermedicius | 0:5ec996c00568 | 513 | _B3=0; |
fermedicius | 0:5ec996c00568 | 514 | break; |
fermedicius | 0:5ec996c00568 | 515 | |
fermedicius | 0:5ec996c00568 | 516 | case 6: |
fermedicius | 0:5ec996c00568 | 517 | _B0=0; |
fermedicius | 0:5ec996c00568 | 518 | _B1=0; |
fermedicius | 0:5ec996c00568 | 519 | _B2=0; |
fermedicius | 0:5ec996c00568 | 520 | _B3=0; |
fermedicius | 0:5ec996c00568 | 521 | break; |
fermedicius | 0:5ec996c00568 | 522 | |
fermedicius | 0:5ec996c00568 | 523 | case 7: |
fermedicius | 0:5ec996c00568 | 524 | _B0=0; |
fermedicius | 0:5ec996c00568 | 525 | _B1=0; |
fermedicius | 0:5ec996c00568 | 526 | _B2=0; |
fermedicius | 0:5ec996c00568 | 527 | _B3=0; |
fermedicius | 0:5ec996c00568 | 528 | break; |
fermedicius | 0:5ec996c00568 | 529 | } |
fermedicius | 0:5ec996c00568 | 530 | wait_us(motorspeed); // wait time defines the speed |
fermedicius | 0:5ec996c00568 | 531 | } |
fermedicius | 0:5ec996c00568 | 532 | } |
fermedicius | 0:5ec996c00568 | 533 | } |
fermedicius | 0:5ec996c00568 | 534 | |
fermedicius | 0:5ec996c00568 | 535 | void fermeMotor::fstep(int num_stepsA, int num_stepsB, int direction, int speed) |
fermedicius | 0:5ec996c00568 | 536 | { |
fermedicius | 0:5ec996c00568 | 537 | int count=0; // initalize step count |
fermedicius | 0:5ec996c00568 | 538 | fermemotorSpeed=speed; //set motor speed |
fermedicius | 0:5ec996c00568 | 539 | int num_steps = (num_stepsA > num_stepsB) ? num_stepsA : num_stepsB; |
fermedicius | 0:5ec996c00568 | 540 | int flagA = 0; |
fermedicius | 0:5ec996c00568 | 541 | int flagB = 0; |
fermedicius | 0:5ec996c00568 | 542 | if (direction==0) // turn clockwise |
fermedicius | 0:5ec996c00568 | 543 | { |
fermedicius | 0:5ec996c00568 | 544 | do { |
fermedicius | 0:5ec996c00568 | 545 | if(count < num_stepsA) flagA=1; |
fermedicius | 0:5ec996c00568 | 546 | else flagA=0; |
fermedicius | 0:5ec996c00568 | 547 | if(count < num_stepsB) flagB=1; |
fermedicius | 0:5ec996c00568 | 548 | else flagB=0; |
fermedicius | 0:5ec996c00568 | 549 | clockwise(flagA, flagB, fermemotorSpeed); |
fermedicius | 0:5ec996c00568 | 550 | count++; |
fermedicius | 0:5ec996c00568 | 551 | } while (count < num_steps); // turn number of steps applied |
fermedicius | 0:5ec996c00568 | 552 | } |
fermedicius | 0:5ec996c00568 | 553 | |
fermedicius | 0:5ec996c00568 | 554 | else if (direction==1)// turn anticlockwise: default direction for recepticle and microtrack conveyor to go forward |
fermedicius | 0:5ec996c00568 | 555 | { |
fermedicius | 0:5ec996c00568 | 556 | count=0; |
fermedicius | 0:5ec996c00568 | 557 | do |
fermedicius | 0:5ec996c00568 | 558 | { |
fermedicius | 0:5ec996c00568 | 559 | if(count < num_stepsA) flagA=1; |
fermedicius | 0:5ec996c00568 | 560 | else flagA=0; |
fermedicius | 0:5ec996c00568 | 561 | if(count<num_stepsB) flagB=1; |
fermedicius | 0:5ec996c00568 | 562 | else flagB=0; |
fermedicius | 0:5ec996c00568 | 563 | anticlockwise(flagA, flagB, fermemotorSpeed); |
fermedicius | 0:5ec996c00568 | 564 | count++; |
fermedicius | 0:5ec996c00568 | 565 | } while (count < num_steps);// turn number of steps applied |
fermedicius | 0:5ec996c00568 | 566 | } |
fermedicius | 0:5ec996c00568 | 567 | } |
fermedicius | 0:5ec996c00568 | 568 | |
fermedicius | 0:5ec996c00568 | 569 | /* The 2 stepper motors, recepticle and microtrack run in different directions in JuiceWorks machine. |
fermedicius | 0:5ec996c00568 | 570 | The direction of the recepticle stepper motor is anticlockwise (i.e. direction = 1) and the direction of the microtrack stepper motor is clockwise (i.e. direction = 0). |
fermedicius | 0:5ec996c00568 | 571 | Thus here in the function fermeMotor, direction = 1 is send as an default argument. This indicates that the the recepticle conveyor will move forward (anticlockwisse direction = 1) |
fermedicius | 0:5ec996c00568 | 572 | and the microtrack stepper will move forward in the clockwise direction = 0. |
fermedicius | 0:5ec996c00568 | 573 | */ |