Просмотр исходного кода

- Add support for L6470 Drivers.

- Both TMC, L6470 and pin-driven drivers work.
- All can be mixed and matched as needed.
domonoky 9 лет назад
Родитель
Сommit
443e7edef4

+ 723
- 0
ArduinoAddons/Arduino_1.x.x/libraries/L6470/L6470.cpp Просмотреть файл

@@ -0,0 +1,723 @@
1
+////////////////////////////////////////////////////////////
2
+//ORIGINAL CODE 12/12/2011- Mike Hord, SparkFun Electronics
3
+//LIBRARY Created by Adam Meyer of bildr Aug 18th 2012
4
+//Released as MIT license
5
+////////////////////////////////////////////////////////////
6
+
7
+#include <Arduino.h>
8
+#include "L6470.h"
9
+#include <SPI.h>
10
+
11
+#define ENABLE_RESET_PIN	0
12
+#define K_VALUE			100
13
+
14
+L6470::L6470(int SSPin){
15
+  _SSPin = SSPin;
16
+  // Serial.begin(9600);
17
+}
18
+
19
+void L6470::init(int k_value){
20
+  // This is the generic initialization function to set up the Arduino to
21
+  // communicate with the dSPIN chip.
22
+  
23
+  // set up the input/output pins for the application.
24
+  pinMode(SLAVE_SELECT_PIN, OUTPUT); // The SPI peripheral REQUIRES the hardware SS pin-
25
+  // pin 10- to be an output. This is in here just
26
+  // in case some future user makes something other
27
+  // than pin 10 the SS pin.
28
+  
29
+  pinMode(_SSPin, OUTPUT);
30
+  digitalWrite(_SSPin, HIGH);
31
+  pinMode(MOSI, OUTPUT);
32
+  pinMode(MISO, INPUT);
33
+  pinMode(SCK, OUTPUT);
34
+  pinMode(BUSYN, INPUT);
35
+#if (ENABLE_RESET_PIN == 1)
36
+  pinMode(RESET, OUTPUT);
37
+  // reset the dSPIN chip. This could also be accomplished by
38
+  // calling the "L6470::ResetDev()" function after SPI is initialized.
39
+  digitalWrite(RESET, HIGH);
40
+  delay(10);
41
+  digitalWrite(RESET, LOW);
42
+  delay(10);
43
+  digitalWrite(RESET, HIGH);
44
+  delay(10);
45
+#endif
46
+  
47
+  
48
+  // initialize SPI for the dSPIN chip's needs:
49
+  // most significant bit first,
50
+  // SPI clock not to exceed 5MHz,
51
+  // SPI_MODE3 (clock idle high, latch data on rising edge of clock)
52
+  SPI.begin();
53
+  SPI.setBitOrder(MSBFIRST);
54
+  SPI.setClockDivider(SPI_CLOCK_DIV16); // or 2, 8, 16, 32, 64
55
+  SPI.setDataMode(SPI_MODE3);
56
+  
57
+  // First things first: let's check communications. The CONFIG register should
58
+  // power up to 0x2E88, so we can use that to check the communications.
59
+  if (GetParam(CONFIG) == 0x2E88){
60
+    //Serial.println('good to go');
61
+  }
62
+  else{
63
+    //Serial.println('Comm issue');
64
+  }
65
+
66
+#if  (ENABLE_RESET_PIN == 0) 
67
+  resetDev();
68
+#endif
69
+  // First, let's set the step mode register:
70
+  // - SYNC_EN controls whether the BUSY/SYNC pin reflects the step
71
+  // frequency or the BUSY status of the chip. We want it to be the BUSY
72
+  // status.
73
+  // - STEP_SEL_x is the microstepping rate- we'll go full step.
74
+  // - SYNC_SEL_x is the ratio of (micro)steps to toggles on the
75
+  // BUSY/SYNC pin (when that pin is used for SYNC). Make it 1:1, despite
76
+  // not using that pin.
77
+  //SetParam(STEP_MODE, !SYNC_EN | STEP_SEL_1 | SYNC_SEL_1);
78
+  
79
+  
80
+  SetParam(KVAL_RUN, k_value);
81
+  SetParam(KVAL_ACC, k_value);
82
+  SetParam(KVAL_DEC, k_value);
83
+  SetParam(KVAL_HOLD, k_value);
84
+  
85
+  // Set up the CONFIG register as follows:
86
+  // PWM frequency divisor = 1
87
+  // PWM frequency multiplier = 2 (62.5kHz PWM frequency)
88
+  // Slew rate is 290V/us
89
+  // Do NOT shut down bridges on overcurrent
90
+  // Disable motor voltage compensation
91
+  // Hard stop on switch low
92
+  // 16MHz internal oscillator, nothing on output
93
+  SetParam(CONFIG, CONFIG_PWM_DIV_1 | CONFIG_PWM_MUL_2 | CONFIG_SR_290V_us| CONFIG_OC_SD_DISABLE | CONFIG_VS_COMP_DISABLE | CONFIG_SW_HARD_STOP | CONFIG_INT_16MHZ);
94
+  // Configure the RUN KVAL. This defines the duty cycle of the PWM of the bridges
95
+  // during running. 0xFF means that they are essentially NOT PWMed during run; this
96
+  // MAY result in more power being dissipated than you actually need for the task.
97
+  // Setting this value too low may result in failure to turn.
98
+  // There are ACC, DEC, and HOLD KVAL registers as well; you may need to play with
99
+  // those values to get acceptable performance for a given application.
100
+  //SetParam(KVAL_RUN, 0xFF);
101
+  // Calling GetStatus() clears the UVLO bit in the status register, which is set by
102
+  // default on power-up. The driver may not run without that bit cleared by this
103
+  // read operation.
104
+  getStatus();
105
+  
106
+  hardStop(); //engage motors
107
+}
108
+
109
+boolean L6470::isBusy(){
110
+  int status = getStatus();
111
+  return !((status >> 1) & 0b1);
112
+}
113
+
114
+void L6470::setMicroSteps(int microSteps){
115
+  byte stepVal = 0;
116
+  
117
+  for(stepVal = 0; stepVal < 8; stepVal++){
118
+    if(microSteps == 1) break;
119
+    microSteps = microSteps >> 1;
120
+  }
121
+
122
+  SetParam(STEP_MODE, !SYNC_EN | stepVal | SYNC_SEL_1);
123
+}
124
+
125
+void L6470::setThresholdSpeed(float thresholdSpeed){
126
+  // Configure the FS_SPD register- this is the speed at which the driver ceases
127
+  // microstepping and goes to full stepping. FSCalc() converts a value in steps/s
128
+  // to a value suitable for this register; to disable full-step switching, you
129
+  // can pass 0x3FF to this register.
130
+  
131
+  if(thresholdSpeed == 0.0){
132
+    SetParam(FS_SPD, 0x3FF);
133
+  }
134
+  else{
135
+    SetParam(FS_SPD, FSCalc(thresholdSpeed));	
136
+  }
137
+}
138
+
139
+
140
+void L6470::setCurrent(int current){}
141
+
142
+
143
+
144
+void L6470::setMaxSpeed(int speed){
145
+  // Configure the MAX_SPEED register- this is the maximum number of (micro)steps per
146
+  // second allowed. You'll want to mess around with your desired application to see
147
+  // how far you can push it before the motor starts to slip. The ACTUAL parameter
148
+  // passed to this function is in steps/tick; MaxSpdCalc() will convert a number of
149
+  // steps/s into an appropriate value for this function. Note that for any move or
150
+  // goto type function where no speed is specified, this value will be used.
151
+  SetParam(MAX_SPEED, MaxSpdCalc(speed));
152
+}
153
+
154
+
155
+void L6470::setMinSpeed(int speed){
156
+  // Configure the MAX_SPEED register- this is the maximum number of (micro)steps per
157
+  // second allowed. You'll want to mess around with your desired application to see
158
+  // how far you can push it before the motor starts to slip. The ACTUAL parameter
159
+  // passed to this function is in steps/tick; MaxSpdCalc() will convert a number of
160
+  // steps/s into an appropriate value for this function. Note that for any move or
161
+  // goto type function where no speed is specified, this value will be used.
162
+  SetParam(MIN_SPEED, MinSpdCalc(speed));
163
+}
164
+
165
+
166
+
167
+
168
+void L6470::setAcc(float acceleration){
169
+  // Configure the acceleration rate, in steps/tick/tick. There is also a DEC register;
170
+  // both of them have a function (AccCalc() and DecCalc() respectively) that convert
171
+  // from steps/s/s into the appropriate value for the register. Writing ACC to 0xfff
172
+  // sets the acceleration and deceleration to 'infinite' (or as near as the driver can
173
+  // manage). If ACC is set to 0xfff, DEC is ignored. To get infinite deceleration
174
+  // without infinite acceleration, only hard stop will work.
175
+  unsigned long accelerationBYTES = AccCalc(acceleration);
176
+  SetParam(ACC, accelerationBYTES);
177
+}
178
+
179
+
180
+void L6470::setDec(float deceleration){
181
+  unsigned long decelerationBYTES = DecCalc(deceleration);
182
+  SetParam(DEC, decelerationBYTES);
183
+}
184
+
185
+
186
+long L6470::getPos(){
187
+  unsigned long position = GetParam(ABS_POS);
188
+  return convert(position);
189
+}
190
+
191
+float L6470::getSpeed(){
192
+  /*
193
+  SPEED
194
+  The SPEED register contains the current motor speed, expressed in step/tick (format unsigned fixed point 0.28).
195
+  In order to convert the SPEED value in step/s the following formula can be used:
196
+  Equation 4
197
+  where SPEED is the integer number stored into the register and tick is 250 ns.
198
+  The available range is from 0 to 15625 step/s with a resolution of 0.015 step/s.
199
+  Note: The range effectively available to the user is limited by the MAX_SPEED parameter.
200
+  */
201
+  
202
+  return (float) GetParam(SPEED);
203
+  //return (float) speed * pow(8, -22);
204
+  //return FSCalc(speed); NEEDS FIX
205
+}
206
+
207
+
208
+void L6470::setOverCurrent(unsigned int ma_current){
209
+  // Configure the overcurrent detection threshold.
210
+  byte OCValue = floor(ma_current / 375);
211
+  if(OCValue > 0x0F)OCValue = 0x0F;
212
+  SetParam(OCD_TH, OCValue);
213
+}
214
+
215
+void L6470::setStallCurrent(float ma_current){
216
+  byte STHValue = (byte)floor(ma_current / 31.25);
217
+  if(STHValue > 0x80)STHValue = 0x80;
218
+  if(STHValue < 0)STHValue = 0;
219
+  SetParam(STALL_TH, STHValue);
220
+}
221
+
222
+void L6470::SetLowSpeedOpt(boolean enable){
223
+  // Enable or disable the low-speed optimization option. If enabling,
224
+  // the other 12 bits of the register will be automatically zero.
225
+  // When disabling, the value will have to be explicitly written by
226
+  // the user with a SetParam() call. See the datasheet for further
227
+  // information about low-speed optimization.
228
+  Xfer(SET_PARAM | MIN_SPEED);
229
+  if (enable) Param(0x1000, 13);
230
+  else Param(0, 13);
231
+}
232
+
233
+
234
+void L6470::run(byte dir, float spd){
235
+  // RUN sets the motor spinning in a direction (defined by the constants
236
+  // FWD and REV). Maximum speed and minimum speed are defined
237
+  // by the MAX_SPEED and MIN_SPEED registers; exceeding the FS_SPD value
238
+  // will switch the device into full-step mode.
239
+  // The SpdCalc() function is provided to convert steps/s values into
240
+  // appropriate integer values for this function.
241
+  unsigned long speedVal = SpdCalc(spd);
242
+  
243
+  Xfer(RUN | dir);
244
+  if (speedVal > 0xFFFFF) speedVal = 0xFFFFF;
245
+  Xfer((byte)(speedVal >> 16));
246
+  Xfer((byte)(speedVal >> 8));
247
+  Xfer((byte)(speedVal));
248
+}
249
+
250
+
251
+void L6470::Step_Clock(byte dir){
252
+  // STEP_CLOCK puts the device in external step clocking mode. When active,
253
+  // pin 25, STCK, becomes the step clock for the device, and steps it in
254
+  // the direction (set by the FWD and REV constants) imposed by the call
255
+  // of this function. Motion commands (RUN, MOVE, etc) will cause the device
256
+  // to exit step clocking mode.
257
+  Xfer(STEP_CLOCK | dir);
258
+}
259
+
260
+void L6470::move(long n_step){
261
+  // MOVE will send the motor n_step steps (size based on step mode) in the
262
+  // direction imposed by dir (FWD or REV constants may be used). The motor
263
+  // will accelerate according the acceleration and deceleration curves, and
264
+  // will run at MAX_SPEED. Stepping mode will adhere to FS_SPD value, as well.
265
+  
266
+  byte dir;
267
+  
268
+  if(n_step >= 0){
269
+    dir = FWD;
270
+  }
271
+  else{
272
+    dir = REV;
273
+  }
274
+
275
+  long n_stepABS = abs(n_step);
276
+  
277
+  Xfer(MOVE | dir); //set direction
278
+  if (n_stepABS > 0x3FFFFF) n_step = 0x3FFFFF;
279
+  Xfer((byte)(n_stepABS >> 16));
280
+  Xfer((byte)(n_stepABS >> 8));
281
+  Xfer((byte)(n_stepABS));
282
+}
283
+
284
+void L6470::goTo(long pos){
285
+  // GOTO operates much like MOVE, except it produces absolute motion instead
286
+  // of relative motion. The motor will be moved to the indicated position
287
+  // in the shortest possible fashion.
288
+  
289
+  Xfer(GOTO);
290
+  if (pos > 0x3FFFFF) pos = 0x3FFFFF;
291
+  Xfer((byte)(pos >> 16));
292
+  Xfer((byte)(pos >> 8));
293
+  Xfer((byte)(pos));
294
+}
295
+
296
+
297
+void L6470::goTo_DIR(byte dir, long pos){
298
+  // Same as GOTO, but with user constrained rotational direction.
299
+  
300
+  Xfer(GOTO_DIR);
301
+  if (pos > 0x3FFFFF) pos = 0x3FFFFF;
302
+  Xfer((byte)(pos >> 16));
303
+  Xfer((byte)(pos >> 8));
304
+  Xfer((byte)(pos));
305
+}
306
+
307
+void L6470::goUntil(byte act, byte dir, unsigned long spd){
308
+  // GoUntil will set the motor running with direction dir (REV or
309
+  // FWD) until a falling edge is detected on the SW pin. Depending
310
+  // on bit SW_MODE in CONFIG, either a hard stop or a soft stop is
311
+  // performed at the falling edge, and depending on the value of
312
+  // act (either RESET or COPY) the value in the ABS_POS register is
313
+  // either RESET to 0 or COPY-ed into the MARK register.
314
+  Xfer(GO_UNTIL | act | dir);
315
+  if (spd > 0x3FFFFF) spd = 0x3FFFFF;
316
+  Xfer((byte)(spd >> 16));
317
+  Xfer((byte)(spd >> 8));
318
+  Xfer((byte)(spd));
319
+}
320
+
321
+void L6470::releaseSW(byte act, byte dir){
322
+  // Similar in nature to GoUntil, ReleaseSW produces motion at the
323
+  // higher of two speeds: the value in MIN_SPEED or 5 steps/s.
324
+  // The motor continues to run at this speed until a rising edge
325
+  // is detected on the switch input, then a hard stop is performed
326
+  // and the ABS_POS register is either COPY-ed into MARK or RESET to
327
+  // 0, depending on whether RESET or COPY was passed to the function
328
+  // for act.
329
+  Xfer(RELEASE_SW | act | dir);
330
+}
331
+
332
+void L6470::goHome(){
333
+  // GoHome is equivalent to GoTo(0), but requires less time to send.
334
+  // Note that no direction is provided; motion occurs through shortest
335
+  // path. If a direction is required, use GoTo_DIR().
336
+  Xfer(GO_HOME);
337
+}
338
+
339
+void L6470::goMark(){
340
+  // GoMark is equivalent to GoTo(MARK), but requires less time to send.
341
+  // Note that no direction is provided; motion occurs through shortest
342
+  // path. If a direction is required, use GoTo_DIR().
343
+  Xfer(GO_MARK);
344
+}
345
+
346
+
347
+void L6470::setMark(long value){
348
+
349
+  Xfer(MARK);
350
+  if (value > 0x3FFFFF) value = 0x3FFFFF;
351
+  if (value < -0x3FFFFF) value = -0x3FFFFF;
352
+  
353
+  
354
+  Xfer((byte)(value >> 16));
355
+  Xfer((byte)(value >> 8));
356
+  Xfer((byte)(value));
357
+}
358
+
359
+
360
+void L6470::setMark(){
361
+  long value = getPos();
362
+  
363
+  Xfer(MARK);
364
+  if (value > 0x3FFFFF) value = 0x3FFFFF;
365
+  if (value < -0x3FFFFF) value = -0x3FFFFF;
366
+  
367
+  
368
+  Xfer((byte)(value >> 16));
369
+  Xfer((byte)(value >> 8));
370
+  Xfer((byte)(value));
371
+}
372
+
373
+void L6470::setAsHome(){
374
+  // Sets the ABS_POS register to 0, effectively declaring the current
375
+  // position to be "HOME".
376
+  Xfer(RESET_POS);
377
+}
378
+
379
+void L6470::resetDev(){
380
+  // Reset device to power up conditions. Equivalent to toggling the STBY
381
+  // pin or cycling power.
382
+  Xfer(RESET_DEVICE);
383
+}
384
+
385
+void L6470::softStop(){
386
+  // Bring the motor to a halt using the deceleration curve.
387
+  Xfer(SOFT_STOP);
388
+}
389
+
390
+void L6470::hardStop(){
391
+  // Stop the motor right away. No deceleration.
392
+  Xfer(HARD_STOP);
393
+}
394
+
395
+void L6470::softFree(){
396
+  // Decelerate the motor and disengage
397
+  Xfer(SOFT_HIZ);
398
+}
399
+
400
+void L6470::free(){
401
+  // disengage the motor immediately with no deceleration.
402
+  Xfer(HARD_HIZ);
403
+}
404
+
405
+int L6470::getStatus(){
406
+  // Fetch and return the 16-bit value in the STATUS register. Resets
407
+  // any warning flags and exits any error states. Using GetParam()
408
+  // to read STATUS does not clear these values.
409
+  int temp = 0;
410
+  Xfer(GET_STATUS);
411
+  temp = Xfer(0)<<8;
412
+  temp |= Xfer(0);
413
+  return temp;
414
+}
415
+
416
+unsigned long L6470::AccCalc(float stepsPerSecPerSec){
417
+  // The value in the ACC register is [(steps/s/s)*(tick^2)]/(2^-40) where tick is
418
+  // 250ns (datasheet value)- 0x08A on boot.
419
+  // Multiply desired steps/s/s by .137438 to get an appropriate value for this register.
420
+  // This is a 12-bit value, so we need to make sure the value is at or below 0xFFF.
421
+  float temp = stepsPerSecPerSec * 0.137438;
422
+  if( (unsigned long) long(temp) > 0x00000FFF) return 0x00000FFF;
423
+  else return (unsigned long) long(temp);
424
+}
425
+
426
+
427
+unsigned long L6470::DecCalc(float stepsPerSecPerSec){
428
+  // The calculation for DEC is the same as for ACC. Value is 0x08A on boot.
429
+  // This is a 12-bit value, so we need to make sure the value is at or below 0xFFF.
430
+  float temp = stepsPerSecPerSec * 0.137438;
431
+  if( (unsigned long) long(temp) > 0x00000FFF) return 0x00000FFF;
432
+  else return (unsigned long) long(temp);
433
+}
434
+
435
+unsigned long L6470::MaxSpdCalc(float stepsPerSec){
436
+  // The value in the MAX_SPD register is [(steps/s)*(tick)]/(2^-18) where tick is
437
+  // 250ns (datasheet value)- 0x041 on boot.
438
+  // Multiply desired steps/s by .065536 to get an appropriate value for this register
439
+  // This is a 10-bit value, so we need to make sure it remains at or below 0x3FF
440
+  float temp = stepsPerSec * .065536;
441
+  if( (unsigned long) long(temp) > 0x000003FF) return 0x000003FF;
442
+  else return (unsigned long) long(temp);
443
+}
444
+
445
+unsigned long L6470::MinSpdCalc(float stepsPerSec){
446
+  // The value in the MIN_SPD register is [(steps/s)*(tick)]/(2^-24) where tick is
447
+  // 250ns (datasheet value)- 0x000 on boot.
448
+  // Multiply desired steps/s by 4.1943 to get an appropriate value for this register
449
+  // This is a 12-bit value, so we need to make sure the value is at or below 0xFFF.
450
+  float temp = stepsPerSec * 4.1943;
451
+  if( (unsigned long) long(temp) > 0x00000FFF) return 0x00000FFF;
452
+  else return (unsigned long) long(temp);
453
+}
454
+
455
+unsigned long L6470::FSCalc(float stepsPerSec){
456
+  // The value in the FS_SPD register is ([(steps/s)*(tick)]/(2^-18))-0.5 where tick is
457
+  // 250ns (datasheet value)- 0x027 on boot.
458
+  // Multiply desired steps/s by .065536 and subtract .5 to get an appropriate value for this register
459
+  // This is a 10-bit value, so we need to make sure the value is at or below 0x3FF.
460
+  float temp = (stepsPerSec * .065536)-.5;
461
+  if( (unsigned long) long(temp) > 0x000003FF) return 0x000003FF;
462
+  else return (unsigned long) long(temp);
463
+}
464
+
465
+unsigned long L6470::IntSpdCalc(float stepsPerSec){
466
+  // The value in the INT_SPD register is [(steps/s)*(tick)]/(2^-24) where tick is
467
+  // 250ns (datasheet value)- 0x408 on boot.
468
+  // Multiply desired steps/s by 4.1943 to get an appropriate value for this register
469
+  // This is a 14-bit value, so we need to make sure the value is at or below 0x3FFF.
470
+  float temp = stepsPerSec * 4.1943;
471
+  if( (unsigned long) long(temp) > 0x00003FFF) return 0x00003FFF;
472
+  else return (unsigned long) long(temp);
473
+}
474
+
475
+unsigned long L6470::SpdCalc(float stepsPerSec){
476
+  // When issuing RUN command, the 20-bit speed is [(steps/s)*(tick)]/(2^-28) where tick is
477
+  // 250ns (datasheet value).
478
+  // Multiply desired steps/s by 67.106 to get an appropriate value for this register
479
+  // This is a 20-bit value, so we need to make sure the value is at or below 0xFFFFF.
480
+  
481
+  float temp = stepsPerSec * 67.106;
482
+  if( (unsigned long) long(temp) > 0x000FFFFF) return 0x000FFFFF;
483
+  else return (unsigned long)temp;
484
+}
485
+
486
+unsigned long L6470::Param(unsigned long value, byte bit_len){
487
+  // Generalization of the subsections of the register read/write functionality.
488
+  // We want the end user to just write the value without worrying about length,
489
+  // so we pass a bit length parameter from the calling function.
490
+  unsigned long ret_val=0; // We'll return this to generalize this function
491
+  // for both read and write of registers.
492
+  byte byte_len = bit_len/8; // How many BYTES do we have?
493
+  if (bit_len%8 > 0) byte_len++; // Make sure not to lose any partial byte values.
494
+  // Let's make sure our value has no spurious bits set, and if the value was too
495
+  // high, max it out.
496
+  unsigned long mask = 0xffffffff >> (32-bit_len);
497
+  if (value > mask) value = mask;
498
+  // The following three if statements handle the various possible byte length
499
+  // transfers- it'll be no less than 1 but no more than 3 bytes of data.
500
+  // L6470::Xfer() sends a byte out through SPI and returns a byte received
501
+  // over SPI- when calling it, we typecast a shifted version of the masked
502
+  // value, then we shift the received value back by the same amount and
503
+  // store it until return time.
504
+  if (byte_len == 3) {
505
+    ret_val |= long(Xfer((byte)(value>>16))) << 16;
506
+    //Serial.println(ret_val, HEX);
507
+  }
508
+  if (byte_len >= 2) {
509
+    ret_val |= long(Xfer((byte)(value>>8))) << 8;
510
+    //Serial.println(ret_val, HEX);
511
+  }
512
+  if (byte_len >= 1) {
513
+    ret_val |= Xfer((byte)value);
514
+    //Serial.println(ret_val, HEX);
515
+  }
516
+  // Return the received values. Mask off any unnecessary bits, just for
517
+  // the sake of thoroughness- we don't EXPECT to see anything outside
518
+  // the bit length range but better to be safe than sorry.
519
+  return (ret_val & mask);
520
+}
521
+
522
+byte L6470::Xfer(byte data){
523
+  // This simple function shifts a byte out over SPI and receives a byte over
524
+  // SPI. Unusually for SPI devices, the dSPIN requires a toggling of the
525
+  // CS (slaveSelect) pin after each byte sent. That makes this function
526
+  // a bit more reasonable, because we can include more functionality in it.
527
+  byte data_out;
528
+  digitalWrite(_SSPin,LOW);
529
+  // SPI.transfer() both shifts a byte out on the MOSI pin AND receives a
530
+  // byte in on the MISO pin.
531
+  data_out = SPI.transfer(data);
532
+  digitalWrite(_SSPin,HIGH);
533
+  return data_out;
534
+}
535
+
536
+
537
+
538
+void L6470::SetParam(byte param, unsigned long value){
539
+  Xfer(SET_PARAM | param);
540
+  ParamHandler(param, value);
541
+}
542
+
543
+unsigned long L6470::GetParam(byte param){
544
+  // Realize the "get parameter" function, to read from the various registers in
545
+  // the dSPIN chip.
546
+  Xfer(GET_PARAM | param);
547
+  return ParamHandler(param, 0);
548
+}
549
+
550
+long L6470::convert(unsigned long val){
551
+  //convert 22bit 2s comp to signed long
552
+  int MSB = val >> 21;
553
+  
554
+  val = val << 11;
555
+  val = val >> 11;
556
+  
557
+  if(MSB == 1) val = val | 0b11111111111000000000000000000000;
558
+  return val;
559
+}
560
+
561
+unsigned long L6470::ParamHandler(byte param, unsigned long value){
562
+  // Much of the functionality between "get parameter" and "set parameter" is
563
+  // very similar, so we deal with that by putting all of it in one function
564
+  // here to save memory space and simplify the program.
565
+  unsigned long ret_val = 0; // This is a temp for the value to return.
566
+  // This switch structure handles the appropriate action for each register.
567
+  // This is necessary since not all registers are of the same length, either
568
+  // bit-wise or byte-wise, so we want to make sure we mask out any spurious
569
+  // bits and do the right number of transfers. That is handled by the dSPIN_Param()
570
+  // function, in most cases, but for 1-byte or smaller transfers, we call
571
+  // Xfer() directly.
572
+  switch (param)
573
+  {
574
+    // ABS_POS is the current absolute offset from home. It is a 22 bit number expressed
575
+    // in two's complement. At power up, this value is 0. It cannot be written when
576
+    // the motor is running, but at any other time, it can be updated to change the
577
+    // interpreted position of the motor.
578
+    case ABS_POS:
579
+      ret_val = Param(value, 22);
580
+      break;
581
+    // EL_POS is the current electrical position in the step generation cycle. It can
582
+    // be set when the motor is not in motion. Value is 0 on power up.
583
+    case EL_POS:
584
+      ret_val = Param(value, 9);
585
+      break;
586
+    // MARK is a second position other than 0 that the motor can be told to go to. As
587
+    // with ABS_POS, it is 22-bit two's complement. Value is 0 on power up.
588
+    case MARK:
589
+      ret_val = Param(value, 22);
590
+      break;
591
+    // SPEED contains information about the current speed. It is read-only. It does
592
+    // NOT provide direction information.
593
+    case SPEED:
594
+      ret_val = Param(0, 20);
595
+      break;
596
+    // ACC and DEC set the acceleration and deceleration rates. Set ACC to 0xFFF
597
+    // to get infinite acceleration/decelaeration- there is no way to get infinite
598
+    // deceleration w/o infinite acceleration (except the HARD STOP command).
599
+    // Cannot be written while motor is running. Both default to 0x08A on power up.
600
+    // AccCalc() and DecCalc() functions exist to convert steps/s/s values into
601
+    // 12-bit values for these two registers.
602
+    case ACC:
603
+      ret_val = Param(value, 12);
604
+      break;
605
+    case DEC:
606
+      ret_val = Param(value, 12);
607
+      break;
608
+    // MAX_SPEED is just what it says- any command which attempts to set the speed
609
+    // of the motor above this value will simply cause the motor to turn at this
610
+    // speed. Value is 0x041 on power up.
611
+    // MaxSpdCalc() function exists to convert steps/s value into a 10-bit value
612
+    // for this register.
613
+    case MAX_SPEED:
614
+      ret_val = Param(value, 10);
615
+      break;
616
+    // MIN_SPEED controls two things- the activation of the low-speed optimization
617
+    // feature and the lowest speed the motor will be allowed to operate at. LSPD_OPT
618
+    // is the 13th bit, and when it is set, the minimum allowed speed is automatically
619
+    // set to zero. This value is 0 on startup.
620
+    // MinSpdCalc() function exists to convert steps/s value into a 12-bit value for this
621
+    // register. SetLowSpeedOpt() function exists to enable/disable the optimization feature.
622
+    case MIN_SPEED:
623
+      ret_val = Param(value, 12);
624
+      break;
625
+    // FS_SPD register contains a threshold value above which microstepping is disabled
626
+    // and the dSPIN operates in full-step mode. Defaults to 0x027 on power up.
627
+    // FSCalc() function exists to convert steps/s value into 10-bit integer for this
628
+    // register.
629
+    case FS_SPD:
630
+      ret_val = Param(value, 10);
631
+      break;
632
+    // KVAL is the maximum voltage of the PWM outputs. These 8-bit values are ratiometric
633
+    // representations: 255 for full output voltage, 128 for half, etc. Default is 0x29.
634
+    // The implications of different KVAL settings is too complex to dig into here, but
635
+    // it will usually work to max the value for RUN, ACC, and DEC. Maxing the value for
636
+    // HOLD may result in excessive power dissipation when the motor is not running.
637
+    case KVAL_HOLD:
638
+      ret_val = Xfer((byte)value);
639
+      break;
640
+    case KVAL_RUN:
641
+      ret_val = Xfer((byte)value);
642
+      break;
643
+    case KVAL_ACC:
644
+      ret_val = Xfer((byte)value);
645
+      break;
646
+    case KVAL_DEC:
647
+      ret_val = Xfer((byte)value);
648
+      break;
649
+    // INT_SPD, ST_SLP, FN_SLP_ACC and FN_SLP_DEC are all related to the back EMF
650
+    // compensation functionality. Please see the datasheet for details of this
651
+    // function- it is too complex to discuss here. Default values seem to work
652
+    // well enough.
653
+    case INT_SPD:
654
+      ret_val = Param(value, 14);
655
+      break;
656
+    case ST_SLP:
657
+      ret_val = Xfer((byte)value);
658
+      break;
659
+    case FN_SLP_ACC:
660
+      ret_val = Xfer((byte)value);
661
+      break;
662
+    case FN_SLP_DEC:
663
+      ret_val = Xfer((byte)value);
664
+      break;
665
+    // K_THERM is motor winding thermal drift compensation. Please see the datasheet
666
+    // for full details on operation- the default value should be okay for most users.
667
+    case K_THERM:
668
+      ret_val = Xfer((byte)value & 0x0F);
669
+      break;
670
+    // ADC_OUT is a read-only register containing the result of the ADC measurements.
671
+    // This is less useful than it sounds; see the datasheet for more information.
672
+    case ADC_OUT:
673
+      ret_val = Xfer(0);
674
+      break;
675
+    // Set the overcurrent threshold. Ranges from 375mA to 6A in steps of 375mA.
676
+    // A set of defined constants is provided for the user's convenience. Default
677
+    // value is 3.375A- 0x08. This is a 4-bit value.
678
+    case OCD_TH:
679
+      ret_val = Xfer((byte)value & 0x0F);
680
+      break;
681
+    // Stall current threshold. Defaults to 0x40, or 2.03A. Value is from 31.25mA to
682
+    // 4A in 31.25mA steps. This is a 7-bit value.
683
+    case STALL_TH:
684
+      ret_val = Xfer((byte)value & 0x7F);
685
+      break;
686
+    // STEP_MODE controls the microstepping settings, as well as the generation of an
687
+    // output signal from the dSPIN. Bits 2:0 control the number of microsteps per
688
+    // step the part will generate. Bit 7 controls whether the BUSY/SYNC pin outputs
689
+    // a BUSY signal or a step synchronization signal. Bits 6:4 control the frequency
690
+    // of the output signal relative to the full-step frequency; see datasheet for
691
+    // that relationship as it is too complex to reproduce here.
692
+    // Most likely, only the microsteps per step value will be needed; there is a set
693
+    // of constants provided for ease of use of these values.
694
+    case STEP_MODE:
695
+      ret_val = Xfer((byte)value);
696
+      break;
697
+    // ALARM_EN controls which alarms will cause the FLAG pin to fall. A set of constants
698
+    // is provided to make this easy to interpret. By default, ALL alarms will trigger the
699
+    // FLAG pin.
700
+    case ALARM_EN:
701
+      ret_val = Xfer((byte)value);
702
+      break;
703
+    // CONFIG contains some assorted configuration bits and fields. A fairly comprehensive
704
+    // set of reasonably self-explanatory constants is provided, but users should refer
705
+    // to the datasheet before modifying the contents of this register to be certain they
706
+    // understand the implications of their modifications. Value on boot is 0x2E88; this
707
+    // can be a useful way to verify proper start up and operation of the dSPIN chip.
708
+    case CONFIG:
709
+      ret_val = Param(value, 16);
710
+      break;
711
+      // STATUS contains read-only information about the current condition of the chip. A
712
+      // comprehensive set of constants for masking and testing this register is provided, but
713
+      // users should refer to the datasheet to ensure that they fully understand each one of
714
+      // the bits in the register.
715
+    case STATUS: // STATUS is a read-only register
716
+      ret_val = Param(0, 16);
717
+      break;
718
+    default:
719
+      ret_val = Xfer((byte)(value));
720
+    break;
721
+  }
722
+  return ret_val;
723
+}

