TMC2130Stepper icon indicating copy to clipboard operation
TMC2130Stepper copied to clipboard

Looking for Help With StallGuard

Open Legohead259 opened this issue 6 years ago • 5 comments

Good day. I've gotten the StallGuard example to work on my Arduino Mega, however, I am confused on how to properly read if the STALL flag has been triggered. I've been able to Jerry-Rig it with (drv_status & SG_RESULT_bm)>>SG_RESULT_bp <= 5 to disable the motor but I know there has to be a cleaner way to get this value. Is there a function I can call to get the STALL flag without that clunkiness?

Also, is there any better documentation on the timer interupt system that is running the motor in the StallGuard example? I'd like to implement it, but I have no idea how it works past TIMSK1 is the clock and OCR1A is the clock speed.

Thanks!

Legohead259 avatar Nov 08 '18 16:11 Legohead259

You can write a function that wraps the bitshifting to read the flag from the registry but it’s pretty standard in embedded programming so just abstract it out if needed. (See: https://home.roboticlab.eu/en/avr/registers )

For the timers / interrupts read an AVR tutorial in regards to timers and interrupts. This is not specific to this library and is common for most microprocessors implementing such interrupts. (See: https://maxembedded.com/2011/06/22/introduction-to-avr-timers/ )

On Thu, Nov 8, 2018 at 11:31 Braidan [email protected] wrote:

Good day. I've gotten the StallGuard example to work on my Arduino Mega, however, I am confused on how to properly read if the STALL flag has been triggered. I've been able to Jerry-Rig it with (drv_status & SG_RESULT_bm)>>SG_RESULT_bp <= 5 to disable the motor but I know there has to be a cleaner way to get this value. Is there a function I can call to get the STALL flag without that clunkiness?

Also, is there any better documentation on the timer interupt system that is running the motor in the StallGuard example? I'd like to implement it, but I have no idea how it works past TIMSK1 is the clock and OCR1A is the clock speed.

Thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/teemuatlut/TMC2130Stepper/issues/58, or mute the thread https://github.com/notifications/unsubscribe-auth/AAoBuBZSoHyJRsTRYD64Ls7c31K0Mhq3ks5utFxogaJpZM4YVCC3 .

--


Dmitri Farkov 647.898.5054

dmitrif avatar Nov 08 '18 16:11 dmitrif

To get the stallguard flag

bool sg_status = driver.stallguard();

To get the stallguard measurement

uint16_t sg_measurement = driver.sg_result();

teemuatlut avatar Nov 08 '18 17:11 teemuatlut

Learned something new, thanks @teemuatlut!


Dmitri Farkov 647.898.5054

On Thu, 8 Nov 2018 at 12:02, teemuatlut [email protected] wrote:

To get the stallguard flag

bool sg_status = driver.stallguard();

To get the stallguard measurement

uint16_t sg_measurement = driver.sg_result();

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/teemuatlut/TMC2130Stepper/issues/58#issuecomment-437077675, or mute the thread https://github.com/notifications/unsubscribe-auth/AAoBuNpM0C5D3rK_gHGcqYaa13yiVlNuks5utGOYgaJpZM4YVCC3 .

dmitrif avatar Nov 08 '18 17:11 dmitrif

Should the motor be turning in that example, as I see no digitalWrite(STEP_PIN,..); commands

pilhuhn avatar Jan 03 '19 16:01 pilhuhn

Yes. AVR timer interrupt with direct port manipulation:

ISR(TIMER1_COMPA_vect){
  PORTF |= 1 << 0;
  PORTF &= ~(1 << 0);
}

teemuatlut avatar Jan 03 '19 18:01 teemuatlut