Browse Source

Distinguish between BUZZER and SPEAKER (PR#2513)

A speaker needs a AC or a pulsed DC to make a sound, a buzzer only needs a DC.
A buzzer has it's own resonator. It works in most cases to feed the buzzer with a pulsed DC, but the sound will not be as loud as with pure DC.

There seem to be boards where the BEEPER-pin is not able to handle a PWM. Obviously intended for a buzzer.
To make these board able to handle a speaker

* replace the PWM based tone()-function again with a on-delay-off-delay loop.

Hopefully the last time I touch the beeper code.
AnHardt 10 years ago
parent
commit
fd0e81b0c7

+ 1
- 0
Marlin/Configuration.h View File

@@ -647,6 +647,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
647 647
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
648 648
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
649 649
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
650
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
650 651
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
651 652
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
652 653
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 15
- 2
Marlin/buzzer.cpp View File

@@ -9,8 +9,21 @@
9 9
         lcd_buzz(duration, freq);
10 10
       #elif defined(BEEPER) && BEEPER >= 0 // on-board buzzers have no further condition
11 11
         SET_OUTPUT(BEEPER);
12
-        tone(BEEPER, freq, duration);
13
-        delay(duration);
12
+        #ifdef SPEAKER // a speaker needs a AC ore a pulsed DC
13
+          //tone(BEEPER, freq, duration); // needs a PWMable pin
14
+          unsigned int delay = 1000000 / freq / 2;
15
+          int i = duration * freq / 1000;
16
+          while (i--) {
17
+            WRITE(BEEPER,HIGH);
18
+            delayMicroseconds(delay);
19
+            WRITE(BEEPER,LOW);
20
+            delayMicroseconds(delay);
21
+           }
22
+        #else // buzzer has its own resonator - needs a DC
23
+          WRITE(BEEPER, HIGH);
24
+          delay(duration);
25
+          WRITE(BEEPER, LOW);
26
+        #endif
14 27
       #else
15 28
         delay(duration);
16 29
       #endif

+ 1
- 0
Marlin/configurator/config/Configuration.h View File

@@ -647,6 +647,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
647 647
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
648 648
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
649 649
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
650
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
650 651
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
651 652
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
652 653
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/Felix/Configuration.h View File

@@ -630,6 +630,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
630 630
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
631 631
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
632 632
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
633
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
633 634
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
634 635
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
635 636
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/Felix/Configuration_DUAL.h View File

@@ -587,6 +587,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
587 587
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
588 588
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
589 589
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
590
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
590 591
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
591 592
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
592 593
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/Hephestos/Configuration.h View File

@@ -639,6 +639,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the logic
639 639
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
640 640
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
641 641
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
642
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
642 643
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
643 644
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
644 645
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/K8200/Configuration.h View File

@@ -635,6 +635,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
635 635
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
636 636
 #define ULTIMAKERCONTROLLER // K8200: for Display VM8201 // as available from the Ultimaker online store.
637 637
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
638
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
638 639
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
639 640
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
640 641
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h View File

@@ -647,6 +647,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
647 647
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
648 648
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
649 649
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
650
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
650 651
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
651 652
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
652 653
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/RigidBot/Configuration.h View File

@@ -627,6 +627,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
627 627
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
628 628
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
629 629
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
630
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
630 631
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
631 632
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
632 633
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/SCARA/Configuration.h View File

@@ -655,6 +655,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
655 655
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
656 656
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
657 657
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
658
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
658 659
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
659 660
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
660 661
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/WITBOX/Configuration.h View File

@@ -639,6 +639,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the logic
639 639
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
640 640
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
641 641
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
642
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
642 643
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
643 644
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
644 645
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/adafruit/ST7565/Configuration.h View File

@@ -647,6 +647,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
647 647
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
648 648
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
649 649
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
650
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
650 651
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
651 652
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
652 653
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/delta/biv2.5/Configuration.h View File

@@ -767,6 +767,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the logic
767 767
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
768 768
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
769 769
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
770
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
770 771
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
771 772
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
772 773
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/delta/generic/Configuration.h View File

@@ -767,6 +767,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the logic
767 767
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
768 768
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
769 769
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
770
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
770 771
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
771 772
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
772 773
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/delta/kossel_mini/Configuration.h View File

@@ -771,6 +771,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
771 771
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
772 772
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
773 773
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
774
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
774 775
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
775 776
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
776 777
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/delta/kossel_pro/Configuration.h View File

@@ -766,6 +766,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
766 766
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
767 767
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
768 768
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
769
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
769 770
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
770 771
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
771 772
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/makibox/Configuration.h View File

@@ -650,6 +650,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
650 650
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
651 651
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
652 652
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
653
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
653 654
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
654 655
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
655 656
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

+ 1
- 0
Marlin/example_configurations/tvrrug/Round2/Configuration.h View File

@@ -641,6 +641,7 @@ const bool Z_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the logic
641 641
 //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking
642 642
 //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
643 643
 //#define ULTIPANEL  //the UltiPanel as on Thingiverse
644
+//#define SPEAKER // The sound device is a speaker - not a buzzer. A buzzer resonates with his own frequency.
644 645
 //#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click
645 646
 //#define LCD_FEEDBACK_FREQUENCY_HZ 1000         // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click
646 647
                                                  // 0 to disable buzzer feedback. Test with M300 S<frequency Hz> P<duration ms>

Loading…
Cancel
Save