Before I release the magic smoke a 3.3v / 5v question

I’m writing a driver for the Sparkfun Sound Detector https://www.sparkfun.com/products/12642 and apparently its a little bit fussy about its power, currently I’m powering it with a lead from the 3.3 pin, what happens if I power it from the 5v pin? Do I fry the mainboard as I it outputs different voltages corresponding the different sound levels (ie I’m using an ‘A’ socket).

What is behind this question is I’m testing the driver on different mainboards (Cerberus, spider, Hydra, etc) and I’m noticing different results and while I can live with slightly different results the interrupt goes heavy with the spider compared to the other mainboards and that bothers me a bit as I’m trying to understand why. All other components used for testing are used with each mainboard (ie the same power module was used on all tests), so I’m wondering if I just need a tad more juice to smooth out the results (but without the smoke).

Thanks, ultimately this is a cool little sensor and I’m looking forward to releasing the completed and tested driver.

I haven’t looked in detail at the chip that it uses, but you absolutely do not want it outputting 3.4v or higher on an analog-in pin !

Seems to use an LM324 which is a rail-to-rail op-amp, so if you only give it 3.3v then you will be fine. If you give it 5v you’ll get up to 5v, and that’s bad, again assuming you’re using Analog-in…

@ Brett - That is what I thought as I’m using an Analog Input, but I had to ask. I have an experiment I want to run where I’m going to be throwing a boat load of readings to Azure and I also want to track loud noise events, but to use event hubs I need SSL so that rules out the Cerberus and Hydra leaving the Spider which has the lowest quality data (all my Raptor boards are in use on other experiments and I haven’t gotten any of the new boards yet as holidays got in the way).

I’m also trying to understand the differences in performance between the different mainboards as all I’m changing in each test is the mainboard (does the Spider dirty up the power compared to other mainboard models?).

The source code for my driver thus far, I still have some more testing, tweaking, tuning etc to do but if anyone sees anything that I can improve or otherwise fix please let me know.


using System;
using Microsoft.SPOT;
using GTM = Gadgeteer.Modules;
using GTI = Gadgeteer.SocketInterfaces;
using GT = Gadgeteer;

namespace Gadgeteer.Modules.BreakoutBoards
{
    /// <summary>
    ///     A .NET Gadgeteer driver for the Sparkfun Sound Detection module
    /// </summary>
    public class SoundDetector : Module
    {
        /// <summary>
        ///     Represents the delegate that is used to handle the <see cref="SoundDetector.SoundEnd" />
        ///     events.
        /// </summary>
        /// <param name="sender">The <see cref="SoundDetector" /> object that raised the event.</param>
        /// <param name="state">The state of the Sound Detector</param>
        public delegate void SoundEndEventHandler(SoundDetector sender, SoundEndEventArgs args);

        /// <summary>
        ///     Represents the delegate that is used to handle the <see cref="SoundDetector.SoundStart" />
        ///     events.
        /// </summary>
        /// <param name="sender">The <see cref="SoundDetector" /> object that raised the event.</param>
        /// <param name="level">The envelope sound voltage level</param>
        public delegate void SoundStartEventHandler(SoundDetector sender, double level);

        private readonly GTI.AnalogInput _audio; //wondering about this
        private readonly GTI.AnalogInput _envelope;
        private readonly GTI.InterruptInput OnSound;
        private TimeSpan _duration;
        private double _level;
        private SoundEndEventHandler onSoundEnd;
        private SoundStartEventHandler onSoundStart;

        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public SoundDetector(int socketNumber)
        {
            var socket = Socket.GetSocket(socketNumber, true, this, null);
            socket.EnsureTypeIsSupported('A', this);

            _envelope = GTI.AnalogInputFactory.Create(socket, Socket.Pin.Four, this);
            _audio = GTI.AnalogInputFactory.Create(socket, Socket.Pin.Five, this);

            OnSound = GTI.InterruptInputFactory.Create(socket, Socket.Pin.Three, GTI.GlitchFilterMode.On,
                GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);

            OnSound.Interrupt += _input_Interrupt;
        }

        /// <summary>
        ///     The envelope voltage returned from the sensor.
        /// </summary>
        /// <returns>The voltage value between 0.0 and 3.3</returns>
        public double EnvelopeReadVoltage()
        {
            return _envelope.ReadVoltage();
        }

        /// <summary>
        ///     The envelope proportion returned from the sensor.
        /// </summary>
        /// <returns>The value between 0.0 and 1.0</returns>
        public double EnvelopeReadProportion()
        {
            return _envelope.ReadProportion();
        }

        /// <summary>
        ///     The audio voltage returned from the sensor.
        /// </summary>
        /// <returns>The voltage value between 0.0 and 3.3</returns>
        public double AudioReadVoltage()
        {
            return _audio.ReadVoltage();
        }

        /// <summary>
        ///     The audio proportion returned from the sensor.
        /// </summary>
        /// <returns>The value between 0.0 and 1.0</returns>
        public double AudioReadProportion()
        {
            return _audio.ReadProportion();
        }

        private void _input_Interrupt(GTI.InterruptInput input, bool value)
        {
            _level = EnvelopeReadVoltage();

            if (value)
            {
                _duration = Timer.GetMachineTime();
                OnSoundStartEvent(this, _level);
            }
            else
            {
                _duration = Timer.GetMachineTime().Subtract(_duration);
                OnSoundEndEvent(this, new SoundEndEventArgs(_level, _duration));
            }
        }