+ 286
- 0
ArduinoAddons/Arduino_1.x.x/libraries/L6470/L6470.h Просмотреть файл

@@ -0,0 +1,286 @@
1
+////////////////////////////////////////////////////////////
2
+//ORIGINAL CODE 12/12/2011- Mike Hord, SparkFun Electronics
3
+//LIBRARY Created by Adam Meyer of bildr Aug 18th 2012
4
+//Released as MIT license
5
+////////////////////////////////////////////////////////////
6
+#ifndef L6470_h
7
+#define L6470_h
8
+
9
+#include <Arduino.h>
10
+#include <SPI.h>
11
+
12
+#define SLAVE_SELECT_PIN 38 // Wire this to the CSN pin
13
+// #define RESET 6 // Wire this to the STBY line
14
+#define BUSYN 7 // Wire this to the BSYN line
15
+
16
+// constant definitions for overcurrent thresholds. Write these values to
17
+// register dSPIN_OCD_TH to set the level at which an overcurrent even occurs.
18
+#define OCD_TH_375mA 0x00
19
+#define OCD_TH_750mA 0x01
20
+#define OCD_TH_1125mA 0x02
21
+#define OCD_TH_1500mA 0x03
22
+#define OCD_TH_1875mA 0x04
23
+#define OCD_TH_2250mA 0x05
24
+#define OCD_TH_2625mA 0x06
25
+#define OCD_TH_3000mA 0x07
26
+#define OCD_TH_3375mA 0x08
27
+#define OCD_TH_3750mA 0x09
28
+#define OCD_TH_4125mA 0x0A
29
+#define OCD_TH_4500mA 0x0B
30
+#define OCD_TH_4875mA 0x0C
31
+#define OCD_TH_5250mA 0x0D
32
+#define OCD_TH_5625mA 0x0E
33
+#define OCD_TH_6000mA 0x0F
34
+
35
+// STEP_MODE option values.
36
+// First comes the "microsteps per step" options...
37
+#define STEP_MODE_STEP_SEL 0x07 // Mask for these bits only.
38
+#define STEP_SEL_1 0x00
39
+#define STEP_SEL_1_2 0x01
40
+#define STEP_SEL_1_4 0x02
41
+#define STEP_SEL_1_8 0x03
42
+#define STEP_SEL_1_16 0x04
43
+#define STEP_SEL_1_32 0x05
44
+#define STEP_SEL_1_64 0x06
45
+#define STEP_SEL_1_128 0x07
46
+
47
+// ...next, define the SYNC_EN bit. When set, the BUSYN pin will instead
48
+// output a clock related to the full-step frequency as defined by the
49
+// SYNC_SEL bits below.
50
+#define STEP_MODE_SYNC_EN 0x80 // Mask for this bit
51
+#define SYNC_EN 0x80
52
+
53
+// ...last, define the SYNC_SEL modes. The clock output is defined by
54
+// the full-step frequency and the value in these bits- see the datasheet
55
+// for a matrix describing that relationship (page 46).
56
+#define STEP_MODE_SYNC_SEL 0x70
57
+#define SYNC_SEL_1_2 0x00
58
+#define SYNC_SEL_1 0x10
59
+#define SYNC_SEL_2 0x20
60
+#define SYNC_SEL_4 0x30
61
+#define SYNC_SEL_8 0x40
62
+#define SYNC_SEL_16 0x50
63
+#define SYNC_SEL_32 0x60
64
+#define SYNC_SEL_64 0x70
65
+
66
+// Bit names for the ALARM_EN register.
67
+// Each of these bits defines one potential alarm condition.
68
+// When one of these conditions occurs and the respective bit in ALARM_EN is set,
69
+// the FLAG pin will go low. The register must be queried to determine which event
70
+// caused the alarm.
71
+#define ALARM_EN_OVERCURRENT 0x01
72
+#define ALARM_EN_THERMAL_SHUTDOWN 0x02
73
+#define ALARM_EN_THERMAL_WARNING 0x04
74
+#define ALARM_EN_UNDER_VOLTAGE 0x08
75
+#define ALARM_EN_STALL_DET_A 0x10
76
+#define ALARM_EN_STALL_DET_B 0x20
77
+#define ALARM_EN_SW_TURN_ON 0x40
78
+#define ALARM_EN_WRONG_NPERF_CMD 0x80
79
+
80
+// CONFIG register renames.
81
+
82
+// Oscillator options.
83
+// The dSPIN needs to know what the clock frequency is because it uses that for some
84
+// calculations during operation.
85
+#define CONFIG_OSC_SEL 0x000F // Mask for this bit field.
86
+#define CONFIG_INT_16MHZ 0x0000 // Internal 16MHz, no output
87
+#define CONFIG_INT_16MHZ_OSCOUT_2MHZ 0x0008 // Default; internal 16MHz, 2MHz output
88
+#define CONFIG_INT_16MHZ_OSCOUT_4MHZ 0x0009 // Internal 16MHz, 4MHz output
89
+#define CONFIG_INT_16MHZ_OSCOUT_8MHZ 0x000A // Internal 16MHz, 8MHz output
90
+#define CONFIG_INT_16MHZ_OSCOUT_16MHZ 0x000B // Internal 16MHz, 16MHz output
91
+#define CONFIG_EXT_8MHZ_XTAL_DRIVE 0x0004 // External 8MHz crystal
92
+#define CONFIG_EXT_16MHZ_XTAL_DRIVE 0x0005 // External 16MHz crystal
93
+#define CONFIG_EXT_24MHZ_XTAL_DRIVE 0x0006 // External 24MHz crystal
94
+#define CONFIG_EXT_32MHZ_XTAL_DRIVE 0x0007 // External 32MHz crystal
95
+#define CONFIG_EXT_8MHZ_OSCOUT_INVERT 0x000C // External 8MHz crystal, output inverted
96
+#define CONFIG_EXT_16MHZ_OSCOUT_INVERT 0x000D // External 16MHz crystal, output inverted
97
+#define CONFIG_EXT_24MHZ_OSCOUT_INVERT 0x000E // External 24MHz crystal, output inverted
98
+#define CONFIG_EXT_32MHZ_OSCOUT_INVERT 0x000F // External 32MHz crystal, output inverted
99
+
100
+// Configure the functionality of the external switch input
101
+#define CONFIG_SW_MODE 0x0010 // Mask for this bit.
102
+#define CONFIG_SW_HARD_STOP 0x0000 // Default; hard stop motor on switch.
103
+#define CONFIG_SW_USER 0x0010 // Tie to the GoUntil and ReleaseSW
104
+                                                    // commands to provide jog function.
105
+                                                    // See page 25 of datasheet.
106
+
107
+// Configure the motor voltage compensation mode (see page 34 of datasheet)
108
+#define CONFIG_EN_VSCOMP 0x0020 // Mask for this bit.
109
+#define CONFIG_VS_COMP_DISABLE 0x0000 // Disable motor voltage compensation.
110
+#define CONFIG_VS_COMP_ENABLE 0x0020 // Enable motor voltage compensation.
111
+
112
+// Configure overcurrent detection event handling
113
+#define CONFIG_OC_SD 0x0080 // Mask for this bit.
114
+#define CONFIG_OC_SD_DISABLE 0x0000 // Bridges do NOT shutdown on OC detect
115
+#define CONFIG_OC_SD_ENABLE 0x0080 // Bridges shutdown on OC detect
116
+
117
+// Configure the slew rate of the power bridge output
118
+#define CONFIG_POW_SR 0x0300 // Mask for this bit field.
119
+#define CONFIG_SR_180V_us 0x0000 // 180V/us
120
+#define CONFIG_SR_290V_us 0x0200 // 290V/us
121
+#define CONFIG_SR_530V_us 0x0300 // 530V/us
122
+
123
+// Integer divisors for PWM sinewave generation
124
+// See page 32 of the datasheet for more information on this.
125
+#define CONFIG_F_PWM_DEC 0x1C00 // mask for this bit field
126
+#define CONFIG_PWM_MUL_0_625 (0x00)<<10
127
+#define CONFIG_PWM_MUL_0_75 (0x01)<<10
128
+#define CONFIG_PWM_MUL_0_875 (0x02)<<10
129
+#define CONFIG_PWM_MUL_1 (0x03)<<10
130
+#define CONFIG_PWM_MUL_1_25 (0x04)<<10
131
+#define CONFIG_PWM_MUL_1_5 (0x05)<<10
132
+#define CONFIG_PWM_MUL_1_75 (0x06)<<10
133
+#define CONFIG_PWM_MUL_2 (0x07)<<10
134
+
135
+// Multiplier for the PWM sinewave frequency
136
+#define CONFIG_F_PWM_INT 0xE000 // mask for this bit field.
137
+#define CONFIG_PWM_DIV_1 (0x00)<<13
138
+#define CONFIG_PWM_DIV_2 (0x01)<<13
139
+#define CONFIG_PWM_DIV_3 (0x02)<<13
140
+#define CONFIG_PWM_DIV_4 (0x03)<<13
141
+#define CONFIG_PWM_DIV_5 (0x04)<<13
142
+#define CONFIG_PWM_DIV_6 (0x05)<<13
143
+#define CONFIG_PWM_DIV_7 (0x06)<<13
144
+
145
+// Status register bit renames- read-only bits conferring information about the
146
+// device to the user.
147
+#define STATUS_HIZ 0x0001 // high when bridges are in HiZ mode
148
+#define STATUS_BUSY 0x0002 // mirrors BUSY pin
149
+#define STATUS_SW_F 0x0004 // low when switch open, high when closed
150
+#define STATUS_SW_EVN 0x0008 // active high, set on switch falling edge,
151
+                                                    // cleared by reading STATUS
152
+#define STATUS_DIR 0x0010 // Indicates current motor direction.
153
+                                                    // High is FWD, Low is REV.
154
+#define STATUS_NOTPERF_CMD 0x0080 // Last command not performed.
155
+#define STATUS_WRONG_CMD 0x0100 // Last command not valid.
156
+#define STATUS_UVLO 0x0200 // Undervoltage lockout is active
157
+#define STATUS_TH_WRN 0x0400 // Thermal warning
158
+#define STATUS_TH_SD 0x0800 // Thermal shutdown
159
+#define STATUS_OCD 0x1000 // Overcurrent detected
160
+#define STATUS_STEP_LOSS_A 0x2000 // Stall detected on A bridge
161
+#define STATUS_STEP_LOSS_B 0x4000 // Stall detected on B bridge
162
+#define STATUS_SCK_MOD 0x8000 // Step clock mode is active
163
+
164
+// Status register motor status field
165
+#define STATUS_MOT_STATUS 0x0060 // field mask
166
+#define STATUS_MOT_STATUS_STOPPED (0x0000)<<13 // Motor stopped
167
+#define STATUS_MOT_STATUS_ACCELERATION (0x0001)<<13 // Motor accelerating
168
+#define STATUS_MOT_STATUS_DECELERATION (0x0002)<<13 // Motor decelerating
169
+#define STATUS_MOT_STATUS_CONST_SPD (0x0003)<<13 // Motor at constant speed
170
+
171
+// Register address redefines.
172
+// See the Param_Handler() function for more info about these.
173
+#define ABS_POS 0x01
174
+#define EL_POS 0x02
175
+#define MARK 0x03
176
+#define SPEED 0x04
177
+#define ACC 0x05
178
+#define DEC 0x06
179
+#define MAX_SPEED 0x07
180
+#define MIN_SPEED 0x08
181
+#define FS_SPD 0x15
182
+#define KVAL_HOLD 0x09
183
+#define KVAL_RUN 0x0A
184
+#define KVAL_ACC 0x0B
185
+#define KVAL_DEC 0x0C
186
+#define INT_SPD 0x0D
187
+#define ST_SLP 0x0E
188
+#define FN_SLP_ACC 0x0F
189
+#define FN_SLP_DEC 0x10
190
+#define K_THERM 0x11
191
+#define ADC_OUT 0x12
192
+#define OCD_TH 0x13
193
+#define STALL_TH 0x14
194
+#define STEP_MODE 0x16
195
+#define ALARM_EN 0x17
196
+#define CONFIG 0x18
197
+#define STATUS 0x19
198
+
199
+//dSPIN commands
200
+#define NOP 0x00
201
+#define SET_PARAM 0x00
202
+#define GET_PARAM 0x20
203
+#define RUN 0x50
204
+#define STEP_CLOCK 0x58
205
+#define MOVE 0x40
206
+#define GOTO 0x60
207
+#define GOTO_DIR 0x68
208
+#define GO_UNTIL 0x82
209
+#define RELEASE_SW 0x92
210
+#define GO_HOME 0x70
211
+#define GO_MARK 0x78
212
+#define RESET_POS 0xD8
213
+#define RESET_DEVICE 0xC0
214
+#define SOFT_STOP 0xB0
215
+#define HARD_STOP 0xB8
216
+#define SOFT_HIZ 0xA0
217
+#define HARD_HIZ 0xA8
218
+#define GET_STATUS 0xD0
219
+
220
+/* dSPIN direction options */
221
+#define FWD 0x01
222
+#define REV 0x00
223
+
224
+/* dSPIN action options */
225
+#define ACTION_RESET 0x00
226
+#define ACTION_COPY 0x01
227
+
228
+
229
+class L6470{
230
+
231
+  public:
232
+
233
+    L6470(int SSPin);
234
+    void init(int k_value);
235
+    void setMicroSteps(int microSteps);
236
+    void setCurrent(int current);
237
+    void setMaxSpeed(int speed);
238
+    void setMinSpeed(int speed);
239
+    void setAcc(float acceleration);
240
+    void setDec(float deceleration);
241
+    void setOverCurrent(unsigned int ma_current);
242
+    void setThresholdSpeed(float threshold);
243
+    void setStallCurrent(float ma_current);
244
+    
245
+    unsigned long ParamHandler(byte param, unsigned long value);
246
+    void SetLowSpeedOpt(boolean enable);
247
+    void run(byte dir, float spd);
248
+    void Step_Clock(byte dir);
249
+    void goHome();
250
+    void setAsHome();
251
+    void goMark();
252
+    void move(long n_step);
253
+    void goTo(long pos);
254
+    void goTo_DIR(byte dir, long pos);
255
+    void goUntil(byte act, byte dir, unsigned long spd);
256
+    boolean isBusy();
257
+    void releaseSW(byte act, byte dir);
258
+    float getSpeed();
259
+    long getPos();
260
+    void setMark();
261
+    void setMark(long value);
262
+    void resetPos();
263
+    void resetDev();
264
+    void softStop();
265
+    void hardStop();
266
+    void softFree();
267
+    void free();
268
+    int getStatus();
269
+	void SetParam(byte param, unsigned long value);
270
+
271
+  private:
272
+    long convert(unsigned long val);
273
+    unsigned long GetParam(byte param);
274
+    unsigned long AccCalc(float stepsPerSecPerSec);
275
+    unsigned long DecCalc(float stepsPerSecPerSec);
276
+    unsigned long MaxSpdCalc(float stepsPerSec);
277
+    unsigned long MinSpdCalc(float stepsPerSec);
278
+    unsigned long FSCalc(float stepsPerSec);
279
+    unsigned long IntSpdCalc(float stepsPerSec);
280
+    unsigned long SpdCalc(float stepsPerSec);
281
+    unsigned long Param(unsigned long value, byte bit_len);
282
+    byte Xfer(byte data);
283
+    int _SSPin;
284
+};
285
+
286
+#endif

+ 53
- 0
ArduinoAddons/Arduino_1.x.x/libraries/L6470/keywords.txt Просмотреть файл

@@ -0,0 +1,53 @@
1
+#######################################################
2
+# keywords.txt - keywords file for the L6470 library
3
+#
4
+# ORIGINAL CODE 12/12/2011- Mike Hord, SparkFun Electronics
5
+# Library by Adam Meyer of bildr Aug 18th 2012
6
+#
7
+# Released as MIT license
8
+#######################################################
9
+
10
+#######################################
11
+# Datatypes (KEYWORD1)
12
+#######################################
13
+
14
+L6470 KEYWORD1
15
+
16
+#######################################
17
+# Methods and Functions (KEYWORD2)
18
+#######################################
19
+
20
+L6470 				KEYWORD2
21
+init 				KEYWORD2
22
+setMicroSteps 		KEYWORD2
23
+setCurrent 			KEYWORD2
24
+setMaxSpeed 		KEYWORD2
25
+setMinSpeed 		KEYWORD2
26
+setAcc 				KEYWORD2
27
+setDec 				KEYWORD2
28
+setOverCurrent 		KEYWORD2
29
+setThresholdSpeed 	KEYWORD2
30
+setStallCurrent 	KEYWORD2
31
+ParamHandler 		KEYWORD2
32
+SetLowSpeedOpt 		KEYWORD2
33
+run 				KEYWORD2
34
+Step_Clock 			KEYWORD2
35
+goHome 				KEYWORD2
36
+goMark 				KEYWORD2
37
+move 				KEYWORD2
38
+goTo 				KEYWORD2
39
+goTo_DIR 			KEYWORD2
40
+goUntil 			KEYWORD2
41
+isBusy 				KEYWORD2
42
+releaseSW 			KEYWORD2
43
+resetPos			KEYWORD2
44
+resetDev 			KEYWORD2
45
+softStop			KEYWORD2
46
+hardStop 			KEYWORD2
47
+softHiZ 			KEYWORD2
48
+hardHiZ 			KEYWORD2
49
+getStatus 			KEYWORD2
50
+
51
+#######################################
52
+# Constants (LITERAL1)
53
+#######################################

+ 90
- 16
Marlin/Configuration_adv.h Просмотреть файл

@@ -467,61 +467,135 @@ const unsigned int dropsegments=5; //everything with less than this number of st
467 467
  * you need to import the TMC26XStepper library into the arduino IDE for this
468 468
  ******************************************************************************/
469 469
 
470
-#define HAVE_TMCDRIVER
470
+//#define HAVE_TMCDRIVER
471 471
 #ifdef HAVE_TMCDRIVER
472 472
 
473
-	#define X_IS_TMC
474
-	#define X_MAX_CURRENT 2000  //in mA
473
+//	#define X_IS_TMC
474
+	#define X_MAX_CURRENT 1000  //in mA
475 475
 	#define X_SENSE_RESISTOR 91 //in mOhms
476 476
 	#define X_MICROSTEPS 16     //number of microsteps
477 477
 	
478 478
 //	#define X2_IS_TMC
479
-	#define X2_MAX_CURRENT 2000  //in mA
479
+	#define X2_MAX_CURRENT 1000  //in mA
480 480
 	#define X2_SENSE_RESISTOR 91 //in mOhms
481 481
 	#define X2_MICROSTEPS 16     //number of microsteps
482 482
 	
483
-	#define Y_IS_TMC
484
-	#define Y_MAX_CURRENT 2000  //in mA
483
+//	#define Y_IS_TMC
484
+	#define Y_MAX_CURRENT 1000  //in mA
485 485
 	#define Y_SENSE_RESISTOR 91 //in mOhms
486 486
 	#define Y_MICROSTEPS 16     //number of microsteps
487 487
 	
488 488
 //	#define Y2_IS_TMC
489
-	#define Y2_MAX_CURRENT 2000  //in mA
489
+	#define Y2_MAX_CURRENT 1000  //in mA
490 490
 	#define Y2_SENSE_RESISTOR 91 //in mOhms
491 491
 	#define Y2_MICROSTEPS 16     //number of microsteps	
492 492
 	
493
-	#define Z_IS_TMC
494
-	#define Z_MAX_CURRENT 2000  //in mA
493
+//	#define Z_IS_TMC
494
+	#define Z_MAX_CURRENT 1000  //in mA
495 495
 	#define Z_SENSE_RESISTOR 91 //in mOhms
496 496
 	#define Z_MICROSTEPS 16     //number of microsteps
497 497
 	
498 498
 //	#define Z2_IS_TMC
499
-	#define Z2_MAX_CURRENT 2000  //in mA
499
+	#define Z2_MAX_CURRENT 1000  //in mA
500 500
 	#define Z2_SENSE_RESISTOR 91 //in mOhms
501 501
 	#define Z2_MICROSTEPS 16     //number of microsteps
502 502
 	
503
-	#define E0_IS_TMC
504
-	#define E0_MAX_CURRENT 2000  //in mA
503
+//	#define E0_IS_TMC
504
+	#define E0_MAX_CURRENT 1000  //in mA
505 505
 	#define E0_SENSE_RESISTOR 91 //in mOhms
