-
Notifications
You must be signed in to change notification settings - Fork 198
/
MovementAxis.cpp
988 lines (822 loc) · 19.2 KB
/
MovementAxis.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
/*
* MovementAxis.cpp
*
* Created on: 18 juli 2015
* Author: Tim Evers
*/
#include "MovementAxis.h"
MovementAxis::MovementAxis()
{
lastCalcLog = 0;
pinStep = 0;
pinDirection = 0;
pinEnable = 0;
pin2Step = 0;
pin2Direction = 0;
pin2Enable = 0;
pinMin = 0;
pinMax = 0;
axisActive = false;
coordSourcePoint = 0;
coordCurrentPoint = 0;
coordDestinationPoint = 0;
coordHomeAxis = 0;
movementUp = false;
movementToHome = false;
movementAccelerating = false;
movementDecelerating = false;
movementCruising = false;
movementCrawling = false;
movementMotorActive = false;
movementMoving = false;
stepIsOn = false;
setMotorStepWrite = &MovementAxis::setMotorStepWriteDefault;
setMotorStepWrite2 = &MovementAxis::setMotorStepWriteDefault2;
resetMotorStepWrite = &MovementAxis::resetMotorStepWriteDefault;
resetMotorStepWrite2 = &MovementAxis::resetMotorStepWriteDefault2;
}
void MovementAxis::test()
{
Serial.print("Check timing ");
Serial.print(" motorInterruptSpeed ");
Serial.print(motorInterruptSpeed);
Serial.print(" axisSpeed ");
Serial.print(axisSpeed);
Serial.print(" active ");
Serial.print(axisActive);
Serial.print(" move ticks ");
Serial.print(moveTicks);
Serial.print(" step on ");
Serial.print(stepIsOn);
Serial.print(" tick on ");
Serial.print(stepOnTick);
Serial.print(" tick off ");
Serial.print(stepOffTick);
Serial.print(" mov step done");
Serial.print(movementStepDone);
Serial.print("\r\n");
}
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
unsigned int MovementAxis::getLostSteps()
{
/**/
//return TMC2130A->get_MSCNT();
return 0;
}
void MovementAxis::initTMC2130()
{
if (channelLabel == 'X')
{
TMC2130A = &TMC2130X;
TMC2130B = &TMC2130E;
}
if (channelLabel == 'Y')
{
TMC2130A = &TMC2130Y;
}
if (channelLabel == 'Z')
{
TMC2130A = &TMC2130Z;
}
setMotorStepWrite = &MovementAxis::setMotorStepWriteDefault;
setMotorStepWrite2 = &MovementAxis::setMotorStepWriteDefault2;
resetMotorStepWrite = &MovementAxis::resetMotorStepWriteDefault;
resetMotorStepWrite2 = &MovementAxis::resetMotorStepWriteDefault2;
/**/ // Not using the edge driving now, only standard pulse driving
// as edge driving causes issues with stall detection routines
//setMotorStepWrite = &MovementAxis::setMotorStepWriteTMC2130;
//setMotorStepWrite2 = &MovementAxis::setMotorStepWriteTMC2130_2;
//resetMotorStepWrite = &MovementAxis::resetMotorStepWriteTMC2130;
//resetMotorStepWrite2 = &MovementAxis::resetMotorStepWriteTMC2130_2;
TMC2130A->init();
if (channelLabel == 'X')
{
TMC2130B->init();
}
}
void MovementAxis::loadSettingsTMC2130(int motorCurrent, int stallSensitivity, int microSteps)
{
loadTMC2130ParametersMotor(TMC2130A, microSteps, motorCurrent, stallSensitivity);
if (channelLabel == 'X')
{
loadTMC2130ParametersMotor(TMC2130B, microSteps, motorCurrent, stallSensitivity);
}
}
uint8_t MovementAxis::getStatus() {
//return TMC2130X.read_STAT();
return TMC2130A->read_STAT();
}
uint16_t MovementAxis::getLoad() {
//return TMC2130A->sg_result();
/**/
return 0;
}
#endif
long MovementAxis::getLastPosition()
{
return axisLastPosition;
}
void MovementAxis::setLastPosition(long position)
{
axisLastPosition = position;
}
unsigned int MovementAxis::calculateSpeed(long sourcePosition, long currentPosition, long destinationPosition, long minSpeed, long maxSpeed, long stepsAccDec)
{
int newSpeed = 0;
long curPos = abs(currentPosition);
long staPos;
long endPos;
movementAccelerating = false;
movementDecelerating = false;
movementCruising = false;
movementCrawling = false;
movementMoving = false;
// Set the possible negative coordinates to all positive numbers
// so the calculation code still works after the changes
staPos = 0;
endPos = abs(destinationPosition - sourcePosition);
if (sourcePosition < destinationPosition)
{
curPos = currentPosition - sourcePosition;
}
else
{
curPos = currentPosition - destinationPosition;
}
unsigned long halfway = ((endPos - staPos) / 2) + staPos;
//unsigned long halfway = ((destinationPosition - sourcePosition) / 2) + sourcePosition;
// Set the homing speed if the position would be out of bounds
if (
(curPos < staPos || curPos > endPos)
// ||
// Also limit the speed to a crawl when the move would pass the home position
// (sourcePosition > 0 && destinationPosition < 0) || (sourcePosition < 0 && destinationPosition > 0)
// (!motorHomeIsUp && currentPosition <= 0) || (motorHomeIsUp && currentPosition >= 0) ||)
)
{
newSpeed = motorSpeedHome;
//newSpeed = minSpeed;
movementCrawling = true;
movementMoving = true;
}
else
{
if (curPos >= staPos && curPos <= halfway)
{
// accelerating
if (curPos > (staPos + stepsAccDec))
{
// now beyond the accelleration point to go full speed
newSpeed = maxSpeed + 1;
movementCruising = true;
movementMoving = true;
}
else
{
// speeding up, increase speed linear within the first period
newSpeed = (1.0 * (curPos - staPos) / stepsAccDec * (maxSpeed - minSpeed)) + minSpeed;
movementAccelerating = true;
movementMoving = true;
}
}
else
{
// decelerating
if (curPos < (endPos - stepsAccDec))
{
// still before the deceleration point so keep going at full speed
newSpeed = maxSpeed + 2;
movementCruising = true;
movementMoving = true;
}
else
{
// speeding up, increase speed linear within the first period
newSpeed = (1.0 * (endPos - curPos) / stepsAccDec * (maxSpeed - minSpeed)) + minSpeed;
movementDecelerating = true;
movementMoving = true;
}
}
}
if (debugPrint && (millis() - lastCalcLog > 1000))
{
lastCalcLog = millis();
Serial.print("R99");
Serial.print(" sta ");
Serial.print(staPos);
Serial.print(" cur ");
Serial.print(curPos);
Serial.print(" end ");
Serial.print(endPos);
Serial.print(" half ");
Serial.print(halfway);
Serial.print(" len ");
Serial.print(stepsAccDec);
Serial.print(" min ");
Serial.print(minSpeed);
Serial.print(" max ");
Serial.print(maxSpeed);
Serial.print(" spd ");
Serial.print(" ");
Serial.print(newSpeed);
Serial.print("\r\n");
}
// Return the calculated speed, in steps per second
return newSpeed;
}
void MovementAxis::checkAxisDirection()
{
if (coordHomeAxis)
{
// When home is active, the direction is fixed
movementUp = motorHomeIsUp;
movementToHome = true;
}
else
{
// For normal movement, move in direction of destination
movementUp = (coordCurrentPoint < coordDestinationPoint);
movementToHome = (abs(coordCurrentPoint) >= abs(coordDestinationPoint));
}
if (coordCurrentPoint == 0)
{
// Go slow when theoretical end point reached but there is no end stop siganl
axisSpeed = motorSpeedMin;
}
}
void MovementAxis::setDirectionAxis()
{
if (((!coordHomeAxis && coordCurrentPoint < coordDestinationPoint) || (coordHomeAxis && motorHomeIsUp)))
{
setDirectionUp();
}
else
{
setDirectionDown();
}
}
void MovementAxis::checkMovement()
{
checkAxisDirection();
// Handle movement if destination is not already reached or surpassed
if (
(
(coordDestinationPoint > coordSourcePoint && coordCurrentPoint < coordDestinationPoint) ||
(coordDestinationPoint < coordSourcePoint && coordCurrentPoint > coordDestinationPoint) ||
coordHomeAxis) &&
axisActive)
{
// home or destination not reached, keep moving
// If end stop reached or the encoder doesn't move anymore, stop moving motor, otherwise set the timing for the next step
if ((coordHomeAxis && !endStopAxisReached(false)) || (!coordHomeAxis && !endStopAxisReached(!movementToHome)))
{
// Get the axis speed, in steps per second
axisSpeed = calculateSpeed(coordSourcePoint, coordCurrentPoint, coordDestinationPoint,
motorSpeedMin, motorSpeedMax, motorStepsAcc);
}
else
{
axisActive = false;
}
}
else
{
// Destination or home reached. Deactivate the axis.
axisActive = false;
}
// If end stop for home is active, set the position to zero
if (endStopAxisReached(false))
{
coordCurrentPoint = 0;
}
}
void MovementAxis::incrementTick()
{
if (axisActive)
{
moveTicks++;
}
}
void MovementAxis::checkTiming()
{
if (stepIsOn)
{
if (moveTicks >= stepOffTick)
{
// Negative flank for the steps
resetMotorStep();
setTicks();
//test();
}
}
else
{
if (axisActive)
{
if (moveTicks >= stepOnTick)
{
// Positive flank for the steps
setStepAxis();
//test();
}
}
}
}
void MovementAxis::setTicks()
{
// Take the requested speed (steps / second) and divide by the interrupt speed (interrupts per seconde)
// This gives the number of interrupts (called ticks here) before the pulse needs to be set for the next step
stepOnTick = moveTicks + (1000.0 * 1000.0 / motorInterruptSpeed / axisSpeed / 2);
stepOffTick = moveTicks + (1000.0 * 1000.0 / motorInterruptSpeed / axisSpeed);
}
void MovementAxis::setStepAxis()
{
stepIsOn = true;
if (movementUp)
{
coordCurrentPoint++;
}
else
{
coordCurrentPoint--;
}
// set a step on the motors
setMotorStep();
}
bool MovementAxis::endStopAxisReached(bool movement_forward)
{
bool min_endstop = false;
bool max_endstop = false;
bool invert = false;
if (motorEndStopInv)
{
invert = true;
}
// for the axis to check, retrieve the end stop status
if (!invert)
{
min_endstop = endStopMin();
max_endstop = endStopMax();
}
else
{
min_endstop = endStopMax();
max_endstop = endStopMin();
}
// if moving forward, only check the end stop max
// for moving backwards, check only the end stop min
if ((!movement_forward && min_endstop) || (movement_forward && max_endstop))
{
return 1;
}
return 0;
}
void MovementAxis::MovementAxis::loadPinNumbers(int step, int dir, int enable, int min, int max, int step2, int dir2, int enable2)
{
pinStep = step;
pinDirection = dir;
pinEnable = enable;
pin2Step = step2;
pin2Direction = dir2;
pin2Enable = enable2;
pinMin = min;
pinMax = max;
}
void MovementAxis::loadMotorSettings(
long speedMax, long speedMin, long speedHome, long stepsAcc, long timeOut, bool homeIsUp, bool motorInv,
bool endStInv, bool endStInv2, long interruptSpeed, bool motor2Enbl, bool motor2Inv, bool endStEnbl,
bool stopAtHome, long maxSize, bool stopAtMax)
{
motorSpeedMax = speedMax;
motorSpeedMin = speedMin;
motorSpeedHome = speedHome;
motorStepsAcc = stepsAcc;
motorTimeOut = timeOut;
motorHomeIsUp = homeIsUp;
motorMotorInv = motorInv;
motorEndStopInv = endStInv;
motorEndStopInv2 = endStInv2;
motorEndStopEnbl = endStEnbl;
motorInterruptSpeed = interruptSpeed;
motorMotor2Enl = motor2Enbl;
motorMotor2Inv = motor2Inv;
motorStopAtHome = stopAtHome;
motorMaxSize = maxSize;
motorStopAtMax = stopAtMax;
if (pinStep == 54)
{
setMotorStepWrite = &MovementAxis::setMotorStepWrite54;
resetMotorStepWrite = &MovementAxis::resetMotorStepWrite54;
}
if (pinStep == 60)
{
setMotorStepWrite = &MovementAxis::setMotorStepWrite60;
resetMotorStepWrite = &MovementAxis::resetMotorStepWrite60;
}
if (pinStep == 46)
{
setMotorStepWrite = &MovementAxis::setMotorStepWrite46;
resetMotorStepWrite = &MovementAxis::resetMotorStepWrite46;
}
if (pin2Step == 26)
{
setMotorStepWrite2 = &MovementAxis::setMotorStepWrite26;
resetMotorStepWrite2 = &MovementAxis::resetMotorStepWrite26;
}
}
bool MovementAxis::loadCoordinates(long sourcePoint, long destinationPoint, bool home)
{
coordSourcePoint = sourcePoint;
coordCurrentPoint = sourcePoint;
coordDestinationPoint = destinationPoint;
coordHomeAxis = home;
bool changed = false;
// Limit normal movement to the home position
if (motorStopAtHome)
{
if (!motorHomeIsUp && coordDestinationPoint < 0)
{
coordDestinationPoint = 0;
changed = true;
}
if (motorHomeIsUp && coordDestinationPoint > 0)
{
coordDestinationPoint = 0;
changed = true;
}
}
// limit the maximum size the bot can move, when there is a size present
if (motorMaxSize > 0 && motorStopAtMax)
{
if (abs(coordDestinationPoint) > abs(motorMaxSize))
{
if (coordDestinationPoint < 0)
{
coordDestinationPoint = -abs(motorMaxSize);
changed = true;
}
else
{
coordDestinationPoint = abs(motorMaxSize);
changed = true;
}
}
}
// Initialize movement variables
moveTicks = 0;
axisActive = true;
return changed;
}
void MovementAxis::enableMotor()
{
digitalWrite(pinEnable, LOW);
if (motorMotor2Enl)
{
digitalWrite(pin2Enable, LOW);
}
movementMotorActive = true;
}
void MovementAxis::disableMotor()
{
digitalWrite(pinEnable, HIGH);
if (motorMotor2Enl)
{
digitalWrite(pin2Enable, HIGH);
}
movementMotorActive = false;
}
void MovementAxis::setDirectionUp()
{
//#if !defined(FARMDUINO_EXP_V20)
if (motorMotorInv)
{
digitalWrite(pinDirection, LOW);
}
else
{
digitalWrite(pinDirection, HIGH);
}
if (motorMotor2Enl && motorMotor2Inv)
{
digitalWrite(pin2Direction, LOW);
}
else
{
digitalWrite(pin2Direction, HIGH);
}
//#endif
/*
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
// The TMC2130 uses a command to change direction, not a pin
if (motorMotorInv)
{
TMC2130A->shaft_dir(0);
}
else
{
TMC2130A->shaft_dir(1);
}
if (motorMotor2Enl && motorMotor2Inv)
{
TMC2130B->shaft_dir(0);
}
else
{
TMC2130B->shaft_dir(1);
}
#endif
*/
}
void MovementAxis::setDirectionDown()
{
//#if !defined(FARMDUINO_EXP_V20)
if (motorMotorInv)
{
digitalWrite(pinDirection, HIGH);
}
else
{
digitalWrite(pinDirection, LOW);
}
if (motorMotor2Enl && motorMotor2Inv)
{
digitalWrite(pin2Direction, HIGH);
}
else
{
digitalWrite(pin2Direction, LOW);
}
//#endif
/*
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
// The TMC2130 uses a command to change direction, not a pin
if (motorMotorInv)
{
TMC2130A->shaft_dir(1);
}
else
{
TMC2130A->shaft_dir(0);
}
if (motorMotor2Enl && motorMotor2Inv)
{
TMC2130B->shaft_dir(1);
}
else
{
TMC2130B->shaft_dir(0);
}
#endif
*/
}
void MovementAxis::setMovementUp()
{
movementUp = true;
}
void MovementAxis::setMovementDown()
{
movementUp = false;
}
void MovementAxis::setDirectionHome()
{
if (motorHomeIsUp)
{
setDirectionUp();
setMovementUp();
}
else
{
setDirectionDown();
setMovementDown();
}
}
void MovementAxis::setDirectionAway()
{
if (motorHomeIsUp)
{
setDirectionDown();
setMovementDown();
}
else
{
setDirectionUp();
setMovementUp();
}
}
unsigned long MovementAxis::getLength(long l1, long l2)
{
if (l1 > l2)
{
return l1 - l2;
}
else
{
return l2 - l1;
}
}
bool MovementAxis::endStopsReached()
{
return ((digitalRead(pinMin) == motorEndStopInv2) || (digitalRead(pinMax) == motorEndStopInv2)) && motorEndStopEnbl;
}
bool MovementAxis::endStopMin()
{
//return ((digitalRead(pinMin) == motorEndStopInv) || (digitalRead(pinMax) == motorEndStopInv));
return ((digitalRead(pinMin) == motorEndStopInv2) && motorEndStopEnbl);
}
bool MovementAxis::endStopMax()
{
//return ((digitalRead(pinMin) == motorEndStopInv) || (digitalRead(pinMax) == motorEndStopInv));
return ((digitalRead(pinMax) == motorEndStopInv2) && motorEndStopEnbl);
}
bool MovementAxis::isAxisActive()
{
return axisActive;
}
void MovementAxis::deactivateAxis()
{
axisActive = false;
}
void MovementAxis::setMotorStep()
{
stepIsOn = true;
//digitalWrite(pinStep, HIGH);
(this->*setMotorStepWrite)();
if (pin2Enable)
{
(this->*setMotorStepWrite2)();
//digitalWrite(pin2Step, HIGH);
}
}
void MovementAxis::resetMotorStep()
{
stepIsOn = false;
movementStepDone = true;
digitalWrite(pinStep, LOW);
//(this->*resetMotorStepWrite)();
if (pin2Enable)
{
digitalWrite(pin2Step, LOW);
//(this->*resetMotorStepWrite2)();
}
}
bool MovementAxis::pointReached(long currentPoint, long destinationPoint)
{
return (destinationPoint == currentPoint);
}
long MovementAxis::currentPosition()
{
return coordCurrentPoint;
}
void MovementAxis::setCurrentPosition(long newPos)
{
coordCurrentPoint = newPos;
}
long MovementAxis::destinationPosition()
{
return coordDestinationPoint;
}
void MovementAxis::setMaxSpeed(long speed)
{
motorSpeedMax = speed;
}
void MovementAxis::activateDebugPrint()
{
debugPrint = true;
}
bool MovementAxis::isStepDone()
{
return movementStepDone;
}
void MovementAxis::resetStepDone()
{
movementStepDone = false;
}
bool MovementAxis::movingToHome()
{
return movementToHome;
}
bool MovementAxis::movingUp()
{
return movementUp;
}
bool MovementAxis::isAccelerating()
{
return movementAccelerating;
}
bool MovementAxis::isDecelerating()
{
return movementDecelerating;
}
bool MovementAxis::isCruising()
{
return movementCruising;
}
bool MovementAxis::isCrawling()
{
return movementCrawling;
}
bool MovementAxis::isMotorActive()
{
return movementMotorActive;
}
/// Functions for pin writing using alternative method
// Pin write default functions
void MovementAxis::setMotorStepWriteDefault()
{
digitalWrite(pinStep, HIGH);
}
void MovementAxis::setMotorStepWriteDefault2()
{
digitalWrite(pin2Step, HIGH);
}
void MovementAxis::resetMotorStepWriteDefault()
{
digitalWrite(pinStep, LOW);
}
void MovementAxis::resetMotorStepWriteDefault2()
{
digitalWrite(pin2Step, LOW);
}
// X step
void MovementAxis::setMotorStepWrite54()
{
//PF0
PORTF |= B00000001;
}
void MovementAxis::resetMotorStepWrite54()
{
//PF0
PORTF &= B11111110;
}
// X step 2
void MovementAxis::setMotorStepWrite26()
{
//PA4
PORTA |= B00010000;
}
void MovementAxis::resetMotorStepWrite26()
{
PORTA &= B11101111;
}
// Y step
void MovementAxis::setMotorStepWrite60()
{
//PF6
PORTF |= B01000000;
}
void MovementAxis::resetMotorStepWrite60()
{
//PF6
PORTF &= B10111111;
}
// Z step
void MovementAxis::setMotorStepWrite46()
{
//PL3
PORTL |= B00001000;
}
void MovementAxis::resetMotorStepWrite46()
{
//PL3
PORTL &= B11110111;
}
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
//// TMC2130 Functions
void MovementAxis::setMotorStepWriteTMC2130()
{
// TMC2130 works on each edge of the step pulse,
// so instead of setting the step bit,
// toggle the bit here
if (tmcStep)
{
digitalWrite(pinStep, HIGH);
tmcStep = false;
}
else
{
digitalWrite(pinStep, LOW);
tmcStep = true;
}
}
void MovementAxis::setMotorStepWriteTMC2130_2()
{
if (tmcStep2)
{
digitalWrite(pin2Step, HIGH);
tmcStep2 = false;
}
else
{
digitalWrite(pin2Step, LOW);
tmcStep2 = true;
}
}
void MovementAxis::resetMotorStepWriteTMC2130()
{
// No action needed
}
void MovementAxis::resetMotorStepWriteTMC2130_2()
{
// No action needed
}
#endif