Today we will wire up a TMC4361A-EVAL + TMC2130-EVAL combination to drive a stepper motor closed loop with an Arduino Uno. The encoder used for this test has a resolution of 10.000 cpr respective a resolution of 40.000.

Preparation

For this tutorial the Eselsbruecke got a soldered connection between +5V_USB (pin 5) to +5V_VM (pin 42) to get +5V for the encoder. You can use jumper wires as well but make sure the connection is properly.

Wiring

The wiring is very simple. You will need 9 jumper wires. To make the wiring more easy you can print out the TMC5130-EVAL_Pinning.pdf (used from a previous blog entry) and cut out the template to mount it on the connector header of the TMC4361-EVAL (As seen on illustration 4). As a reference you can use the TMC5130-Eval_v15_01_Schematic.pdf. Here you’ll find the signals that are on each pin. The configuration is documented in the comment section of the Arduino code.

Arduino Code

The Arduino Code below does not need any additional libraries. The SPI library comes with the Arduino IDE. The program initializes the TMC2130 thru the TMC4361A-EVAL (cover datagram) and the TMC4361 itself. It will rotate a 200 full step motor 2 revolutions to the one and 2 revolutions to the other direction depending on the wiring of the stepper motor. Please use either the TMC4361 and TMC2130 datasheets as a reference for the different registers (Download links below).

Arduino TMC4361 code example

Arduino

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

#include <SPI.h>

#include "TMC4361A_Register.h"

/* The trinamic TMC4361 motor controller operates through an

* SPI interface. Each datagram is sent to the device as an address byte

14 Comments

Please check the datasheet chapter 3. SPI Interfacing.
All registers that are readable simply need to be send with its corresponding address with any dummy data. An example can be found in the datasheet on page 17 (datasheet revision 1.21).

This is a .tpc file. If you are using the Landungsbrücke or Startrampe you can use our TMCL IDE to start the PC/Host host Tool you’ll find in the menu entry Tools.
Within the Tool click on the TMCL/PC menu entry and select Options… –> Module Assignments….
Now you need to assign the listed module on the left to the Assigned modules on the right, cope to code and edit the first line of the above .tpc file with the generated line.

If you do not use the Landungsbrücke or Startrampe you can use the .tpc file to help yourself on editing the code. All WMCcommands mean write to micro controller. Those are essentially the SPI commands.

I have set up the platform with my own micro controller, and test the source code with above, but now the problem is that I need the similar source code for Step/Dir mode to verify the chip & driver performance. So right now maybe it’s not possible to get the hardware Landungsbrücke or Startrampe from trinamic.

I have summarized 5 questions below. Hopefully you can help me on this..

1. Under SPI mode Max speed.
Based on my hardware:
External clock: 16Mhz
Encoder resolution: 500 cpr
Stepper motor : 200 step per revolution
a. How to calculate the max speed limit VMAX in pps?
b. Based on the sample code (SPI mode),
sendData(0xA4,0x079A8000); // VMAX = 400.000 pps （equals to 120 rpm?）
079A8000 equals 489304.00000000
This value how to match 400.000pps. What’s the formula?
c. When I test the speed with my existing hardware (described as above), I measure the actual motor speed is around 570 rpm, not same to the sample 120 rpm (400.000 pps).
Is it any hardware or parameter I need to set differently due to the hardware difference?
2. Motor engaged status
During my testing stage, I noticed that the moto engaged status (when the motor shaft become engaged) is related to 2 registers below.
0x07 0x00400000 & 0x54 0x00009C40
But how to get back the motor engaged/disengaged status? Can you show me the register?
3. The last question is I want to confirm is that from the SPI mode sample code: the encoder resolution 10.000cpr
This encoder is 10cpr or 10,000cpr?
I guess it is supposed to be 10cpr, but its resolution seems too low, and this type of encoder is very rare, so a bit unbelievable.
I am a beginner with the Trinamic Chip, if whatever statement I made is not clear or wrong , please let me know.. Thanks.

If any information you want to know about my platform, just let me know.
Thanks a lot..

Hi, Lars Jaskulski!
Am I missing something, but can`t find the type and model of the incremental encoder… I am trying but only text that I find is: “The encoder used for this test has a resolution of 10.000 cpr respective a resolution of 40.000.”.
And if it is possible, explain to me (us) the difference between the two data: 10x10e3 cpr and 40x10e3.
Thank you.
Regards,
Predrag Pesic.

Yes. First the controller will adapt automatically the current to overcome the load condition by maintaining the target velocity. If the physics of the motor are exceeded, with more load than the motor can handle with set maximum current, the motor will reduce velocity as long as the overload condition happens. As soon as the overload condition is overcome, the motor will speed up to catch up the “lost” time.

Hope that answers your question sufficient. Let us know if you need further assistance.