506 506
 	#define E0_MICROSTEPS 16     //number of microsteps
507 507
 	
508
-	#define E1_IS_TMC
509
-	#define E1_MAX_CURRENT 2000  //in mA
508
+//	#define E1_IS_TMC
509
+	#define E1_MAX_CURRENT 1000  //in mA
510 510
 	#define E1_SENSE_RESISTOR 91 //in mOhms
511 511
 	#define E1_MICROSTEPS 16     //number of microsteps	
512 512
 	
513 513
 //	#define E2_IS_TMC
514
-	#define E2_MAX_CURRENT 2000  //in mA
514
+	#define E2_MAX_CURRENT 1000  //in mA
515 515
 	#define E2_SENSE_RESISTOR 91 //in mOhms
516 516
 	#define E2_MICROSTEPS 16     //number of microsteps	
517 517
 	
518 518
 //	#define E3_IS_TMC
519
-	#define E3_MAX_CURRENT 2000  //in mA
519
+	#define E3_MAX_CURRENT 1000  //in mA
520 520
 	#define E3_SENSE_RESISTOR 91 //in mOhms
521 521
 	#define E3_MICROSTEPS 16     //number of microsteps		
522 522
 
523 523
 #endif
524 524
 
525
+/******************************************************************************\
526
+ * enable this section if you have L6470  motor drivers. 
527
+ * you need to import the L6470 library into the arduino IDE for this
528
+ ******************************************************************************/
529
+
530
+//#define HAVE_L6470DRIVER
531
+#ifdef HAVE_L6470DRIVER
532
+
533
+//	#define X_IS_L6470
534
+	#define X_MICROSTEPS 16     //number of microsteps
535
+	#define X_K_VAL 50          // 0 - 255, Higher values, are higher power. Be carefull not to go too high    
536
+	#define X_OVERCURRENT 2000  //maxc current in mA. If the current goes over this value, the driver will switch off
537
+	#define X_STALLCURRENT 1500 //current in mA where the driver will detect a stall
538
+	
539
+//	#define X2_IS_L6470
540
+	#define X2_MICROSTEPS 16     //number of microsteps
541
+	#define X2_K_VAL 50          // 0 - 255, Higher values, are higher power. Be carefull not to go too high    
542
+	#define X2_OVERCURRENT 2000  //maxc current in mA. If the current goes over this value, the driver will switch off
543
+	#define X2_STALLCURRENT 1500 //current in mA where the driver will detect a stall
544
+	
545
+//	#define Y_IS_L6470
546
+	#define Y_MICROSTEPS 16     //number of microsteps
547
+	#define Y_K_VAL 50          // 0 - 255, Higher values, are higher power. Be carefull not to go too high    
548
+	#define Y_OVERCURRENT 2000  //maxc current in mA. If the current goes over this value, the driver will switch off
549
+	#define Y_STALLCURRENT 1500 //current in mA where the driver will detect a stall
550
+	
551
+//	#define Y2_IS_L6470
552
+	#define Y2_MICROSTEPS 16     //number of microsteps	
553
+	#define Y2_K_VAL 50          // 0 - 255, Higher values, are higher power. Be carefull not to go too high    
554
+	#define Y2_OVERCURRENT 2000  //maxc current in mA. If the current goes over this value, the driver will switch off
555
+	#define Y2_STALLCURRENT 1500 //current in mA where the driver will detect a stall	
556
+	
557
+//	#define Z_IS_L6470
558
+	#define Z_MICROSTEPS 16     //number of microsteps
559
+	#define Z_K_VAL 50          // 0 - 255, Higher values, are higher power. Be carefull not to go too high    
560
+	#define Z_OVERCURRENT 2000  //maxc current in mA. If the current goes over this value, the driver will switch off
561
+	#define Z_STALLCURRENT 1500 //current in mA where the driver will detect a stall
562
+	
563
+//	#define Z2_IS_L6470
564
+	#define Z2_MICROSTEPS 16     //number of microsteps
565
+	#define Z2_K_VAL 50          // 0 - 255, Higher values, are higher power. Be carefull not to go too high    
566
+	#define Z2_OVERCURRENT 2000  //maxc current in mA. If the current goes over this value, the driver will switch off
567
+	#define Z2_STALLCURRENT 1500 //current in mA where the driver will detect a stall
568
+	
569
+//	#define E0_IS_L6470
570
+	#define E0_MICROSTEPS 16     //number of microsteps
571
+	#define E0_K_VAL 50          // 0 - 255, Higher values, are higher power. Be carefull not to go too high    
572
+	#define E0_OVERCURRENT 2000  //maxc current in mA. If the current goes over this value, the driver will switch off
573
+	#define E0_STALLCURRENT 1500 //current in mA where the driver will detect a stall
574
+	
575
+//	#define E1_IS_L6470
576
+	#define E1_MICROSTEPS 16     //number of microsteps	
577
+	#define E1_MICROSTEPS 16     //number of microsteps
578
+	#define E1_K_VAL 50          // 0 - 255, Higher values, are higher power. Be carefull not to go too high    
579
+	#define E1_OVERCURRENT 2000  //maxc current in mA. If the current goes over this value, the driver will switch off
580
+	#define E1_STALLCURRENT 1500 //current in mA where the driver will detect a stall
581
+	
582
+//	#define E2_IS_L6470
583
+	#define E2_MICROSTEPS 16     //number of microsteps	
584
+	#define E2_MICROSTEPS 16     //number of microsteps
585
+	#define E2_K_VAL 50          // 0 - 255, Higher values, are higher power. Be carefull not to go too high    
586
+	#define E2_OVERCURRENT 2000  //maxc current in mA. If the current goes over this value, the driver will switch off
587
+	#define E2_STALLCURRENT 1500 //current in mA where the driver will detect a stall
588
+	
589
+//	#define E3_IS_L6470
590
+	#define E3_MICROSTEPS 16     //number of microsteps		
591
+	#define E3_MICROSTEPS 16     //number of microsteps
592
+	#define E3_K_VAL 50          // 0 - 255, Higher values, are higher power. Be carefull not to go too high    
593
+	#define E3_OVERCURRENT 2000  //maxc current in mA. If the current goes over this value, the driver will switch off
594
+	#define E3_STALLCURRENT 1500 //current in mA where the driver will detect a stall
595
+	
596
+#endif
597
+
598
+
525 599
 //===========================================================================
526 600
 //=============================  Define Defines  ============================
527 601
 //===========================================================================

+ 5
- 0
Marlin/Marlin.ino Просмотреть файл

@@ -59,3 +59,8 @@
59 59
   #include <SPI.h>
60 60
   #include <TMC26XStepper.h>
61 61
 #endif
62
+
63
+#ifdef HAVE_L6470DRIVER
64
+  #include <SPI.h>
65
+  #include <L6470.h>
66
+#endif

+ 5
- 0
Marlin/stepper.cpp Просмотреть файл

@@ -842,6 +842,11 @@ void st_init()
842 842
   #ifdef HAVE_TMCDRIVER
843 843
      tmc_init();
844 844
   #endif
845
+    // initialise L6470 Steppers
846
+  #ifdef HAVE_L6470DRIVER
847
+     L6470_init();
848
+  #endif
849
+  
845 850
   
846 851
   //Initialize Dir Pins
847 852
   #if defined(X_DIR_PIN) && X_DIR_PIN > -1

+ 119
- 1
Marlin/stepper_indirection.cpp Просмотреть файл

@@ -103,4 +103,122 @@ void tmc_init()
103 103
 	stepperE3.start();
104 104
 #endif
105 105
 }
