Main Site Documentation

Fez Panda PWM Crash


#1

Hey guys!

So I’m learning how to use the .net microframework for my lab, and I wanted to try out PWM to make sound, because I had never done so before. But I can’t get off the ground because of some really weird PWM error.

I start up visual studio, take the led example that comes when you create a Fez Panda solution, and initialize a PWM variable. If I do this, the program will compile and send to the device, but then the device will just go “fuck you” and not run anything. No errors or warnings for me to work off of…

So here’s the code:

using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;

namespace FEZ_Panda_Application3
{
    public class Program
    {
        //comment this out and you will hit the while loop
        static PWM pwm1;

        public static void Main()
        {
            // Blink board LED

            //even if you comment this out, it still doesn't work
            pwm1 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di5);

            bool ledState = false;

            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);

            while (true)
            {

                Thread.Sleep(500);
                ledState = !ledState;
                led.Write(ledState);

            }
        }

    }
}

In the code above, even if you move the while loop to before the PWM init, or put the PWM init inside a function that is never called, it will still crash. Importing the GHIElectronics.NETMF.Hardware library does not cause any issues.

If anyone can explain to me why this is happening, that’d be amazing.

Oh, fyi, the registration for TinyCLR is down. I was only able to get on the forum by using a cached version of the registration page through google.

Thanks much!

NOTE: Updated code because I made an error at 2am. Issue still applies.


#2

I am not exactly sure what you are seeing or not seeing, nor am I sure what you expected, but if you expected the LED to blink at all, then it may not be working because you do not have the statement:


                led.Write(ledState);

in your code just after the statement


                ledState = !ledState;

So your while loop should look something like this.


            while (true)
            {
                // Sleep for 500 milliseconds
                Thread.Sleep(500);

                // toggle LED state
                ledState = !ledState;
                led.Write(ledState);
            }


#3

Oh wow. That’s just from me being really tired last night :stuck_out_tongue:

Even if you add the

led.Write(ledState);

To the while loop… so you know, it should actually blink, if you have the PWM init beforehand, that never happens.

I’m going to update my first post to reflect this.

Thanks Dave!


#4

Ok, I copied the code in your post to my program.cs and it built and ran fine on my panda. Did you forget to add something to the code you posted?
Did you add GHIElectronics.NETMF.Hardware to your references? I know you said you imported it, but from the syntax coloring in your code example I suspect that you may not have.
It is not sufficient to add

using GHIElectronics.NETMF.Hardware;

, you need to add it to your rerences.
Just a reminder, in the Solution Explorer right-mouse-click on the references select “add reference” and select GHIElectronics.NETMF.Hardware. You should notice

FEZ_Pin

on line 22 change from black to blue.
Sorry I didn’t notice that this morning.


#5

Hey Dave,

The syntax highlighting is built into the forum I think. I definitely have the library in my references. In my Visual Studio it is highlighted correctly.

Its good to know it is working for someone else though. Do you know if there is something firmware related (I just got this hardware from my lab and don’t know about this) that might cause this? Or, if not, is it just a hardware issue?

I’m going to try running this on a different machine and see if it something that my computer is doing.

Thanks for the help!

-Matthew


#6

Just to let you know, I only slightly modified your Main and I am getting a decreasing frequency beep everytime I turn on the LED. Heres the code

        public static void Main()
        {
            UInt32 duration = 1000000;
            // Blink board LED
            //even if you comment this out, it still doesn't work
            pwm1 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di5);

            bool ledState = false;

            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);
            while (true)
            {
                if (ledState)
                {
                    pwm1.SetPulse(duration, duration / 2);
                    duration = duration + 1000;
                }
                else
                {
                    pwm1.SetPulse(duration, 0);
                }
                Thread.Sleep(500);
                ledState = !ledState;
                led.Write(ledState);
            }
        }

#7

Just saw your note about version. You did make sure your running the correct version of firmware by checking the release note and your panda, didn’t you?


Might be worthwhile doing that if you are sure you have the code correct.