        /// <summary>
        ///     Raised when the state of <see cref="SoundDetector" /> is NoDetection.
        /// </summary>
        /// <remarks>
        ///     Implement this event handler and the <see cref="SoundDetected" /> event handler
        ///     when you want to provide an action associated with sound sensor activity.
        ///     The state of the Sound Detector is passed to the <see cref="SoundSensorEventHandler" /> delegate,
        ///     so you can use the same event handler for both sound sensor states.
        /// </remarks>
        public event SoundEndEventHandler SoundEnd;

        /// <summary>
        ///     Raised when the state of <see cref="SoundDetector" /> is Detected.
        /// </summary>
        /// <remarks>
        ///     Implement this event handler and the <see cref="SoundEnded" /> event handler
        ///     when you want to provide an action associated with sound sensor activity.
        ///     Since the state of the sound sensor is passed to the <see cref="SoundSensorEventHandler" /> delegate,
        ///     you can use the same event handler for both sound sensor states.
        /// </remarks>
        public event SoundStartEventHandler SoundStart;

        /// <summary>
        ///     Raises the <see cref="SoundStart" /> event.
        /// </summary>
        /// <param name="sender">The <see cref="SoundDetector" /> that raised the event.</param>
        /// <param name="level">The sound envelope voltage level.</param>
        /// ///
        /// <param name="soundSensorState">The state of the sound sensor.</param>
        private void OnSoundStartEvent(SoundDetector sender, double level)
        {
            if (onSoundStart == null)
            {
                onSoundStart = OnSoundStartEvent;
            }

            if (Program.CheckAndInvoke(SoundStart, onSoundStart, sender, level))
            {
                SoundStart(sender, level);
            }
        }

        /// <summary>
        ///     Raises the <see cref="SoundEnd" /> event.
        /// </summary>
        /// <param name="sender">The <see cref="SoundDetector" /> that raised the event.</param>
        /// <param name="e">The event args <see cref="SoundEndEventArgs" />.</param>
        private void OnSoundEndEvent(SoundDetector sender, SoundEndEventArgs e)
        {
            if (onSoundEnd == null)
            {
                onSoundEnd = OnSoundEndEvent;
            }

            if (Program.CheckAndInvoke(SoundEnd, onSoundEnd, sender, e))
            {
                SoundEnd(sender, e);
            }
        }

        /// <summary>Event arguments for the Sound End event.</summary>
        public class SoundEndEventArgs : EventArgs
        {
            internal SoundEndEventArgs(double level, TimeSpan duration)
            {
                Level = level;
                Duration = duration;
            }

            /// <summary>
            ///     The measured envelope voltage level.
            /// </summary>
            public double Level { get; private set; }

            /// <summary>
            ///     The measured duration of the sound event from start to finish.
            /// </summary>
            public TimeSpan Duration { get; private set; }

            /// <summary>
            ///     Provides a string representation of the instance.
            /// </summary>
            /// <returns>A string describing the values contained in the object.</returns>
            public override string ToString()
            {
                return "End Sound Level: " + Level.ToString("f2") + " sound event duration: " + FormatDuration(Duration) +
                       ".";
            }

            private string FormatDuration(TimeSpan x)
            {
                return x.Days.ToString("D") + ":" + x.Hours.ToString("D2") + ":" + x.Minutes.ToString("D2") + ":" +
                       x.Seconds.ToString("D2") + "." + x.Milliseconds.ToString("D3");
            }
        }
    }
}

I am seeing a 1uf decoupling cap on their schematic. Usually this is 0.1uf and it is specifically needed for noise on the power lines. Maybe this is why you are having issues.

@ Gus - on https://learn.sparkfun.com/tutorials/sound-detector-hookup-guide?_ga=1.214429271.1362966818.1406232508 it mentions

Which is what got me thinking its a power issue, but what to do about it?

I have a couple of those PowerExt modules, so I hooked one up and my experiment is back in the game (with clean, clear, smooth power), hello Spider, SSL, Azure, Event Hubs and PowerBI, the free world can sleep safely tonight. I’ve got to get some of those new Gadgeteer Mainboards and some more power modules.

Looking at some of the breakout boards I’ve picked up lately I’m starting to think we’ve been spoiled by just good GHI design as some of these breakout boards are just finicky unforgiving little bastards, but fun.

With power for analog devices such as an ADC, I always use a small 0805 inductor with a 0.1uF cap on either side. This I find cleans up the supply nicely. I locate it very close to the power pin on the ADC IC.

@ Dave McLaughlin - I found with the AS3935 Lightning detector that using the PowerExt module made a huge difference as well with both the SPI and I2C interfaces. I had it working rather nicely with the Cerberus but everything else had some minor issues (usually with Calibration), so I tried it using the PowerExt module and everything worked (now I just need some lightning, but I’m wondering if really these chips are Lightning Defenders as the electrical storms have been parting like the Red Sea around Calgary since I got these).

Might have to figure out a way to implement your idea on a breadboard for further work on breakout boards as this seems to be a reoccurring theme.

As we are in the dry season just now, the AS3935 board is lying unused. Once it returns I plan to butcher is and add the inductor and caps to clean up the supply to it as I suspect that this is why it is not so good at detecting even close lightning the last time I tested it.

I’ve got a AS3935 Evaluation Kit on its way to me as the lightning emulator would be very helpful considering we don’t get much lightning with blizzards as we are heading into the cold season here (wish I had wet or dry seasons but both were warm, but I’d rather have Canada then anywhere else).