Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: OpenCM 9.04, best way to beep?

  1. #1

    OpenCM 9.04, best way to beep?

    I don't have the data sheet for STM32F103 or the Maple libraries here.
    I notice that the OpenCM software doesn't include the tone() functions from the Arduino.
    For debugging it's totally helpful to be able to output clicks and beeps from a piezo buzzer (with appropriate diode/resistor protection.)

    A simple analogWrite() doesn't work very well, because the frequency used for PWM is fairly low.

    I'm thinking the STM32 has lots of timers, and there's probably an unused timer that I can tie to some output pin (ideally one I'm already breaking out on the main board I have ...) and make it beep at the frequency I want.

    Anyone got any good pointers?

  2. #2

    Re: OpenCM 9.04, best way to beep?

    Seems like the HardwareTimer object can be used to set the frequency on a per-pin-group basis?

    http://support.robotis.com/en/softwa...m/lib/gpio.htm

  3. #3

    Re: OpenCM 9.04, best way to beep?

    Except pinMode(16, PWM) and analogWrite(16, whatever) doesn't do anything. It just floats.
    digitalWrite() to the pin, or using togglePin(), can wiggle it just fine with the OUTPUT pinMode().

    Because, you know, why would things work as documented?

  4. #4

    Re: OpenCM 9.04, best way to beep?

    Pins 0 through 13 support PWM, 14 and up not. So, not as bad as I thought, just under-documented in this location.
    (It's hard to find the right location where they document these things ...)

  5. #5

    Re: OpenCM 9.04, best way to beep?

    Except when I set the HardwareTimer period to 400, it ends up ... floating in the middle, with a small wiggle up and down?

    I'll live with the default frequency of 1.1 kHz. It's better than silence. And next year, I'm certainly going Teensy and/or RPi!

  6. #6

    Re: OpenCM 9.04, best way to beep?

    For what it is worth, for a long time I used some pretty basic functions to make beeps.
    Code:
    //==============================================================================
    //    SoundNoTimer - Quick and dirty tone function to try to output a frequency
    //            to a speaker for some simple sounds.
    //==============================================================================
    #ifdef SOUND_PIN
    void SoundNoTimer(unsigned long duration,  unsigned int frequency)
    {
    #ifndef KINETISK
    #ifdef __AVR__
      volatile uint8_t *pin_port;
      volatile uint8_t pin_mask;
    #else
      volatile uint32_t *pin_port;
      volatile uint16_t pin_mask;
    #endif
      long toggle_count = 0;
      long lusDelayPerHalfCycle;
    
      // Set the pinMode as OUTPUT
      pinMode(SOUND_PIN, OUTPUT);
    
      pin_port = portOutputRegister(digitalPinToPort(SOUND_PIN));
      pin_mask = digitalPinToBitMask(SOUND_PIN);
    
      toggle_count = 2 * frequency * duration / 1000;
      lusDelayPerHalfCycle = 1000000L/(frequency * 2);
    
      // if we are using an 8 bit timer, scan through prescalars to find the best fit
      while (toggle_count--) {
        // toggle the pin
        *pin_port ^= pin_mask;
    
        // delay a half cycle
        delayMicroseconds(lusDelayPerHalfCycle);
      }    
      *pin_port &= ~(pin_mask);  // keep pin low after stop
    }
    
    void MSound(byte cNotes, ...)
    {
      va_list ap;
      unsigned int uDur;
      unsigned int uFreq;
      va_start(ap, cNotes);
    
      while (cNotes > 0) {
        uDur = va_arg(ap, unsigned int);
        uFreq = va_arg(ap, unsigned int);
        SoundNoTimer(uDur, uFreq);
        cNotes--;
      }
      va_end(ap);
    }
    Assuming my cut and paste. Again this is rather simple
    Example in Phoenix when the power on command is given:
    MSound(3, 60, 2000, 80, 2250, 100, 2500);

    I kept meaning to convert to timer object and the like but never got around with it. Now on some other boards I am going to make use of the DAC and use the audio library and/or talky.

  7. #7

    Re: OpenCM 9.04, best way to beep?

    Ah, yes! I need the beep to be asynchronous, because it's also driving an IK engine and an airsoft gun and polling various bits of status and reading remote control and sending telemetry ...

  8. #8

    Re: OpenCM 9.04, best way to beep?

    Aaaand now I'm getting Board Not Responding from the OpenCM, both on Windows and Linux.

  9. #9
    Join Date
    May 2016
    Location
    White Plains, NY
    Posts
    122
    Images
    1
    Rep Power
    10

    Re: OpenCM 9.04, best way to beep?

    I was scrounging around on Amazon the other day and found my new favorite component:
    https://www.amazon.com/gp/product/B0...?ie=UTF8&psc=1

    Its a 500Hz buzzer, you just turn it off and on "(with appropriate diode/resistor protection.)".

    With a couple of layers of electrical tape over the opening it becomes suitable for indoor use.

    With the Teensy you get its four Interval Timers and programmable interrupt levels. I've derived a class from the Teensy's IntervalTimer class I call OneShot that's very useful for things like beeps and morse-code alerts,

    Down the road I want to add a small audio amp driven by a DAC and DMA, playing canned waveforms. But for now, 500Hz is just fine.

  10. #10

    Re: OpenCM 9.04, best way to beep?

    Yeah, I have some of these, too:
    https://www.digikey.com/product-deta...458-ND/5011393
    It makes a very distinctive "chweeeeeeep" sound :-)

    The point of beeps for debugging is that different small ticks and frequencies can let me know what parts of the system are doing what. Listening to a somewhat-musical illustration of what's going on is often very helpful to debug things that are too fast to just look at for LEDs, and that are too repetitive to do a good job of with text logging.
    Case in point: Debugging the Xbee transmission delays / batching from my Onyx X build thread... A small "tick" each time I get a packet will let me instantly hear how smooth or clunky the input stream is. The self-beeping ones are generally too slow to start/stop to be helpful for this.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question(s) AX-12A servos with OpenCM 9.04: can actuate but not read
    By corot in forum DYNAMIXEL & Robot Actuators
    Replies: 0
    Last Post: 11-06-2016, 01:00 PM
  2. Question(s) Is my OpenCM 9.04 dead? Or do are my AX-12A servos?
    By corot in forum DYNAMIXEL & Robot Actuators
    Replies: 4
    Last Post: 10-31-2016, 05:54 PM
  3. Acceleration implementation on OpenCM?
    By jomo in forum DYNAMIXEL & Robot Actuators
    Replies: 4
    Last Post: 05-19-2016, 08:18 AM
  4. OpenCM IDE (Ubuntu 14.04)
    By rasheinstein in forum Arbotix, Microcontrollers, Arduino
    Replies: 2
    Last Post: 04-12-2016, 01:47 PM
  5. Project OpenCM 9.04 - B and 18 Dynamixel AX-12A servos
    By OpenRobot in forum Power
    Replies: 2
    Last Post: 11-29-2015, 06:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •