-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with Stallguard #75
Comments
The library comes with a proven example for testing the stallGuard feature. I'd suggest you start there. |
Thanks for the quick response! `#define MAX_SPEED 40 // In timer value
#define MIN_SPEED 1000
#define STALL_VALUE 0 // [-64..63]
// Note: You also have to connect GND, 5V and VM.
// A connection diagram can be found in the schematics.
#define EN_PIN 7 // Nano v3: 16 Mega: 38 //enable (CFG6)
#define DIR_PIN 6 // 19 55 //direction
#define STEP_PIN 5 // 18 54 //step
#define CS_PIN 10 // 17 64 //chip select
#include <SPI.h>
#include <TMC2130Stepper.h>
#include <TMC2130Stepper_REGDEFS.h>
TMC2130Stepper driver = TMC2130Stepper(EN_PIN, DIR_PIN, STEP_PIN, CS_PIN);
bool vsense;
uint16_t rms_current(uint8_t CS, float Rsense = 0.11) {
return (float)(CS+1)/32.0 * (vsense?0.180:0.325)/(Rsense+0.02) / 1.41421 * 1000;
}
void setup() {
//init serial port
{
Serial.begin(9600); //init serial port and set baudrate
Serial.println("\nStart...");
driver.begin();
}
//set TMC2130 config
{
driver.rms_current(600); // mA
//driver.microsteps(16);
driver.diag1_stall(1);
driver.diag1_active_high(1);
driver.coolstep_min_speed(0xFFFFF); // 20bit max
driver.THIGH(0);
driver.semin(5);
driver.semax(2);
driver.sedn(0b01);
driver.sg_stall_value(STALL_VALUE);
}
// Set stepper interrupt
{
cli();//stop interrupts
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
OCR1A = 256;// = (16*10^6) / (1*1024) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS11 bits for 8 prescaler
TCCR1B |= (1 << CS11);// | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei();//allow interrupts
}
//TMC2130 outputs on (LOW active)
digitalWrite(EN_PIN, LOW);
//vsense = driver.vsense();
}
ISR(TIMER1_COMPA_vect){
digitalWrite(STEP_PIN, HIGH);
digitalWrite(STEP_PIN, LOW);
}
bool dir = false;
void loop()
{
for(uint16_t i=0; i<51200; i++){
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(10);
static uint32_t last_time=0;
uint32_t ms = millis();
while(Serial.available() > 0) {
int8_t read_byte = Serial.read();
if (read_byte == '0') { TIMSK1 &= ~(1 << OCIE1A); digitalWrite( EN_PIN, HIGH ); }
else if (read_byte == '1') { TIMSK1 |= (1 << OCIE1A); digitalWrite( EN_PIN, LOW ); }
else if (read_byte == '+') if (OCR1A > MAX_SPEED) OCR1A -= 20;
else if (read_byte == '-') if (OCR1A < MIN_SPEED) OCR1A += 20;
}
if((ms-last_time) > 100) //run every 0.1s if >100
{
last_time = ms;
uint32_t drv_status = driver.DRV_STATUS();
Serial.print("0 ");
Serial.print((drv_status & SG_RESULT_bm)>>SG_RESULT_bp , DEC);
Serial.print(" ");
Serial.println(rms_current((drv_status & CS_ACTUAL_bm)>>CS_ACTUAL_bp), DEC);
}
}
if (dir) {
Serial.println("Dir -> 0");
driver.shaft_dir(0);
} else {
Serial.println("Dir -> 1");
driver.shaft_dir(1);
}
dir = !dir;
}` |
The motor doesn't stop because the code doesn't react to activated stallGaurd signal. |
I'm quite confused with what you mean with 'set the pins before you start modifying the example". And btw the motor has been turning the way I want. |
You should first try to get the example working as is and then start expanding from there. |
did you manage to get the example to work? |
I didn't, I stopped trying since I didn't have time anymore... |
This doesn't work for me either. I'm getting stallguard measurements before moving the motor, but as soon as I do as single step, either via digitalWrite(STEP_PIN, HIGH); or by using the AccelStepper library's stepper.run() method to move the motor, I stop receiving any stallguard measurements. The only way to get measurements again is resetting the whole device, and this lasts until the motor moves a step. |
Hi!
First of all thank you for your amazing work!
Now my problem: I'm trying to get stallguard working with my arduino nano and fysetc tmc2130. I got the "simple" example working fairly quickly, but I added the "driver.stallguard" and "driver.sg_result" as you can see in my code below. (I also disabled stealthchop) Now when I try it out, I get back "Stalling" and "0" in my serial monitor, nothing changes even when I block the motor. However when I turn down the 12V power from the VM pin (the arduino is powered through USB), I get back "Not stalling" and "0".
I don't really know what I'm doing wrong, I've been experimenting with this library for a quit a few days now, I even remember using the same functions and getting back different numbers, but they weren't really correct. So I'm kind of at a loss right now and I hope you can help me ^^
Kind regards.
The text was updated successfully, but these errors were encountered: