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.
pull/1/head
AnHardt 9 years ago
committed by Richard Wackerbarth
parent
commit
fd0e81b0c7
  1. 1
      Marlin/Configuration.h
  2. 17
      Marlin/buzzer.cpp
  3. 1
      Marlin/configurator/config/Configuration.h
  4. 1
      Marlin/example_configurations/Felix/Configuration.h
  5. 1
      Marlin/example_configurations/Felix/Configuration_DUAL.h
  6. 1
      Marlin/example_configurations/Hephestos/Configuration.h
  7. 1
      Marlin/example_configurations/K8200/Configuration.h
  8. 1
      Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h
  9. 1
      Marlin/example_configurations/RigidBot/Configuration.h
  10. 1
      Marlin/example_configurations/SCARA/Configuration.h
  11. 1
      Marlin/example_configurations/WITBOX/Configuration.h
  12. 1
      Marlin/example_configurations/adafruit/ST7565/Configuration.h
  13. 1
      Marlin/example_configurations/delta/biv2.5/Configuration.h
  14. 1
      Marlin/example_configurations/delta/generic/Configuration.h
  15. 1
      Marlin/example_configurations/delta/kossel_mini/Configuration.h
  16. 1
      Marlin/example_configurations/delta/kossel_pro/Configuration.h
  17. 1
      Marlin/example_configurations/makibox/Configuration.h
  18. 1
      Marlin/example_configurations/tvrrug/Round2/Configuration.h

1
Marlin/Configuration.h

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

17
Marlin/buzzer.cpp

@ -9,8 +9,21 @@
lcd_buzz(duration, freq);
#elif defined(BEEPER) && BEEPER >= 0 // on-board buzzers have no further condition
SET_OUTPUT(BEEPER);
tone(BEEPER, freq, duration);
delay(duration);
#ifdef SPEAKER // a speaker needs a AC ore a pulsed DC
//tone(BEEPER, freq, duration); // needs a PWMable pin
unsigned int delay = 1000000 / freq / 2;
int i = duration * freq / 1000;
while (i--) {
WRITE(BEEPER,HIGH);
delayMicroseconds(delay);
WRITE(BEEPER,LOW);
delayMicroseconds(delay);
}
#else // buzzer has its own resonator - needs a DC
WRITE(BEEPER, HIGH);
delay(duration);
WRITE(BEEPER, LOW);
#endif
#else
delay(duration);
#endif

1
Marlin/configurator/config/Configuration.h

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

1
Marlin/example_configurations/Felix/Configuration.h

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

1
Marlin/example_configurations/Felix/Configuration_DUAL.h

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

1
Marlin/example_configurations/Hephestos/Configuration.h

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

1
Marlin/example_configurations/K8200/Configuration.h

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

1
Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h

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

1
Marlin/example_configurations/RigidBot/Configuration.h

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

1
Marlin/example_configurations/SCARA/Configuration.h

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

1
Marlin/example_configurations/WITBOX/Configuration.h

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

1
Marlin/example_configurations/adafruit/ST7565/Configuration.h

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

1
Marlin/example_configurations/delta/biv2.5/Configuration.h

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

1
Marlin/example_configurations/delta/generic/Configuration.h

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

1
Marlin/example_configurations/delta/kossel_mini/Configuration.h

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

1
Marlin/example_configurations/delta/kossel_pro/Configuration.h

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

1
Marlin/example_configurations/makibox/Configuration.h

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

1
Marlin/example_configurations/tvrrug/Round2/Configuration.h

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

Loading…
Cancel
Save