Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Robert Echten

Member Since 11 Sep 2010
Offline Last Active May 15 2011 11:46 PM
-----

Posts I've Made

In Topic: Netduino Xmas tree

21 January 2011 - 01:13 AM

Robert,

You're a year early :) I love that you didn't just stop with the LEDs, but added in the holiday tunes too. Cool.

Chris


That's another (better) way to look at it ;-) Thanks for the compliment.

I managed to find the schema (see attached). Now looking for the code.

Robert :-)

In Topic: OZ-Solutions - Sheet Music

17 November 2010 - 03:45 AM

Hi Omar,

Just had a look at your player for a little holiday project I'm working on and found that some notes couldn't be heard (I guess the same thing happens with the two notes you claim to have missing in the Mission Impossible ringtone).

After some investigation, what I found was that your PlayNote method allows the duration to be longer than the period, which I understand is not allowed. If I understand it correctly PWM sets a period (the total time of one cycle in the square wave) and the duration is the total time in that period that it's ON).

This means that the duration should therefore be less than the period. However, if you make the duration the same as the period or slightly less, it still drops off (you can still hear it, but only faint). I found that a max duration of 95% of the period worked well for me. I changed your PlayNote method as follows:
        public static void PlayNote(uint frequencyInHertz, uint durationMilliseconds)
        {

            if (frequencyInHertz != 0)
            {
                uint timbre = 50; // 50% = perfect square wave.
                pwm.SetDutyCycle(timbre);

                uint period = (uint)1000000 / frequencyInHertz; // 1000,000 instead of 1,000 because SetPulse duration is in microseconds, not in milliSeconds.

                //Duration needs to be less than the period. To make sure we have at least some sound, make sure we stay below 95% of the period:
                double maxDuration = 0.95*period;
                uint duration = (uint)(durationMilliseconds <= maxDuration ? durationMilliseconds : maxDuration);
                Debug.Print("Frequency -> " + frequencyInHertz + ", Period -> " + period + ", durationMilliseconds -> " + durationMilliseconds + ", Max Duration -> " + maxDuration + ", duration -> " + duration);
                pwm.SetPulse(period, duration);
            }

            //-- Wait for note (or silence) to play out, then be quiet --
            Thread.Sleep((int)durationMilliseconds);
            pwm.SetDutyCycle(0);
        }
Hope this helps. If anyone has some suggestions or want to tell me I'm completely wrong, please feel free. I'm an experienced .Net developer, but new to Netduino/electronics, so...

Robert :-)

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.