-
Notifications
You must be signed in to change notification settings - Fork 6
/
Attiny85_firmware_v3.ino
executable file
·78 lines (74 loc) · 2.49 KB
/
Attiny85_firmware_v3.ino
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
// Needs TMC2208Stepper library by teemuatlut
#include <TMC2208Stepper.h>
// Define pins
#define EN_PIN 2 // LOW: Driver enabled. HIGH: Driver disabled
#define rxPin 3
#define txPin 0
#define input_enable_motors 1
TMC2208Stepper driver = TMC2208Stepper(rxPin, txPin); // Create driver and use
// Software Serial for communication
void setDriversInternal_ref(int current_mA){
driver.push(); // Reset registers
driver.pdn_disable(true); // Use PDN/UART pin for communication
driver.mstep_reg_select(true);
driver.microsteps(32);
driver.I_scale_analog(false); // Use internal voltage reference
driver.rms_current(current_mA);// Set driver current
driver.toff(5); // Enable driver in software
driver.blank_time(24);
driver.intpol(1);
driver.TPOWERDOWN(128); // ~2s until driver lowers to hold current
//driver.hysterisis_start(3);
//driver.hysterisis_end(2);
//driver.pwm_lim(12);
//driver.pwm_reg(8);
driver.pwm_autograd(1);
driver.pwm_autoscale(1);
driver.pwm_freq(1);
//driver.pwm_grad(14);
//driver.pwm_ofs(36);
driver.en_spreadCycle(false);
driver.GSTAT(0b111); // Clear
}
void setDriversExternal_ref(){
driver.push(); // Reset registers
driver.pdn_disable(true); // Use PDN/UART pin for communication
driver.mstep_reg_select(true);
driver.microsteps(32);
//driver.IHOLD_IRUN(0x1F10); // Irms = (Vref * 1.768A) / 2.5V = Vref * 0.707
driver.IHOLD_IRUN(0x1008); // Irms = Vref * 0.37565
driver.I_scale_analog(true);
driver.internal_Rsense(false);
driver.toff(3); // Enable driver in software
driver.blank_time(24);
driver.intpol(1);
driver.TPOWERDOWN(128); // ~2s until driver lowers to hold current
driver.hysterisis_start(3);
driver.hysterisis_end(3);
//driver.pwm_lim(12);
driver.pwm_autograd(1);
driver.pwm_autoscale(1);
driver.pwm_freq(1);
driver.pwm_reg(5);
driver.pwm_grad(14);
driver.pwm_ofs(36);
driver.en_spreadCycle(false);
driver.GSTAT(0b111); // Clear
}
void setup() {
pinMode(input_enable_motors, INPUT);
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, HIGH); // Disable driver in hardware
driver.beginSerial(9600);
setDriversExternal_ref();
//setDriversInternal_ref(200);// Set driver current 200mA
}
void loop() {
delay(500);
if(digitalRead(input_enable_motors)){
digitalWrite(EN_PIN, LOW); // Enable driver in hardware
}
else {
digitalWrite(EN_PIN, HIGH); // Disable driver in hardware
}
}