System hang

Hi…
Can anyone shine a light in the direction I need to go.

My project is ready for the customer viewing ( tommorrow ) however I have a bug.

When the project is deployed and is running in debug mode connected to visual studio, it runs superb everything works as it should… If I stop debugging, reboot and stand alone after a period of time (about 30mins, not really determinable) it hangs and you have to reboot…

The project is just an extension of the GHI demo… There is extra dispatch timers but they are disposed of carefully… It seems to crash in any window opened inside the desktop (even ones created by GHI ie… “clock demo” but not the desktop itself… It mainly happens when you try to close the current window… but it seems to randomly crash aswell

Regards Ian

I think it will help if you post your code.

That would be a task

Do you think I should narrow it down a bit the main window is my crane display this is whre most crashes take place as its the default window.


public class craneview : BaseWindow
    {
        // Reference to the Desktop window
        private Desktop _window;

        // Image that represents this window
        private Bitmap screen = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);

        // Fonts
        private Font ninaBFont = Resources.GetFont(Resources.FontResources.NinaB);
        private Font smallFont = Resources.GetFont(Resources.FontResources.small);
        private Font segoeFont = Resources.GetFont(Resources.FontResources.SegoeUI12Bold);
        private Font selectedfont = Resources.GetFont(Resources.FontResources.CourierNew32Bold);

        private Bitmap uniccrane = Resources.GetBitmap(Resources.BitmapResources.unic);
        private Bitmap _task = Resources.GetBitmap(Resources.BitmapResources.taskbar);
        private Bitmap _bar = Resources.GetBitmap(Resources.BitmapResources.bargraphG);
        private DispatcherTimer loopTimer;
        private sbyte ATB = 0, OR = 0;
        private float length = (float)1.7;
        private float radius = 1;
        private float swl = (float)2.45 ;
        private float weight = 0, angle = 50;
        private string messages;
        private int bar = 3;
        private Random random = new Random();
        AnalogIn pot1 = new AnalogIn(GHIElectronics.NETMF.Hardware.AnalogIn.Pin.Ain2);
        AnalogIn pot2 = new AnalogIn(GHIElectronics.NETMF.Hardware.AnalogIn.Pin.Ain3);
        AnalogIn pot3 = new AnalogIn(GHIElectronics.NETMF.Hardware.AnalogIn.Pin.Ain6);

        // Stops loops from throwing errors on exit
        private bool exiting = false;

        public craneview(Desktop window)
        {
            _window = window;
            this.TouchDown += OnTouchDown;
                              
            loopTimer = new DispatcherTimer();
            loopTimer.Tick += Loop;
            loopTimer.Interval = new TimeSpan(0, 0, 0, 0, 200); // 16 FPS
            loopTimer.Start();
       }

        /// <summary>
        /// Renders the screen bitmap initially.
        /// </summary>
        /// <param name="dc"></param>
        public override void OnRender(DrawingContext dc)
        {
            dc.DrawImage(screen, 0, 0);
        }

        /// <summary>
        /// Loop that handles the game's logic.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Loop(object sender, EventArgs e)
        {
            if (exiting) return;
            weight = angle = length = 0;
            for (int b = 0; b <7; b++)
            {
                weight += (float)pot1.Read() / 350;
                angle +=  (float)pot2.Read() / 10;
                length += (float)pot3.Read() / 300;
            }
            length /= 8; angle /= 8; weight /= 8;
            double limit = 2.45 /( 1 + (length / 3.4));
            if (length > 1)
                limit = limit * (angle / 90);
            swl = (float)limit;
            length += 1.7f;
            radius = length * (float)(MathEx.Cos(angle * 0.017444));
            radius -= 0.3f;
            if (swl > 0)
                bar = (int)(160 * (weight / swl));
            if (bar > 160) bar = 160;
            
            messages = "";
            _bar = Resources.GetBitmap(Resources.BitmapResources.bargraphG);
            if (ATB == 1)
                messages = "ATB ON";
            if (bar > 120)
            {
                messages = "APPROACH";
                _bar = Resources.GetBitmap(Resources.BitmapResources.bargraphO);
            }
            if (bar > 140)
            {
                messages = "OVER LOAD";
                _bar = Resources.GetBitmap(Resources.BitmapResources.bargraphR);
            }
            if (bar > 150)
                messages = "CUT OUT";
            if (OR == 1)
                messages = "OVERRIDE"; 
            
            UpdateScreen();
        }

        /// <summary>
        /// Update the screen bitmap.
        /// </summary>
        private void UpdateScreen()
        {
            screen.Clear();
            screen.Scale9Image(0, 0, this.Width, 32, _task, 0, 0, 0, 0, 0xFF);
            screen.Scale9Image(350 ,230 - bar , 80, bar, _bar, 0, 0, 0, 0, 0xFF);
            screen.DrawImage(0, 32, uniccrane, 0, 0, uniccrane.Width, uniccrane.Height);
            screen.DrawText(angle.ToString("F1"), segoeFont, Color.Black, 5, 180);
            screen.DrawText(length.ToString("F1"), segoeFont, Color.Black, 165, 170);
            screen.DrawText(radius.ToString("F1"), segoeFont, Color.Black, 185, 230);
            screen.DrawText(messages, ninaBFont, Color.White, 5, 5);
            screen.DrawText(weight.ToString("F3")+ " LOAD", segoeFont, Color.White, 350, 250);
            screen.DrawText(swl.ToString("F3")+" SWL", segoeFont, Color.White, 350, 32);
            
            screen.Flush();
        }

        /// <summary>
        /// Get a random number between two values.
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        private int Randomize(int min, int max)
        {
            return (random.Next() % (max - min)) + min;
        }

        /// <summary>
        /// Exit this window by touch.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnTouchDown(object sender, TouchEventArgs e)
        {            
            Exit();
        }

        /// <summary>
        /// Exit this window by button.
     
        protected override void OnButtonDown(ButtonEventArgs e)
        {
            if (e.Button == Button.VK_SELECT)
                Exit();
            if (e.Button == Button.VK_UP)
                ATB = 1;
            if (e.Button == Button.VK_DOWN)
                OR = 1;
         }
        protected override void OnButtonUp(ButtonEventArgs e)
        {
            if (e.Button == Button.VK_UP)
                ATB = 0;
            if (e.Button == Button.VK_DOWN)
                OR = 0;
        }
        /// <summary>
        /// Exit this window.
        /// </summary>
        public override void Exit()
        {
            exiting = true;
            loopTimer.Stop();
            screen.Clear();
            pot1.Dispose();
            pot2.Dispose();
            pot3.Dispose();
            this.Close();
            _window.SetFocus();
        }

    }

Its been running about 2 hours now linked to the debugger (typical)
Cheers

How is your board powered when it is not hooked up for debugging?

First thing to try is ti hook up the debugger and see if you get any exceptions…
Try to minimize your code until you find the problem.

Assuming that an exception is happening, when not teathed to the debugger, you could put some try/catch handling into the program and write out the exception info to a SD.

I think Joe means that you need to run mfdeploy and click connect then let your device run

Excellent…

Well done Jeff (its why you made master)

I have monitored the fez cobra power requirements
I have a regulated 6v supply 700ma (I assumed to be enough)
with the 5 v from the usb the board regulates to approx 4.85V

With the board running from the 6v alone the regulators aren’t happy
the votage drops to 4.7 4.6 volts and occasionally dips ( looking at an angle about 30 degrees to the screen you notice the slight flicker.

Hopefully its solved… Ive bypassed the onboard regs and supplied a 5v at 3 amps switched mode supply …

Its now been running for 4 hours on is own…

Cheers lads

Great glad you got it sorted out. I happened to think about the power as I had a friend who was having a fit with a PIC that was supposed to run off of 3.3V buts its internal low voltage reset had a lower limit of 4.5V! So, if you did not disable the low voltage reset the chip would never actually come out of reset.