-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathTMC4361A_TMC2660_Utils.cpp
2128 lines (1654 loc) · 82.6 KB
/
TMC4361A_TMC2660_Utils.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
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Utils.cpp
This file contains higher-level functions for interacting with the TMC4362A.
Some functions are low-level helpers and do not need to be accessed directly by the user
User-facing functions:
tmc4361A_tmc2660_init: Initialize the tmc4361A and tmc2660
Arguments: TMC4361ATypeDef *tmc4361A, uint32_t clk_Hz_TMC4361
tmc4361A_setMaxSpeed: Write the target velocity to the tmc4361A in units microsteps per second and recalculates bow values
Arguments: TMC4361ATypeDef *tmc4361A, int32_t velocity
tmc4361A_setSpeed: Start moving at a constant speed in units microsteps per second
Arguments: TMC4361ATypeDef *tmc4361A, int32_t velocity
tmc4361A_init_ABN_encoder: Initialize an incremental ABN encoder with a given resolution and filter parameters
Arguments: TMC4361ATypeDef *tmc4361A, int32_t enc_res, uint8_t filter_wait_time, uint8_t filter_exponent, uint16_t filter_vmean
tmc4361A_init_calib_feedback: Initialize the encoder feedback and run calibration
Arguments: (TMC4361ATypeDef *tmc4361A, int32_t enc_res);
read_feedback_flag: Returns the feedback error flags
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_speed: Returns the current speed in microsteps per second
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_acceleration: Returns the current acceleration in microsteps per second^2
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_setMaxAcceleration: Write the maximum acceleration in units microsteps per second squared and recalculates bow values
Arguments: TMC4361ATypeDef *tmc4361A, uint32_t acceleration
tmc4361A_moveTo: Move to the target absolute position in units microsteps
Arguments: TMC4361ATypeDef *tmc4361A, int32_t x_pos
tmc4361A_move: Move to a position relative to the current position in units microsteps
Arguments: TMC4361ATypeDef *tmc4361A, int32_t x_pos
tmc4361A_currentPosition: Return the current position in units microsteps
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_targetPosition: Return the target position in units microsteps
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_setCurrentPosition: Set the current position to a specific value in units microsteps
Arguments: TMC4361ATypeDef *tmc4361A, int32_t position
tmc4361A_stop: Halt operation by setting the target position to the current position
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_isRunning: Returns true if the motor is moving
Arguments: TMC4361ATypeDef *tmc4361A, bool pid_enable
tmc4361A_xmmToMicrosteps: Convert from millimeters to units microsteps for position and jerk values
Arguments: TMC4361ATypeDef *tmc4361A, float mm
tmc4361A_xmicrostepsTomm: Convert from microsteps to units millimeters for position and jerk values
Arguments: TMC4361ATypeDef *tmc4361A, int32_t microsteps
tmc4361A_vmmToMicrosteps: Convert from millimeters to units microsteps for velocity values
Arguments: TMC4361ATypeDef *tmc4361A, float mm
tmc4361A_vmicrostepsTomm: Convert from microsteps to units millimeters for velocity values
Arguments: TMC4361ATypeDef *tmc4361A, int32_t microsteps
tmc4361A_ammToMicrosteps: Convert from millimeters to units microsteps for acceleration values
Arguments: TMC4361ATypeDef *tmc4361A, float mm
tmc4361A_amicrostepsTomm: Convert from microsteps to units millimeters for acceleration values
Arguments: TMC4361ATypeDef *tmc4361A, int32_t microsteps
tmc4361A_enableLimitSwitch: Enables reading from limit switches and using limit switches as automatic stop indicators.
Arguments: TMC4361ATypeDef *tmc4361A, uint8_t polarity, uint8_t which
tmc4361A_enableHomingLimit: Enables using the limit switch or homing
Arguments: TMC4361ATypeDef *tmc4361A, uint8_t sw, uint8_t pol_lft, uint8_t pol_rht
tmc4361A_readLimitSwitches: Read limit switch current state
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_moveToExtreme: Go all the way left or right
Arguments: TMC4361ATypeDef *tmc4361A, int32_t vel, int8_t dir
tmc4361A_setHome: Set current location as home
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_cScaleInit: Initialize current scale values.
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_setPitch: Set the pitch (mm of travel per motor rotation)
Arguments: TMC4361ATypeDef *tmc4361A, float pitchval
tmc4361A_setMicrosteps: Set the number of microsteps per fullstep, must be a power of 2 between 1 and 256 inclusive
Arguments: TMC4361ATypeDef *tmc4361A, uint16_t mstep
tmc4361A_setSPR: Set the motor's steps per revolution, typically 200
Arguments: TMC4361ATypeDef *tmc4361A, uint16_t spr
tmc4361A_writeMicrosteps: Write the number of microsteps per fullstep to the motor driver
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_writeSPR: Write the number of steps per revolution to the motor driver
Arguments: TMC4361ATypeDef *tmc4361A
For internal use:
tmc4361A_readWriteArray: Used for low-level SPI communication with the TMC4361A
Arguments: uint8_t channel, uint8_t *data, size_t length
tmc4361A_setBits: Implements some of the features of tmc4361A_readWriteCover in an easier to use way; it sets bits in a register without disturbing the other bits
Arguments: TMC4361ATypeDef *tmc4361A, uint8_t address, int32_t dat
tmc4361A_rstBits: Implements some of the features of tmc4361A_readWriteCover in an easier to use way; it clears bits in a register without disturbing the other bits
Arguments: TMC4361ATypeDef *tmc4361A, uint8_t address, int32_t dat
tmc4361A_readSwitchEvent: Read events created by the limit switches
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_sRampInit: Write all parameters for the s-shaped ramp
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_cScaleInit: Write all parameters for current scaling
Arguments: TMC4361ATypeDef *tmc4361A
tmc4361A_setSRampParam: Set and write an individual parameter for the s-shaped ramp
Arguments: TMC4361ATypeDef *tmc4361A, uint8_t idx, int32_t param
tmc4361A_adjustBows: Sets shared bow values based on velocity and acceleration
Arguments: TMC4361ATypeDef *tmc4361A
*/
#include "TMC4361A_TMC2660_Utils.h"
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_readWriteArray() sends a number of bytes to a target device over SPI. Functions in TMC4316A.cpp depend on this function.
OPERATION: This function mediates a SPI transaction by first setting the CS pin of the target device low, then sending bytes from an array one at a time over SPI and storing the data back into the original array. Once the transaction is over, the CS pin is brought high again.
ARGUMENTS:
uint8_t channel: CS pin number
uint8_t *data: Pointer to data array
size_t length: Number of bytes in the data array
RETURNS: None
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES: None
SHARED VARIABLES:
uint8_t *data: Values in this array are overwritten
GLOBAL VARIABLES: None
DEPENDENCIES: SPI.h
-----------------------------------------------------------------------------
*/
void tmc4361A_readWriteArray(uint8_t channel, uint8_t *data, size_t length) {
// Initialize SPI transfer
SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE0));
digitalWrite(channel, LOW);
delayMicroseconds(100);
// Write each byte and overwrite data[] with the response
for (size_t i = 0; i < length; i++) {
data[i] = SPI.transfer(data[i]);
}
// End the transaction
digitalWrite(channel, HIGH);
SPI.endTransaction();
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_setBits() sets bits in a register without affecting the other bits.
OPERATION: We first read the register data then OR the register with the bits we want to set. Then, it writes the data to the address.
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
uint8_t address: Address of the register we want to write to
int32_t dat: Data we want to write to the array
RETURNS: None
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES:
int32_t datagram: Used to hold both the data read from the register and the data we want to write to the register
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_setBits(TMC4361ATypeDef *tmc4361A, uint8_t address, int32_t dat) {
// Set the bits in dat without disturbing any other bits in the register
// Read the bits already there
int32_t datagram = tmc4361A_readInt(tmc4361A, address);
// OR with the bits we want to set
datagram |= dat;
// Write
tmc4361A_writeInt(tmc4361A, address, datagram);
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_rstBits() clears bits in a register without affecting the other bits.
OPERATION: We first read the register data then AND the register with the negation of bits we want to set. Then, it writes the data to the address.
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
uint8_t address: Address of the register we want to write to
int32_t dat: Data we want to write to the array
RETURNS: None
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES:
int32_t datagram: Used to hold both the data read from the register and the data we want to write to the register
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_rstBits(TMC4361ATypeDef *tmc4361A, uint8_t address, int32_t dat) {
// Reset the bits in dat without disturbing any other bits in the register
// Read the bits already there
int32_t datagram = tmc4361A_readInt(tmc4361A, address);
// AND with the bits with the negation of the bits we want to clear
datagram &= ~dat;
// Write
tmc4361A_writeInt(tmc4361A, address, datagram);
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_cScaleInit() writes current scale parameters to the TCM4361A and TMC2660
OPERATION: We first write the current scale to the TMC2660 then write hold, drive, and boost scale parameters to the TCM4361A. The values being written are stored in *tmc4361A.
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
RETURNS: None
INPUTS / OUTPUTS: Sends signals ove MOSI/MISO; the motor should not move
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_cScaleInit(TMC4361ATypeDef *tmc4361A) {
tmc4361A_writeInt(tmc4361A, TMC4361A_COVER_LOW_WR, SGCSCONF | SFILT | tmc4361A->cscaleParam[CSCALE_IDX]);
// current open loop scaling
tmc4361A_writeInt(tmc4361A, TMC4361A_SCALE_VALUES, (tmc4361A->cscaleParam[HOLDSCALE_IDX] << TMC4361A_HOLD_SCALE_VAL_SHIFT) + // Set hold scale value (0 to 255)
(tmc4361A->cscaleParam[DRV2SCALE_IDX] << TMC4361A_DRV2_SCALE_VAL_SHIFT) + // Set DRV2 scale (0 to 255)
(tmc4361A->cscaleParam[DRV1SCALE_IDX] << TMC4361A_DRV1_SCALE_VAL_SHIFT) + // Set DRV1 scale (0 to 255)
(tmc4361A->cscaleParam[BSTSCALE_IDX] << TMC4361A_BOOST_SCALE_VAL_SHIFT)); // Set boost scale (0 to 255)
tmc4361A_setBits(tmc4361A, TMC4361A_CURRENT_CONF, TMC4361A_DRIVE_CURRENT_SCALE_EN_MASK); // keep drive current scale
tmc4361A_setBits(tmc4361A, TMC4361A_CURRENT_CONF, TMC4361A_HOLD_CURRENT_SCALE_EN_MASK); // keep hold current scale
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_setPitch() sets screw pitch for the screw attached to the motor.
OPERATION: We write the value in the argument to the motor driver struct
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
float pitchval: Number of millimeteres traveled per full motor revolution
RETURNS: None
INPUTS / OUTPUTS: None
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_setPitch(TMC4361ATypeDef *tmc4361A, float pitchval) {
tmc4361A->threadPitch = pitchval;
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_writeMicrosteps() writes the number of microsteps per fullstep to the motor controller.
OPERATION: We first check if the mstep argument is a power of 2. We set an error flag if it is not.
We then convert the microsteps number to the correct format for the tmc4361A: 256 -> 0, 128 -> 1, ..., 1 -> 8.
This conversion is performed by shifting mstep down a bit and incrementing bitsSet until mstep is equal to 0. This is equivalent to evaluating log_2(mstep)+1. Then we calculate 9-bitsSet to convert to the proper format.
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
uint16_t mstep: Number of microsteps in one full step
RETURNS: none
INPUTS / OUTPUTS: Sends signals ove MOSI/MISO; the motor should not move
LOCAL VARIABLES:
int8_t err: indicates whether the operation was successful
uint8_t bitsSet: Holds which bits to set on the tmc4361A
uint16_t microsteps: Holds a copy of microsteps
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_writeMicrosteps(TMC4361ATypeDef *tmc4361A) {
int8_t err = NO_ERR; // Initally assume mstep is valid
uint8_t bitsSet = 0;
uint16_t mstep = tmc4361A->microsteps;
// Check if mstep is a valid microstep value (a power of 2 between 1 and 256 inclusive)
if ((mstep != 0) && !(mstep & (mstep - 1)) && (mstep <= 256)) {
// Clear the low 4 bits of STEP_CONF to prepare it for writing to
tmc4361A_rstBits(tmc4361A, TMC4361A_STEP_CONF, 0b1111);
}
else {
// If it's not valid, mark all the bits as invalid
mstep = 0;
err = ERR_OUT_OF_RANGE;
}
while (mstep > 0) {
bitsSet++;
mstep = mstep >> 1;
}
bitsSet = 9 - bitsSet;
if (err == NO_ERR) {
tmc4361A_setBits(tmc4361A, TMC4361A_STEP_CONF, bitsSet);
}
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_setMicrosteps() sets microsteps per fullstep for the motor.
OPERATION: We write the value in the argument to the motor driver struct
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
uint16_t mstep: microsteps per fullstep
RETURNS: None
INPUTS / OUTPUTS: None
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
int8_t tmc4361A_setMicrosteps(TMC4361ATypeDef *tmc4361A, uint16_t mstep) {
// Ensure mstep is a power of 2 and within bounds
if ((mstep != 0) && !(mstep & (mstep - 1)) && (mstep <= 256)) {
tmc4361A->microsteps = mstep;
return NO_ERR;
}
else {
return ERR_OUT_OF_RANGE;
}
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_setSPR() sets steps-per-revolution for the motor.
OPERATION: We write the value in the argument to the motor driver struct
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
uint16_t spr: Steps per revolution
RETURNS: None
INPUTS / OUTPUTS: None
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
int8_t tmc4361A_setSPR(TMC4361ATypeDef *tmc4361A, uint16_t spr) {
if (spr > ((1 << 12) - 1)) { // spr is a 12 bit number
return ERR_OUT_OF_RANGE;
}
else {
tmc4361A->stepsPerRev = spr;
return NO_ERR;
}
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_writeSPR() writes steps-per-revolution for the motor to the motor driver.
OPERATION: We read the value in the motor driver struct, format it, and send it to the motor driver
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
RETURNS: None
INPUTS / OUTPUTS: None
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_writeSPR(TMC4361ATypeDef *tmc4361A) {
tmc4361A_rstBits(tmc4361A, TMC4361A_STEP_CONF, TMC4361A_FS_PER_REV_MASK);
tmc4361A_setBits(tmc4361A, TMC4361A_STEP_CONF, tmc4361A->stepsPerRev << TMC4361A_FS_PER_REV_SHIFT);
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_tmc2660_init() initializes the tmc4361A and tmc2660
OPERATION: We write several bytes to the two ICs to configure their behaviors.
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
uint32_t clk_Hz_TMC4361: Clock frequency we are driving the ICs at
RETURNS: None
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_tmc2660_init(TMC4361ATypeDef *tmc4361A, uint32_t clk_Hz_TMC4361) {
// reset
tmc4361A_writeInt(tmc4361A, TMC4361A_RESET_REG, 0x52535400);
// clk
tmc4361A_writeInt(tmc4361A, TMC4361A_CLK_FREQ, clk_Hz_TMC4361);
// SPI configuration
tmc4361A_writeInt(tmc4361A, TMC4361A_SPIOUT_CONF, 0x4440108A);
// cover datagram for TMC2660
tmc4361A_writeInt(tmc4361A, TMC4361A_COVER_LOW_WR, 0x000900C3); // CHOPCONF
tmc4361A_writeInt(tmc4361A, TMC4361A_COVER_LOW_WR, 0x000A0000); // SMARTEN
tmc4361A_writeInt(tmc4361A, TMC4361A_COVER_LOW_WR, 0x000C000A); // SGCSCON
tmc4361A_writeInt(tmc4361A, TMC4361A_COVER_LOW_WR, 0x000E00A1); // SDOFF = 1 -> SPI mode
// current scaling
tmc4361A_cScaleInit(tmc4361A);
// microstepping setting
tmc4361A_writeMicrosteps(tmc4361A);
tmc4361A_writeSPR(tmc4361A);
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_tmc2660_disable_driver() shut off driver MOSFETs
OPERATION: shut off the driver MOSFETs to make axis to disable status
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
RETURNS: None
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_tmc2660_disable_driver(TMC4361ATypeDef *tmc4361A) {
tmc4361A_writeInt(tmc4361A, TMC4361A_COVER_LOW_WR, 0x000900C0); // CHOPCONF
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_tmc2660_enable_driver() enable driver MOSFETs to init argument value
OPERATION: enable the driver MOSFETs to make axis to enable status
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
RETURNS: None
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_tmc2660_enable_driver(TMC4361ATypeDef *tmc4361A) {
tmc4361A_writeInt(tmc4361A, TMC4361A_COVER_LOW_WR, 0x000900C3); // CHOPCONF
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_tmc2660_update() update the tmc4361A and tmc2660 settings (current scaling and microstepping settings)
OPERATION: We write several bytes to the two ICs to configure their behaviors.
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
RETURNS: None
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_tmc2660_update(TMC4361ATypeDef *tmc4361A) {
// current scaling
tmc4361A_cScaleInit(tmc4361A);
// microstepping setting
tmc4361A_writeMicrosteps(tmc4361A);
tmc4361A_writeSPR(tmc4361A);
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_tmc2660_config() configures the parameters for tmc4361A and tmc2660
OPERATION: set parameters
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
float tmc2660_cscale: 0-1
float tmc4361a_hold_scale_val: 0-1
float tmc4361a_drv2_scale_val: 0-1
float tmc4361a_drv1_scale_val: 0-1
float tmc4361a_boost_scale_val: maximum current during the boost phase (in certain sections of the velocity ramp it can be useful to boost the current), 0-1
float pitch_mm: mm traveled per full motor revolution
uint16_t steps_per_rev: full steps per rev
uint16_t microsteps: number of microsteps per fullstep. must be a power of 2 from 1 to 256.
uint8_t dac_idx: DAC associated with this stage. Set to NO_DAC of there isn't one
uint32_t dac_fullscale_msteps: abs(mstep when voltage set to 0 - mstep when voltage set to 5V); used for setting the position using the piezo
RETURNS: None
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_tmc2660_config(TMC4361ATypeDef *tmc4361A, float tmc2660_cscale, float tmc4361a_hold_scale_val, float tmc4361a_drv2_scale_val, float tmc4361a_drv1_scale_val, float tmc4361a_boost_scale_val, float pitch_mm, uint16_t steps_per_rev, uint16_t microsteps, uint8_t dac_idx, uint32_t dac_fullscale_msteps) {
tmc4361A->cscaleParam[0] = uint8_t(tmc2660_cscale * 31);
tmc4361A->cscaleParam[1] = uint8_t(tmc4361a_hold_scale_val * 255);
tmc4361A->cscaleParam[2] = uint8_t(tmc4361a_drv2_scale_val * 255);
tmc4361A->cscaleParam[3] = uint8_t(tmc4361a_drv1_scale_val * 255);
tmc4361A->cscaleParam[4] = uint8_t(tmc4361a_boost_scale_val * 255);
tmc4361A_setPitch(tmc4361A, pitch_mm);
tmc4361A_setSPR(tmc4361A, steps_per_rev);
tmc4361A_setMicrosteps(tmc4361A, microsteps);
tmc4361A->dac_idx = dac_idx;
tmc4361A->dac_fullscale_msteps = dac_fullscale_msteps;
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_enableLimitSwitch() enables either the left or right
OPERATION: We format the switch polarity variables into a datagram and send it to the tmc4361. We then enable position latching when the limit switch is hit
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
uint8_t polarity: Polarity of the switch - 0 if active low, 1 if active high
uint8_t which: either LEFT_SW or RGHT_SW - which switch to enable
uint8_t flipped: if flipped is 1, treat the left/right switches for this motor the opposite way. For example, if which = LEFT_SW and flipped = 1 then the right switch will be initialized and behave as though it was the left switch.
RETURNS: None
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES:
uint32_t pol_datagram, en_datagram: store datagrams to write to the tmc4361.
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_enableLimitSwitch(TMC4361ATypeDef *tmc4361A, uint8_t polarity, uint8_t which, uint8_t flipped) {
polarity &= 1; // mask off unwanted bits
uint32_t pol_datagram;
uint32_t en_datagram;
// Handle case where the switches are flipped
if (flipped != 0) {
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, TMC4361A_INVERT_STOP_DIRECTION_MASK);
}
// Determine what to do based on which switch to enable
switch (which) {
case LEFT_SW:
// Set whether they are low active (set bit to 0) or high active (1)
pol_datagram = (polarity << TMC4361A_POL_STOP_LEFT_SHIFT);
en_datagram = TMC4361A_STOP_LEFT_EN_MASK;
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, pol_datagram);
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, en_datagram);
// store position when we hit left bound
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, TMC4361A_LATCH_X_ON_ACTIVE_L_MASK);
break;
case RGHT_SW:
// Set whether they are low active (set bit to 0) or high active (1)
pol_datagram = (polarity << TMC4361A_POL_STOP_RIGHT_SHIFT);
en_datagram = TMC4361A_STOP_RIGHT_EN_MASK;
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, pol_datagram);
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, en_datagram);
// store position when we hit right bound
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, TMC4361A_LATCH_X_ON_ACTIVE_R_MASK);
break;
}
return;
}
void tmc4361A_setVirtualStop(TMC4361ATypeDef *tmc4361A, uint8_t which, int32_t target) {
// Set VIRTUAL_STOP_[LEFT/RIGHT] with stop position in microsteps
uint8_t address = (which == LEFT_SW) ? TMC4361A_VIRT_STOP_LEFT : TMC4361A_VIRT_STOP_RIGHT;
tmc4361A_writeInt(tmc4361A, address, target);
// Set virtual_[left/right]_limit_en = 1 in REFERENCE_CONF
int32_t dat = (which == LEFT_SW) ? (1 << TMC4361A_VIRTUAL_LEFT_LIMIT_EN_SHIFT) : (1 << TMC4361A_VIRTUAL_RIGHT_LIMIT_EN_SHIFT);
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, dat);
return;
}
// vitual limit switch - to add doc
void tmc4361A_enableVirtualLimitSwitch(TMC4361ATypeDef *tmc4361A, int dir) {
uint32_t en_datagram;
// Determine what to do based on which switch to enable
switch (dir) {
case -1:
en_datagram = TMC4361A_VIRTUAL_LEFT_LIMIT_EN_MASK + (1<<TMC4361A_VIRT_STOP_MODE_SHIFT); // hard stop
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, en_datagram);
break;
case 1:
en_datagram = TMC4361A_VIRTUAL_RIGHT_LIMIT_EN_MASK + (1<<TMC4361A_VIRT_STOP_MODE_SHIFT); // hard stop
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, en_datagram);
break;
}
return;
}
void tmc4361A_disableVirtualLimitSwitch(TMC4361ATypeDef *tmc4361A, int dir) {
uint32_t en_datagram;
// Determine what to do based on which switch to enable
switch (dir) {
case -1:
en_datagram = TMC4361A_VIRTUAL_LEFT_LIMIT_EN_MASK;
tmc4361A_rstBits(tmc4361A, TMC4361A_REFERENCE_CONF, en_datagram);
break;
case 1:
en_datagram = TMC4361A_VIRTUAL_RIGHT_LIMIT_EN_MASK;
tmc4361A_rstBits(tmc4361A, TMC4361A_REFERENCE_CONF, en_datagram);
break;
}
return;
}
int8_t tmc4361A_setVirtualLimit(TMC4361ATypeDef *tmc4361A, int dir, int32_t limit) {
switch (dir) {
case -1:
tmc4361A_writeInt(tmc4361A, TMC4361A_VIRT_STOP_LEFT, limit);
break;
case 1:
tmc4361A_writeInt(tmc4361A, TMC4361A_VIRT_STOP_RIGHT, limit);
break;
}
return NO_ERR;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_enableHomingLimit() enables using either the left or right limit switch for homing
OPERATION: We format the switch polarity variables and target switch into a datagram and send it to the tmc4361. We then enable position latching when the limit switch is hit
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
uint8_t polarity: Polarity of the switch - 0 if active low, 1 if active high
uint8_t which: Which switch to use as home
uint16_t safety_margin: safty margin of home pointer around
RETURNS: None
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_enableHomingLimit(TMC4361ATypeDef *tmc4361A, uint8_t polarity, uint8_t which, uint16_t safety_margin) {
if (which == LEFT_SW) {
if (polarity != 0) {
// If the left switch is active high, HOME_REF = 0 indicates positive direction in reference to X_HOME
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, 0b1100 << TMC4361A_HOME_EVENT_SHIFT);
}
else {
// if active low, HOME_REF = 0 indicates negative direction in reference to X_HOME
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, 0b0011 << TMC4361A_HOME_EVENT_SHIFT);
}
// use stop left as home
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, TMC4361A_STOP_LEFT_IS_HOME_MASK);
}
else {
if (polarity != 0) {
// If the right switch is active high, HOME_REF = 0 indicates positive direction in reference to X_HOME
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, 0b0011 << TMC4361A_HOME_EVENT_SHIFT);
}
else {
// if active low, HOME_REF = 0 indicates negative direction in reference to X_HOME
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, 0b1100 << TMC4361A_HOME_EVENT_SHIFT);
}
// use stop right as home
tmc4361A_setBits(tmc4361A, TMC4361A_REFERENCE_CONF, TMC4361A_STOP_RIGHT_IS_HOME_MASK);
}
// have a safety margin around home
tmc4361A_setBits(tmc4361A, TMC4361A_HOME_SAFETY_MARGIN, safety_margin);
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_readLimitSwitches() reads the limit switches and returns their state in the two low bits of a byte.
00 - both not pressed
01 - right switch pressed
10 - left
11 - both
OPERATION: We read the status register, mask the irrelevant bits, and shift the relevant bits down
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
RETURNS:
uint8_t result: Byte containing the button state in the last two bits
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES:
uint32_t i_datagram: data received from the tmc4361A
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
uint8_t tmc4361A_readLimitSwitches(TMC4361ATypeDef *tmc4361A) {
// Read both limit switches. Set bit 0 if the left switch is pressed and bit 1 if the right switch is pressed
uint32_t i_datagram = 0;
// Get the datagram
i_datagram = tmc4361A_readInt(tmc4361A, TMC4361A_STATUS);
// Mask off everything except the button states
i_datagram &= (TMC4361A_STOPL_ACTIVE_F_MASK | TMC4361A_STOPR_ACTIVE_F_MASK);
// Shift the button state down to bits 0 and 1
i_datagram >>= TMC4361A_STOPL_ACTIVE_F_SHIFT;
// Get rid of the high bits
uint8_t result = i_datagram & 0xff;
return result;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_readSwitchEvent() checks whether there was a switch event and returns their state in the two low bits of a byte.
00 - both not pressed
01 - left switch pressed
10 - right
11 - both
OPERATION: We read the events register, mast the irrelevant bits, and shift the relevant bits down
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
RETURNS:
uint8_t result: Byte containing the button state in the last two bits
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES:
uint32_t i_datagram: data received from the tmc4361A
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
uint8_t tmc4361A_readSwitchEvent(TMC4361ATypeDef *tmc4361A) {
// Read both limit switches. Set bit 0 if the left switch is pressed and bit 1 if the right switch is pressed
unsigned long i_datagram = 0;
unsigned long address = TMC4361A_EVENTS;
// Get the datagram
i_datagram = tmc4361A_readInt(tmc4361A, address);
// Mask off everything except the button states
i_datagram &= (TMC4361A_STOPL_EVENT_MASK | TMC4361A_STOPR_EVENT_MASK);
// Shift the button state down to bits 0 and 1
i_datagram >>= TMC4361A_STOPL_EVENT_SHIFT;
// Get rid of the high bits
uint8_t result = i_datagram & 0xff;
return result;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_setHome() writes the latched position to the motor driver struct.
OPERATION: We read the latched value from the TMC4361 and write it to the struct
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
RETURNS: None
INPUTS / OUTPUTS: None
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are written to the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_setHome(TMC4361ATypeDef *tmc4361A) {
tmc4361A->xhome = tmc4361A_readInt(tmc4361A, TMC4361A_X_LATCH_RD);
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_moveToExtreme() moves a carriage to one of the extremes (min x or max x) and writes the min/max positions to the struct. Use the RGHT_DIR and LEFT_DIR macros as direction arguements
OPERATION: First, move away from any limit switches to ensure an accurate reading of the extreme. Ensure the velocity has the correct sign. Then we clear events and start moving until we hit a switch event. We latch the position value and write it to the struct.
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
RETURNS: None
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES:
uint32_t eventstate: data from the events register
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from and written to the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_moveToExtreme(TMC4361ATypeDef *tmc4361A, int32_t vel, int8_t dir) {
uint8_t eventstate = tmc4361A_readLimitSwitches(tmc4361A);
vel = abs(vel);
// If we are moving right and already are at the right switch, back up a bit
if (dir == RGHT_DIR && eventstate == RGHT_SW) {
tmc4361A_readInt(tmc4361A, TMC4361A_EVENTS);
// rotate puts us in velocity mode
tmc4361A_setSpeed(tmc4361A, vel * LEFT_DIR);
while (eventstate == RGHT_SW) {
eventstate = tmc4361A_readLimitSwitches(tmc4361A);
delay(5);
}
delay(300);
}
// If we are moving left and already are at the left switch, back up
else if (dir == LEFT_DIR && eventstate == LEFT_SW) {
tmc4361A_readInt(tmc4361A, TMC4361A_EVENTS);
tmc4361A_setSpeed(tmc4361A, vel * RGHT_DIR);
while (eventstate == LEFT_SW) {
eventstate = tmc4361A_readLimitSwitches(tmc4361A);
delay(5);
}
delay(300);
}
// Move to the right to find xmax
// Move the direction specified
vel *= dir;
// Read the events register before moving
tmc4361A_readInt(tmc4361A, TMC4361A_EVENTS);
tmc4361A_setSpeed(tmc4361A, vel);
// Keep moving until we get a switch event or switch status
while (((eventstate != RGHT_SW) && (dir == RGHT_DIR)) || ((eventstate != LEFT_SW) && (dir == LEFT_DIR))) {
delay(5);
eventstate = tmc4361A_readSwitchEvent(tmc4361A );
eventstate |= tmc4361A_readLimitSwitches(tmc4361A);
}
// When we do get a switch event, write the latched X
if (dir == RGHT_DIR) {
tmc4361A->xmax = tmc4361A_readInt(tmc4361A, TMC4361A_X_LATCH_RD);
tmc4361A_writeInt(tmc4361A, TMC4361A_X_TARGET, tmc4361A->xmax);
}
else {
tmc4361A->xmin = tmc4361A_readInt(tmc4361A, TMC4361A_X_LATCH_RD);
tmc4361A_writeInt(tmc4361A, TMC4361A_X_TARGET, tmc4361A->xmin);
}
return;
}
/*
-----------------------------------------------------------------------------
DESCRIPTION: tmc4361A_sRampInit() writes the ramp parameters to the TMC4361A.
OPERATION: We read the data from the shared struct and write them one at a time to the tmc4361A
ARGUMENTS:
TMC4361ATypeDef *tmc4361A: Pointer to a struct containing motor driver info
RETURNS: None
INPUTS / OUTPUTS: The CS pin and SPI MISO and MOSI pins output, input, and output data respectively
LOCAL VARIABLES: None
SHARED VARIABLES:
TMC4361ATypeDef *tmc4361A: Values are read from and written to the struct
GLOBAL VARIABLES: None
DEPENDENCIES: tmc4316A.h
-----------------------------------------------------------------------------
*/
void tmc4361A_sRampInit(TMC4361ATypeDef *tmc4361A) {
tmc4361A_setBits(tmc4361A, TMC4361A_RAMPMODE, TMC4361A_RAMP_POSITION | TMC4361A_RAMP_SSHAPE); // positioning mode, s-shaped ramp
tmc4361A_rstBits(tmc4361A, TMC4361A_GENERAL_CONF, TMC4361A_USE_ASTART_AND_VSTART_MASK); // keep astart, vstart = 0
tmc4361A_writeInt(tmc4361A, TMC4361A_BOW1, tmc4361A->rampParam[BOW1_IDX]); // determines the value which increases the absolute acceleration value.
tmc4361A_writeInt(tmc4361A, TMC4361A_BOW2, tmc4361A->rampParam[BOW2_IDX]); // determines the value which decreases the absolute acceleration value.
tmc4361A_writeInt(tmc4361A, TMC4361A_BOW3, tmc4361A->rampParam[BOW3_IDX]); // determines the value which increases the absolute deceleration value.
tmc4361A_writeInt(tmc4361A, TMC4361A_BOW4, tmc4361A->rampParam[BOW4_IDX]); // determines the value which decreases the absolute deceleration value.
tmc4361A_writeInt(tmc4361A, TMC4361A_AMAX, tmc4361A->rampParam[AMAX_IDX]); // max acceleration
tmc4361A_writeInt(tmc4361A, TMC4361A_DMAX, tmc4361A->rampParam[DMAX_IDX]); // max decelleration
tmc4361A_writeInt(tmc4361A, TMC4361A_ASTART, tmc4361A->rampParam[ASTART_IDX]); // initial acceleration
tmc4361A_writeInt(tmc4361A, TMC4361A_DFINAL, tmc4361A->rampParam[DFINAL_IDX]); // final decelleration
tmc4361A_writeInt(tmc4361A, TMC4361A_VMAX, tmc4361A->rampParam[VMAX_IDX]); // max speed
return;
}