106
-#endif
106
+#endif
107
+
108
+// L6470 Driver objects and inits
109
+
110
+#ifdef HAVE_L6470DRIVER
111
+#include <SPI.h>
112
+#include <L6470.h>
113
+#endif
114
+
115
+// L6470 Stepper objects
116
+#ifdef X_IS_L6470
117
+	L6470 stepperX(X_ENABLE_PIN);
118
+#endif
119
+#ifdef X2_IS_L6470
120
+	L6470 stepperX2(X2_ENABLE_PIN);
121
+#endif
122
+#ifdef Y_IS_L6470
123
+	L6470 stepperY(Y_ENABLE_PIN);
124
+#endif
125
+#ifdef Y2_IS_L6470
126
+	L6470 stepperY2(Y2_ENABLE_PIN);
127
+#endif
128
+#ifdef Z_IS_L6470
129
+	L6470 stepperZ(Z_ENABLE_PIN);
130
+#endif
131
+#ifdef Z2_IS_L6470
132
+	L6470 stepperZ2(Z2_ENABLE_PIN);
133
+#endif
134
+#ifdef E0_IS_L6470
135
+	L6470 stepperE0(E0_ENABLE_PIN);
136
+#endif
137
+#ifdef E1_IS_L6470
138
+	L6470 stepperE1(E1_ENABLE_PIN);
139
+#endif
140
+#ifdef E2_IS_L6470
141
+	L6470 stepperE2(E2_ENABLE_PIN);
142
+#endif
143
+#ifdef E3_IS_L6470
144
+	L6470 stepperE3(E3_ENABLE_PIN);
145
+#endif	
146
+
147
+
148
+// init routine
149
+#ifdef HAVE_L6470DRIVER
150
+void L6470_init()
151
+{
152
+#ifdef X_IS_L6470
153
+	stepperX.init(X_K_VAL);
154
+	stepperX.softFree();
155
+	stepperX.setMicroSteps(X_MICROSTEPS);
156
+    stepperX.setOverCurrent(X_OVERCURRENT); //set overcurrent protection
157
+    stepperX.setStallCurrent(X_STALLCURRENT);
158
+#endif
159
+#ifdef X2_IS_L6470
160
+	stepperX2.init(X2_K_VAL);
161
+	stepperX2.softFree();
162
+	stepperX2.setMicroSteps(X2_MICROSTEPS);
163
+    stepperX2.setOverCurrent(X2_OVERCURRENT); //set overcurrent protection
164
+    stepperX2.setStallCurrent(X2_STALLCURRENT);
165
+#endif
166
+#ifdef Y_IS_L6470
167
+	stepperY.init(Y_K_VAL);
168
+	stepperY.softFree();
169
+	stepperY.setMicroSteps(Y_MICROSTEPS);
170
+    stepperY.setOverCurrent(Y_OVERCURRENT); //set overcurrent protection
171
+    stepperY.setStallCurrent(Y_STALLCURRENT);
172
+#endif
173
+#ifdef Y2_IS_L6470
174
+	stepperY2.init(Y2_K_VAL);
175
+	stepperY2.softFree();
176
+	stepperY2.setMicroSteps(Y2_MICROSTEPS);
177
+    stepperY2.setOverCurrent(Y2_OVERCURRENT); //set overcurrent protection
178
+    stepperY2.setStallCurrent(Y2_STALLCURRENT);
179
+#endif
180
+#ifdef Z_IS_L6470
181
+	stepperZ.init(Z_K_VAL);
182
+	stepperZ.softFree();
183
+	stepperZ.setMicroSteps(Z_MICROSTEPS);
184
+    stepperZ.setOverCurrent(Z_OVERCURRENT); //set overcurrent protection
185
+    stepperZ.setStallCurrent(Z_STALLCURRENT);
186
+#endif
187
+#ifdef Z2_IS_L6470
188
+	stepperZ2.init(Z2_K_VAL);
189
+	stepperZ2.softFree();
190
+	stepperZ2.setMicroSteps(Z2_MICROSTEPS);
191
+    stepperZ2.setOverCurrent(Z2_OVERCURRENT); //set overcurrent protection
192
+    stepperZ2.setStallCurrent(Z2_STALLCURRENT);
193
+#endif
194
+#ifdef E0_IS_L6470
195
+	stepperE0.init(E0_K_VAL);
196
+	stepperE0.softFree();
197
+	stepperE0.setMicroSteps(E0_MICROSTEPS);
198
+    stepperE0.setOverCurrent(E0_OVERCURRENT); //set overcurrent protection
199
+    stepperE0.setStallCurrent(E0_STALLCURRENT);
200
+#endif
201
+#ifdef E1_IS_L6470
202
+	stepperE1.init(E1_K_VAL);
203
+	stepperE1.softFree();
204
+	stepperE1.setMicroSteps(E1_MICROSTEPS);
205
+    stepperE1.setOverCurrent(E1_OVERCURRENT); //set overcurrent protection
206
+    stepperE1.setStallCurrent(E1_STALLCURRENT);
207
+#endif
208
+#ifdef E2_IS_L6470
209
+	stepperE2.init(E2_K_VAL);
210
+	stepperE2.softFree();
211
+	stepperE2.setMicroSteps(E2_MICROSTEPS);
212
+    stepperE2.setOverCurrent(E2_OVERCURRENT); //set overcurrent protection
213
+    stepperE2.setStallCurrent(E2_STALLCURRENT);
214
+#endif
215
+#ifdef E3_IS_L6470
216
+	stepperE3.init(E3_K_VAL);
217
+	stepperE3.softFree();
218
+	stepperE3.setMicroSteps(E3_MICROSTEPS);
219
+    stepperE3.setOverCurrent(E3_OVERCURRENT); //set overcurrent protection
220
+    stepperE3.setStallCurrent(E3_STALLCURRENT);
221
+#endif	
222
+}
223
+#endif
224
+

+ 227
- 31
Marlin/stepper_indirection.h Просмотреть файл

@@ -160,38 +160,9 @@
160 160
 #include <SPI.h>
161 161
 #include <TMC26XStepper.h>
162 162
 
163
-#ifdef X_IS_TMC
164
-	extern TMC26XStepper stepperX;
165
-#endif
166
-#ifdef X2_IS_TMC
167
-	extern TMC26XStepper stepperX2;
168
-#endif
169
-#ifdef Y_IS_TMC
170
-	extern TMC26XStepper stepperY;
171
-#endif
172
-#ifdef Y2_IS_TMC
173
-	extern TMC26XStepper stepperY2;
174
-#endif
175
-#ifdef Z_IS_TMC
176
-	extern TMC26XStepper stepperZ;
177
-#endif
178
-#ifdef Z2_IS_TMC
179
-	extern TMC26XStepper stepperZ2;
180
-#endif
181
-#ifdef E0_IS_TMC
182
-	extern TMC26XStepper stepperE0;
183
-#endif
184
-#ifdef E1_IS_TMC
185
-	extern TMC26XStepper stepperE1;
186
-#endif
187
-#ifdef E2_IS_TMC
188
-	extern TMC26XStepper stepperE2;
189
-#endif
190
-#ifdef E3_IS_TMC
191
-	extern TMC26XStepper stepperE3;
192
-#endif	
193 163
   void tmc_init();
194 164
 #ifdef X_IS_TMC
165
+   extern TMC26XStepper stepperX;
195 166
    #undef X_ENABLE_INIT 
196 167
    #define X_ENABLE_INIT ((void)0)
197 168
    
@@ -200,8 +171,10 @@
200 171
    
201 172
    #undef X_ENABLE_READ
202 173
    #define X_ENABLE_READ stepperX.isEnabled()
174
+   
203 175
 #endif
204 176
 #ifdef X2_IS_TMC
177
+   extern TMC26XStepper stepperX2;
205 178
    #undef X2_ENABLE_INIT
206 179
    #define X2_ENABLE_INIT ((void)0)
207 180
    
@@ -212,6 +185,7 @@
212 185
    #define X2_ENABLE_READ stepperX2.isEnabled()   
213 186
 #endif
214 187
 #ifdef Y_IS_TMC
188
+   extern TMC26XStepper stepperY;
215 189
    #undef Y_ENABLE_INIT
216 190
    #define Y_ENABLE_INIT ((void)0)
217 191
    
@@ -222,6 +196,7 @@
222 196
    #define Y_ENABLE_READ stepperY.isEnabled()   
223 197
 #endif
224 198
 #ifdef Y2_IS_TMC
199
+   extern TMC26XStepper stepperY2;
225 200
    #undef Y2_ENABLE_INIT
226 201
    #define Y2_ENABLE_INIT ((void)0)
227 202
    
@@ -232,6 +207,7 @@
232 207
    #define Y2_ENABLE_READ stepperY2.isEnabled()     
233 208
 #endif
234 209
 #ifdef Z_IS_TMC
210
+   extern TMC26XStepper stepperZ;
235 211
    #undef Z_ENABLE_INIT
236 212
    #define Z_ENABLE_INIT ((void)0)
237 213
    
@@ -242,6 +218,7 @@
242 218
    #define Z_ENABLE_READ stepperZ.isEnabled()       
243 219
 #endif
244 220
 #ifdef Z2_IS_TMC
221
+   extern TMC26XStepper stepperZ2;
245 222
    #undef Z2_ENABLE_INIT
246 223
    #define Z2_ENABLE_INIT ((void)0)
247 224
    
@@ -252,6 +229,7 @@
252 229
    #define Z2_ENABLE_READ stepperZ2.isEnabled()   
253 230
 #endif
254 231
 #ifdef E0_IS_TMC
232
+   extern TMC26XStepper stepperE0;
255 233
    #undef E0_ENABLE_INIT
256 234
    #define E0_ENABLE_INIT ((void)0)
257 235
    
@@ -262,6 +240,7 @@
262 240
    #define E0_ENABLE_READ stepperE0.isEnabled()   
263 241
 #endif
264 242
 #ifdef E1_IS_TMC
243
+   extern TMC26XStepper stepperE1;
265 244
    #undef E1_ENABLE_INIT
266 245
    #define E1_ENABLE_INIT ((void)0)
267 246
    
@@ -272,6 +251,7 @@
272 251
    #define E1_ENABLE_READ stepperE1.isEnabled()   
273 252
 #endif
274 253
 #ifdef E2_IS_TMC
254
+   extern TMC26XStepper stepperE2;
275 255
    #undef E2_ENABLE_INIT
276 256
    #define E2_ENABLE_INIT ((void)0)
277 257
    
@@ -282,6 +262,7 @@
282 262
    #define E2_ENABLE_READ stepperE2.isEnabled()   
283 263
 #endif
284 264
 #ifdef E3_IS_TMC
265
+   extern TMC26XStepper stepperE3;
285 266
    #undef E3_ENABLE_INIT
286 267
    #define E3_ENABLE_INIT ((void)0)
287 268
    
@@ -291,6 +272,221 @@
291 272
    #undef E3_ENABLE_READ
292 273
    #define E3_ENABLE_READ stepperE3.isEnabled()   
293 274
 #endif
294
-#endif
295 275
 
276
+#endif  // HAVE_TMCDRIVER
277
+
278
+//////////////////////////////////
279
+// Pin redefines for L6470 drivers. 
280
+// L640 drivers have step on normal pins, but dir and everything else via SPI
281
+//////////////////////////////////
282
+#ifdef HAVE_L6470DRIVER
283
+
284
+#include <SPI.h>
285
+#include <L6470.h>
286
+
287
+  void L6470_init();
288
+#ifdef X_IS_L6470
289
+   extern L6470 stepperX;
290
+   #undef X_ENABLE_INIT 
291
+   #define X_ENABLE_INIT ((void)0)
292
+   
293
+   #undef X_ENABLE_WRITE
294
+   #define X_ENABLE_WRITE(STATE) {if(STATE) stepperX.Step_Clock(stepperX.getStatus() & STATUS_HIZ); else stepperX.softFree();}
295
+   
296
+   #undef X_ENABLE_READ
297
+   #define X_ENABLE_READ (stepperX.getStatus() & STATUS_HIZ)
298
+   
299
+   #undef X_DIR_INIT 
300
+   #define X_DIR_INIT ((void)0)
301
+   
302
+   #undef X_DIR_WRITE
303
+   #define X_DIR_WRITE(STATE) stepperX.Step_Clock(STATE)
304
+   
305
+   #undef X_DIR_READ
306
+   #define X_DIR_READ (stepperX.getStatus() & STATUS_DIR)
307
+   
308
+#endif
309
+#ifdef X2_IS_L6470
310
+   extern L6470 stepperX2;
311
+   #undef X2_ENABLE_INIT
312
+   #define X2_ENABLE_INIT ((void)0)
313
+   
314
+   #undef X2_ENABLE_WRITE
315
+   #define X2_ENABLE_WRITE(STATE) (if(STATE) stepperX2.Step_Clock(stepperX2.getStatus() & STATUS_HIZ); else stepperX2.softFree();)
316
+   
317
+   #undef X2_ENABLE_READ
318
+   #define X2_ENABLE_READ (stepperX2.getStatus() & STATUS_HIZ)
319
+   
320
+   #undef X2_DIR_INIT 
321
+   #define X2_DIR_INIT ((void)0)
322
+   
323
+   #undef X2_DIR_WRITE
324
+   #define X2_DIR_WRITE(STATE) stepperX2.Step_Clock(STATE)
325
+   
326
+   #undef X2_DIR_READ
327
+   #define X2_DIR_READ (stepperX2.getStatus() & STATUS_DIR)
328
+#endif
329
+#ifdef Y_IS_L6470
330
+   extern L6470 stepperY;
331
+   #undef Y_ENABLE_INIT
332
+   #define Y_ENABLE_INIT ((void)0)
333
+   
334
+   #undef Y_ENABLE_WRITE
335
+   #define Y_ENABLE_WRITE(STATE) (if(STATE) stepperY.Step_Clock(stepperY.getStatus() & STATUS_HIZ); else stepperY.softFree();)
336
+   
337
+   #undef Y_ENABLE_READ
338
+   #define Y_ENABLE_READ (stepperY.getStatus() & STATUS_HIZ)
339
+   
340
+   #undef Y_DIR_INIT 
341
+   #define Y_DIR_INIT ((void)0)
342
+   
343
+   #undef Y_DIR_WRITE
344
+   #define Y_DIR_WRITE(STATE) stepperY.Step_Clock(STATE)
345
+   
346
+   #undef Y_DIR_READ
347
+   #define Y_DIR_READ (stepperY.getStatus() & STATUS_DIR)  
296 348
 #endif
349
+#ifdef Y2_IS_L6470
350
+   extern L6470 stepperY2;
351
+   #undef Y2_ENABLE_INIT
352
+   #define Y2_ENABLE_INIT ((void)0)
353
+   
354
+   #undef Y2_ENABLE_WRITE
355
+   #define Y2_ENABLE_WRITE(STATE) (if(STATE) stepperY2.Step_Clock(stepperY2.getStatus() & STATUS_HIZ); else stepperY2.softFree();)
356
+   
357
+   #undef Y2_ENABLE_READ
358
+   #define Y2_ENABLE_READ (stepperY2.getStatus() & STATUS_HIZ)
359
+   
360
+   #undef Y2_DIR_INIT 
361
+   #define Y2_DIR_INIT ((void)0)
362
+   
363
+   #undef Y2_DIR_WRITE
364
+   #define Y2_DIR_WRITE(STATE) stepperY2.Step_Clock(STATE)
365
+   
366
+   #undef Y2_DIR_READ
367
+   #define Y2_DIR_READ (stepperY2.getStatus() & STATUS_DIR)   
368
+#endif
369
+#ifdef Z_IS_L6470
370
+   extern L6470 stepperZ;
371
+   #undef Z_ENABLE_INIT
372
+   #define Z_ENABLE_INIT ((void)0)
373
+   
374
+   #undef Z_ENABLE_WRITE
375
+   #define Z_ENABLE_WRITE(STATE) (if(STATE) stepperZ.Step_Clock(stepperZ.getStatus() & STATUS_HIZ); else stepperZ.softFree();)
376
+   
377
+   #undef Z_ENABLE_READ
378
+   #define Z_ENABLE_READ (stepperZ.getStatus() & STATUS_HIZ)
379
+   
380
+   #undef Z_DIR_INIT 
381
+   #define Z_DIR_INIT ((void)0)
382
+   
383
+   #undef Z_DIR_WRITE
384
+   #define Z_DIR_WRITE(STATE) stepperZ.Step_Clock(STATE)
385
+   
386
+   #undef Y_DIR_READ
387
+   #define Y_DIR_READ (stepperZ.getStatus() & STATUS_DIR)      
388
+#endif
389
+#ifdef Z2_IS_L6470
390
+   extern L6470 stepperZ2;
391
+   #undef Z2_ENABLE_INIT
392
+   #define Z2_ENABLE_INIT ((void)0)
393
+   
394
+   #undef Z2_ENABLE_WRITE
395
+   #define Z2_ENABLE_WRITE(STATE) (if(STATE) stepperZ2.Step_Clock(stepperZ2.getStatus() & STATUS_HIZ); else stepperZ2.softFree();)
396
+   
397
+   #undef Z2_ENABLE_READ
398
+   #define Z2_ENABLE_READ (stepperZ2.getStatus() & STATUS_HIZ)
399
+   
400
+   #undef Z2_DIR_INIT 
401
+   #define Z2_DIR_INIT ((void)0)
402
+   
403
+   #undef Z2_DIR_WRITE
404
+   #define Z2_DIR_WRITE(STATE) stepperZ2.Step_Clock(STATE)
405
+   
406
+   #undef Y2_DIR_READ
407
+   #define Y2_DIR_READ (stepperZ2.getStatus() & STATUS_DIR)       
408
+#endif
409
+#ifdef E0_IS_L6470
410
+   extern L6470 stepperE0;
411
+   #undef E0_ENABLE_INIT
412
+   #define E0_ENABLE_INIT ((void)0)
413
+   
414
+   #undef E0_ENABLE_WRITE
415
+   #define E0_ENABLE_WRITE(STATE) (if(STATE) stepperE0.Step_Clock(stepperE0.getStatus() & STATUS_HIZ); else stepperE0.softFree();)
416
+   
417
+   #undef E0_ENABLE_READ
418
+   #define E0_ENABLE_READ (stepperE0.getStatus() & STATUS_HIZ)
419
+   
420
+   #undef E0_DIR_INIT 
421
+   #define E0_DIR_INIT ((void)0)
422
+   
423
+   #undef E0_DIR_WRITE
424
+   #define E0_DIR_WRITE(STATE) stepperE0.Step_Clock(STATE)
425
+   
426
+   #undef E0_DIR_READ
427
+   #define E0_DIR_READ (stepperE0.getStatus() & STATUS_DIR)    
428
+#endif
429
+#ifdef E1_IS_L6470
430
+   extern L6470 stepperE1;
431
+   #undef E1_ENABLE_INIT
432
+   #define E1_ENABLE_INIT ((void)0)
433
+   
434
+   #undef E1_ENABLE_WRITE
435
+   #define E1_ENABLE_WRITE(STATE) (if(STATE) stepperE1.Step_Clock(stepperE1.getStatus() & STATUS_HIZ); else stepperE1.softFree();)
436
+   
437
+   #undef E1_ENABLE_READ
438
+   #define E1_ENABLE_READ (stepperE1.getStatus() & STATUS_HIZ)
439
+   
440
+   #undef E1_DIR_INIT 
441
+   #define E1_DIR_INIT ((void)0)
442
+   
443
+   #undef E1_DIR_WRITE
444
+   #define E1_DIR_WRITE(STATE) stepperE1.Step_Clock(STATE)
445
+   
446
+   #undef E1_DIR_READ
447
+   #define E1_DIR_READ (stepperE1.getStatus() & STATUS_DIR)  
448
+#endif
449
+#ifdef E2_IS_L6470
450
+   extern L6470 stepperE2;
451
+   #undef E2_ENABLE_INIT
452
+   #define E2_ENABLE_INIT ((void)0)
453
+   
454
+   #undef E2_ENABLE_WRITE
455
+   #define E2_ENABLE_WRITE(STATE) (if(STATE) stepperE2.Step_Clock(stepperE2.getStatus() & STATUS_HIZ); else stepperE2.softFree();)
456
+   
457
+   #undef E2_ENABLE_READ
458
+   #define E2_ENABLE_READ (stepperE2.getStatus() & STATUS_HIZ)
459
+   
460
+   #undef E2_DIR_INIT 
461
+   #define E2_DIR_INIT ((void)0)
462
+   
463
+   #undef E2_DIR_WRITE
464
+   #define E2_DIR_WRITE(STATE) stepperE2.Step_Clock(STATE)
465
+   
466
+   #undef E2_DIR_READ
467
+   #define E2_DIR_READ (stepperE2.getStatus() & STATUS_DIR)  
468
+#endif
469
+#ifdef E3_IS_L6470
470
+   extern L6470 stepperE3;
471
+   #undef E3_ENABLE_INIT
472
+   #define E3_ENABLE_INIT ((void)0)
473
+   
474
+   #undef E3_ENABLE_WRITE
475
+   #define E3_ENABLE_WRITE(STATE) (if(STATE) stepperE3.Step_Clock(stepperE3.getStatus() & STATUS_HIZ); else stepperE3.softFree();)
476
+   
477
+   #undef E3_ENABLE_READ
478
+   #define E3_ENABLE_READ (stepperE3.getStatus() & STATUS_HIZ)
479
+   
480
+   #undef E3_DIR_INIT 
481
+   #define E3_DIR_INIT ((void)0)
482
+   
483
+   #undef E3_DIR_WRITE
484
+   #define E3_DIR_WRITE(STATE) stepperE3.Step_Clock(STATE)
485
+   
486
+   #undef E3_DIR_READ
487
+   #define E3_DIR_READ (stepperE3.getStatus() & STATUS_DIR)  
488
+#endif
489
+
490
+#endif  //HAVE_L6470DRIVER
491
+
492
+#endif // STEPPER_INDIRECTION_H

Загрузка…
Отмена
Сохранить