4
4
import machine
5
5
from machine import Pin as GPIO
6
6
7
- from .TMC_2209_uart import TMC_UART
8
- from . import TMC_2209_reg as reg
7
+ from .uart import TMC_UART
8
+ from . import reg as reg
9
9
10
10
11
11
logger = logging .getLogger (__name__ )
@@ -275,8 +275,7 @@ def setMotorEnabled(self, en):
275
275
if en :
276
276
self .p_pin_en .off ()
277
277
else :
278
- self .p_pin_en .on ()
279
- logging .info ("TMC2209: Motor output active: {}" .format (en ))
278
+ self .p_pin_en .on ()
280
279
281
280
#-----------------------------------------------------------------------
282
281
# homes the motor in the given direction using stallguard
@@ -374,10 +373,8 @@ def getIScaleAnalog(self):
374
373
def setIScaleAnalog (self ,en ):
375
374
gconf = self .tmc_uart .read_int (reg .GCONF )
376
375
if (en ):
377
- logging .info ("TMC2209: activated Vref for current scale" )
378
376
gconf = self .tmc_uart .set_bit (gconf , reg .i_scale_analog )
379
377
else :
380
- logging .info ("TMC2209: activated 5V-out for current scale" )
381
378
gconf = self .tmc_uart .clear_bit (gconf , reg .i_scale_analog )
382
379
self .tmc_uart .write_reg_check (reg .GCONF , gconf )
383
380
@@ -420,10 +417,8 @@ def getInternalRSense(self):
420
417
def setInternalRSense (self ,en ):
421
418
gconf = self .tmc_uart .read_int (reg .GCONF )
422
419
if (en ):
423
- logging .info ("TMC2209: activated internal sense resistors." )
424
420
gconf = self .tmc_uart .set_bit (gconf , reg .internal_rsense )
425
421
else :
426
- logging .info ("TMC2209: activated operation with external sense resistors" )
427
422
gconf = self .tmc_uart .clear_bit (gconf , reg .internal_rsense )
428
423
self .tmc_uart .write_reg_check (reg .GCONF , gconf )
429
424
@@ -438,9 +433,6 @@ def setIRun_Ihold(self, IHold, IRun, IHoldDelay):
438
433
ihold_irun = ihold_irun | IHold << 0
439
434
ihold_irun = ihold_irun | IRun << 8
440
435
ihold_irun = ihold_irun | IHoldDelay << 16
441
- logging .info ("TMC2209: ihold_irun: " , bin (ihold_irun ))
442
- #logging.info(bin(ihold_irun))
443
- logging .info ("TMC2209: writing ihold_irun" )
444
436
self .tmc_uart .write_reg_check (reg .IHOLD_IRUN , ihold_irun )
445
437
446
438
#-----------------------------------------------------------------------
@@ -454,10 +446,10 @@ def setCurrent(self, run_current, hold_current_multiplier = 0.5, hold_current_de
454
446
Vfs = 0
455
447
456
448
if (self .getVSense ()):
457
- logging .info ("TMC2209: Vsense: 1" )
449
+ logging .debug ("TMC2209: Vsense: 1" )
458
450
Vfs = 0.180 * Vref / 2.5
459
451
else :
460
- logging .info ("TMC2209: Vsense: 0" )
452
+ logging .debug ("TMC2209: Vsense: 0" )
461
453
Vfs = 0.325 * Vref / 2.5
462
454
463
455
CS_IRun = 32.0 * 1.41421 * run_current / 1000.0 * (Rsense + 0.02 )/ Vfs - 1
@@ -471,10 +463,6 @@ def setCurrent(self, run_current, hold_current_multiplier = 0.5, hold_current_de
471
463
CS_IHold = round (CS_IHold )
472
464
hold_current_delay = round (hold_current_delay )
473
465
474
- logging .debug ("TMC2209: CS_IRun: " + str (CS_IRun ))
475
- logging .debug ("TMC2209: CS_IHold: " + str (CS_IHold ))
476
- logging .debug ("TMC2209: Delay: " + str (hold_current_delay ))
477
-
478
466
self .setIRun_Ihold (CS_IHold , CS_IRun , hold_current_delay )
479
467
480
468
#-----------------------------------------------------------------------
@@ -490,10 +478,8 @@ def getSpreadCycle(self):
490
478
def setSpreadCycle (self ,en_spread ):
491
479
gconf = self .tmc_uart .read_int (reg .GCONF )
492
480
if (en_spread ):
493
- logging .info ("TMC2209: activated Spreadcycle" )
494
481
gconf = self .tmc_uart .set_bit (gconf , reg .en_spreadcycle )
495
482
else :
496
- logging .info ("TMC2209: activated Stealthchop" )
497
483
gconf = self .tmc_uart .clear_bit (gconf , reg .en_spreadcycle )
498
484
self .tmc_uart .write_reg_check (reg .GCONF , gconf )
499
485
@@ -518,7 +504,7 @@ def setInterpolation(self, en):
518
504
else :
519
505
chopconf = self .tmc_uart .clear_bit (chopconf , reg .intpol )
520
506
521
- logging .info ("TMC2209: writing microstep interpolation setting: " + str (en ))
507
+ logging .debug ("TMC2209: writing microstep interpolation setting: " + str (en ))
522
508
self .tmc_uart .write_reg_check (reg .CHOPCONF , chopconf )
523
509
524
510
#-----------------------------------------------------------------------
@@ -543,7 +529,7 @@ def setMicrosteppingResolution(self, msres):
543
529
chopconf = int (chopconf ) & int (4043309055 )
544
530
chopconf = chopconf | msresdezimal << 24
545
531
546
- logging .info ("TMC2209: writing " + str (msres )+ " microstep setting" )
532
+ logging .debug ("TMC2209: writing " + str (msres )+ " microstep setting" )
547
533
self .tmc_uart .write_reg_check (reg .CHOPCONF , chopconf )
548
534
self .setMStepResolutionRegSelect (True )
549
535
self .readStepsPerRevolution ()
@@ -562,7 +548,7 @@ def setMStepResolutionRegSelect(self, en):
562
548
else :
563
549
gconf = self .tmc_uart .clear_bit (gconf , reg .mstep_reg_select )
564
550
565
- logging .info ("TMC2209: writing MStep Reg Select: " + str (en ))
551
+ logging .debug ("TMC2209: writing MStep Reg Select: " + str (en ))
566
552
self .tmc_uart .write_reg_check (reg .GCONF , gconf )
567
553
568
554
#-----------------------------------------------------------------------
@@ -585,7 +571,6 @@ def getStepsPerRevolution(self):
585
571
#-----------------------------------------------------------------------
586
572
def getInterfaceTransmissionCounter (self ):
587
573
ifcnt = self .tmc_uart .read_int (reg .IFCNT )
588
- logging .info ("TMC2209: Interface Transmission Counter: " + str (ifcnt ))
589
574
return ifcnt
590
575
591
576
#-----------------------------------------------------------------------
@@ -613,23 +598,13 @@ def getStallguard_Result(self):
613
598
# SG_RESULT ≤ SGTHRS*2
614
599
#-----------------------------------------------------------------------
615
600
def setStallguard_Threshold (self , threshold ):
616
-
617
- logging .info ("TMC2209: sgthrs" )
618
- logging .info (bin (threshold ))
619
-
620
- logging .info ("TMC2209: writing sgthrs" )
621
601
self .tmc_uart .write_reg_check (reg .SGTHRS , threshold )
622
602
623
603
#-----------------------------------------------------------------------
624
604
# This is the lower threshold velocity for switching
625
605
# on smart energy CoolStep and StallGuard to DIAG output. (unsigned)
626
606
#-----------------------------------------------------------------------
627
607
def setCoolStep_Threshold (self , threshold ):
628
-
629
- logging .info ("TMC2209: tcoolthrs" )
630
- logging .info (bin (threshold ))
631
-
632
- logging .info ("TMC2209: writing tcoolthrs" )
633
608
self .tmc_uart .write_reg_check (reg .TCOOLTHRS , threshold )
634
609
635
610
#-----------------------------------------------------------------------
@@ -640,10 +615,7 @@ def setCoolStep_Threshold(self, threshold):
640
615
def setStallguard_Callback (self , pin_stallguard , threshold , my_callback , min_speed = 2000 ):
641
616
642
617
self .setStallguard_Threshold (threshold )
643
- self .setCoolStep_Threshold (min_speed )
644
-
645
- logging .info ("TMC2209: setup stallguard callback" )
646
-
618
+ self .setCoolStep_Threshold (min_speed )
647
619
#GPIO.setup(pin_stallguard, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
648
620
#GPIO.add_event_detect(pin_stallguard, GPIO.RISING, callback=my_callback, bouncetime=300)
649
621
p25 = machine .Pin (pin_stallguard , machine .Pin .IN , machine .Pin .PULL_DOWN )
@@ -714,3 +686,4 @@ def getAcceleration(self):
714
686
def stop (self ):
715
687
self ._stop = True
716
688
689
+
0 commit comments