teemuatlut / TMC2130Stepper

Arduino library for Trinamic TMC2130 Stepper driver
MIT License
159 stars 50 forks source link

Looking for Help With StallGuard #58

Open Legohead259 opened 5 years ago

Legohead259 commented 5 years ago

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!

dmitrif commented 5 years ago

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 notifications@github.com 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

teemuatlut commented 5 years ago

To get the stallguard flag

bool sg_status = driver.stallguard();

To get the stallguard measurement

uint16_t sg_measurement = driver.sg_result();
dmitrif commented 5 years ago

Learned something new, thanks @teemuatlut!


Dmitri Farkov 647.898.5054

On Thu, 8 Nov 2018 at 12:02, teemuatlut notifications@github.com 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 .

pilhuhn commented 5 years ago

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

teemuatlut commented 5 years ago

Yes. AVR timer interrupt with direct port manipulation:

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