Problem in LCD On/off during low power mode with FEZ Cobra

I am working for a low power mode in FEZ Cobra with 4.3 LCD Combination.

My requirement is to set the system in hibernate mode and set LCD off to achieve low power. To Make LCD On/off I have connected IO-21 pin from FEZ Boards to SHDN pin on LCD board. I am controlling IO-21 pin from my program to on/off LCD.

The processor should weak-up in two conditions. One is from RTC interrupt and another is from Interrupt input. When it weak-up from Interrupt input, I am making IO-21 pin high, This makes LCD On and I can see the display. After some interval the processor again go into sleep mode and I will make IO-21 pin low this makes LCD Off. This is cyclic process.

Problem: - I have observed that sometimes LCD weak-up properly and give proper display but some time it get blur(giving lines on screen fed down slowly and with appear white light). Once it get blur and go into sleep mode it never come-up with my expected screen.

I am getting confuse that it is codes problem or LCDs Problem. I doubt that it is because of LCD problem as; though LCD gives improper display my internal functionality is working properly and updating data in SD card.

Can some of guide please?

Remove the backlight connection and write a small test only to demo the problem please.

I didn’t get u Gus.

My requirement is to off the LCD when the processor go in hibernate mode and while it weak-up it should on LCD and display the last screen. You are trying to say that the SHDN pin is for back-light?

what u mean by “small test only to demo problem”? Sorry i didn’t understand this.

I have removed the back-light connection and test the application. In this case the LCD will on with every RTC Alarm interrupt (in my case it is every one minute). and goes in sleep mode after 30 second. Still, after 8 to 10 minutes the screen is getting blur and changing colors (white/red/green/blue) and after that it is not giving expected screen.

Few months back, in my initial query for low power mode ([url] http://www.tinyclr.com/forum/10/2645/[/url])

some one has suggested below statement.

“If you just want to turn the LCD off, you can use a transistor like a 2N2222 to control the power pin on the LCD. You then use one of the free pins to control the transistor like a switch.”

but, I am not getting the power pin of 4.3" LCD. If by going with this direction helps, please suggest the power pin details to control 4.3" LCD.

I am trying to find the source of the problem, which is not in SHDN pin I believe. We need your test app that shows the problem so our engineers can use it to fix the problem.

Hi Gus,

Please find the code as under. I don’t know how to send you the whole project, so i am attaching class file.



using System;
using System.IO;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.IO;
using Microsoft.SPOT.IO;
using System.Text;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.Hardware.LowLevel;
using Microsoft.SPOT.Presentation.Controls;

namespace Project_Sample
{
/*This version is working properly with FEZ cobra and 4.3" LCD. 

Functionality of the code: - Every one minute code will log the time stamp in to SD card. Every 30 second it will go in to the sleep mode. 
   It will weak-up from sleep mode in two conditions. 
    
1)	When SD card time will come and onscreen display the time and status of interrupt input register. 
2)	When it get interrupt input (IO23).

IO21 is used to manage SHDN pin. When it weak-up from Interrupt input code will glow the LCD backlight in other condition it will be in sleep mode.

Problem statement:- The code works properly up to certain time (some time 1 hour some time 5 minutes). 
    After that it doesnt display expected screen during weak-up. The screen either become blurry or changing colors or only with white background. 
    In background the code is storing data properly in SD card. 
 
To Run the code :- Please Call this class from Programm.cs  
 */



    class clsTest : Window
    {
        static OutputPort OutPort;
        InterruptPort LDR;

        private int DHr;
        private int DMn;
        private int DSc;

        private int SmodeHr;
        private int SmodeMn;
        private int SmodeSc;

        private DateTime NxtDat;
        private DateTime NxtSmodeTm;
        private DateTime AbsTime;
        private bool FlgFTimeThread;
        private TimeSpan SmodeSpan;
        private TimeSpan ThreadSpan;
        private bool flgsts;

        DispatcherTimer ThreadTimer;
        DispatcherTimer SleepModeTimer;

        public static PersistentStorage sdps = null;
        public static string rootdirctry;

        String s = "";
        Text txtVal;
        public clsTest()
        {
            LDR = new InterruptPort((Cpu.Pin)23, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            OutPort = new OutputPort((Cpu.Pin)21, true);

            DHr = 0;
            DMn = 1;
            DSc = 0;

            SmodeHr = 0;
            SmodeMn = 0;
            SmodeSc = 30;

            DateTime ATm = DateTime.Now; //RealTimeClock.GetTime();
            SmodeSpan = new TimeSpan(SmodeHr, SmodeMn, SmodeSc);
            ThreadSpan = new TimeSpan(DHr, DMn, DSc);
            NxtSmodeTm = ATm.Add(SmodeSpan);
            NxtDat = ATm.Add(ThreadSpan);
                        
            WriteIntoFile("Test", "TestThread.txt");

            ThreadTimer = new DispatcherTimer();
            ThreadTimer.Interval = new TimeSpan(DHr, DMn, DSc);
            ThreadTimer.Tick += new EventHandler(ThreadTimer_Tick);
            ThreadTimer.Start();

            SleepModeTimer = new DispatcherTimer();
            SleepModeTimer.Interval = new TimeSpan(0, 0, 2);
            SleepModeTimer.Tick += new EventHandler(SleepModeTimer_Tick);
            SleepModeTimer.Start();

            txtVal = new Text();
            txtVal.TextContent = "Text";
            txtVal.Font = Resources.GetFont(Resources.FontResources.NinaB);
            txtVal.ForeColor = Color.Black;
            txtVal.SetMargin(125, 110, 0, 0);
            this.Child = txtVal;

        }

        public void ThreadTimer_Tick(object sender, EventArgs e)
        {           

            DateTime Ctime = DateTime.Now;             

            if (Ctime >= NxtDat)
            {
                NxtDat = Ctime.Add(ThreadSpan);
            }
            else if (Ctime <= NxtDat)
            {
                return;
            }

            bool flgsts = LDR.Read();

            ThreadCall(flgsts);

        }

        private void ThreadCall(bool ui)
        {
            DateTime Ct = DateTime.Now;
            s = Ct.ToString("hh:mm:ss");
            txtVal.TextContent = s + "--" + ui.ToString();            
            s = s + "\r\n";
            WriteIntoFile(s, "TestThread.txt");
        }


        public void SleepModeTimer_Tick(object sender, EventArgs e)
        {
            DateTime Atime = DateTime.Now; 

            if (Atime >= NxtSmodeTm)
            {
                HibernetMode();
            }
            else if (Atime < NxtSmodeTm)
            {
                return;
            }
        }
        
        private void HibernetMode()
        {
            DateTime Dtm = DateTime.Now;
            RealTimeClock.SetTime(Dtm);

            TimeSpan Tdif = NxtDat.Subtract(Dtm);
            RealTimeClock.SetAlarm(RealTimeClock.GetTime().Add(Tdif));
            ThreadTimer.Stop();
            SleepModeTimer.Stop();

            OutPort.Write(false);
            Power.Hibernate(Power.WakeUpInterrupt.RTCAlarm | Power.WakeUpInterrupt.InterruptInputs);

            flgsts = LDR.Read();

            Dtm = RealTimeClock.GetTime();
            Utility.SetLocalTime(Dtm);

            if (flgsts == true)
            {
                OutPort.Write(false);
                ThreadCall(flgsts);

                Dtm = DateTime.Now;

                NxtDat = Dtm.Add(ThreadSpan);
                NxtSmodeTm = Dtm.Add(SmodeSpan);

                ThreadTimer.Start();
                SleepModeTimer.Start();
                //HibernetMode();
            }
            else
            {
                OutPort.Write(true);
                ThreadCall(flgsts);

                Dtm = DateTime.Now;
                NxtSmodeTm = Dtm.Add(SmodeSpan);

                ThreadTimer.Start();
                SleepModeTimer.Start();
            }
        }


        public static bool WriteIntoFile(string StrToWrite, String FileName)
        {
            try
            {
                if (sdps == null)
                {
                    sdps = new PersistentStorage("SD");
                    sdps.MountFileSystem();
                    rootdirctry = VolumeInfo.GetVolumes()[0].RootDirectory;
                }
                string filepath = rootdirctry + "\\" + FileName;

                FileStream fs = new FileStream(filepath, FileMode.Append);
                byte[] DataToWrt = Encoding.UTF8.GetBytes(StrToWrite);
                fs.Write(DataToWrt, 0, DataToWrt.Length);
                fs.Flush();
                fs.Close();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }


    }

}


Please check at your end and let me know the solution.

Thank you very much but this is not exactly demonstrating the problem. What I asked for is "We need your test app that shows the problem so our engineers can use it to fix the problem."
Which should be as small as possible and only use the things that cause the problem, according to you it is LCD and sleep but it is not related to SD card for example.

We need one code snippet that we can copy/paste in a new project and run please.

Hi Gus,

Try this, I have removed SD card storage. As per your suggestion, i have prepare as you can copy paste this whole code in any project and execute it. I have test this code, it is giving problem with FEZ Cobra 3.5" LCD and 4.3" LCD.

Hope this is as per your expectation.


using System;
using System.IO;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Theming;
using GHIElectronics.NETMF.Hardware;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.Presentation.Themes;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.IO;
using Microsoft.SPOT.IO;
using System.Text;
using GHIElectronics.NETMF.Hardware.LowLevel;

namespace Project_Sample
{
    public class Program : Microsoft.SPOT.Application
    {
        static Program myApplication;

        class clsTest : Window
        {
            static OutputPort OutPort;
            InterruptPort LDR;
            private int DHr;
            private int DMn;
            private int DSc;
            private int SmodeHr;
            private int SmodeMn;
            private int SmodeSc;
            private DateTime NxtDat;
            private DateTime NxtSmodeTm;
            private DateTime AbsTime;
            private bool FlgFTimeThread;
            private TimeSpan SmodeSpan;
            private TimeSpan ThreadSpan;
            private bool flgsts;
            DispatcherTimer ThreadTimer;
            DispatcherTimer SleepModeTimer;

            String s = "";
            Text txtVal;
            public clsTest()
            {
                LDR = new InterruptPort((Cpu.Pin)23, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
                OutPort = new OutputPort((Cpu.Pin)21, true);

                DHr = 0;
                DMn = 1;
                DSc = 0;

                SmodeHr = 0;
                SmodeMn = 0;
                SmodeSc = 30;

                DateTime ATm = DateTime.Now; //RealTimeClock.GetTime();
                SmodeSpan = new TimeSpan(SmodeHr, SmodeMn, SmodeSc);
                ThreadSpan = new TimeSpan(DHr, DMn, DSc);
                NxtSmodeTm = ATm.Add(SmodeSpan);
                NxtDat = ATm.Add(ThreadSpan);

                ThreadTimer = new DispatcherTimer();
                ThreadTimer.Interval = new TimeSpan(DHr, DMn, DSc);
                ThreadTimer.Tick += new EventHandler(ThreadTimer_Tick);
                ThreadTimer.Start();

                SleepModeTimer = new DispatcherTimer();
                SleepModeTimer.Interval = new TimeSpan(0, 0, 2);
                SleepModeTimer.Tick += new EventHandler(SleepModeTimer_Tick);
                SleepModeTimer.Start();

                txtVal = new Text();
                txtVal.TextContent = "Text";
                txtVal.Font = Resources.GetFont(Resources.FontResources.NinaB);
                txtVal.ForeColor = Color.Black;
                txtVal.SetMargin(125, 110, 0, 0);
                this.Child = txtVal;

            }

            public void ThreadTimer_Tick(object sender, EventArgs e)
            {
                DateTime Ctime = DateTime.Now;
                if (Ctime >= NxtDat)
                {
                    NxtDat = Ctime.Add(ThreadSpan);
                }
                else if (Ctime <= NxtDat)
                {
                    return;
                }
                bool flgsts = LDR.Read();
                ThreadCall(flgsts);
            }

            private void ThreadCall(bool ui)
            {
                DateTime Ct = DateTime.Now;
                s = Ct.ToString("hh:mm:ss");
                txtVal.TextContent = s + "--" + ui.ToString();
                s = s + "\r\n";
            }


            public void SleepModeTimer_Tick(object sender, EventArgs e)
            {
                DateTime Atime = DateTime.Now;
                if (Atime >= NxtSmodeTm)
                {
                    HibernetMode();
                }
                else if (Atime < NxtSmodeTm)
                {
                    return;
                }
            }

            private void HibernetMode()
            {
                DateTime Dtm = DateTime.Now;
                RealTimeClock.SetTime(Dtm);

                TimeSpan Tdif = NxtDat.Subtract(Dtm);
                RealTimeClock.SetAlarm(RealTimeClock.GetTime().Add(Tdif));

                ThreadTimer.Stop();
                SleepModeTimer.Stop();

                OutPort.Write(false);
                Power.Hibernate(Power.WakeUpInterrupt.RTCAlarm | Power.WakeUpInterrupt.InterruptInputs);

                flgsts = LDR.Read();

                Dtm = RealTimeClock.GetTime();
                Utility.SetLocalTime(Dtm);

                if (flgsts == true)
                {
                    OutPort.Write(false);
                    ThreadCall(flgsts);

                    Dtm = DateTime.Now;

                    NxtDat = Dtm.Add(ThreadSpan);
                    NxtSmodeTm = Dtm.Add(SmodeSpan);

                    ThreadTimer.Start();
                    SleepModeTimer.Start();
                }
                else
                {
                    OutPort.Write(true);
                    ThreadCall(flgsts);

                    Dtm = DateTime.Now;
                    NxtSmodeTm = Dtm.Add(SmodeSpan);

                    ThreadTimer.Start();
                    SleepModeTimer.Start();
                }
            }
        }
        
        public static void Main()
        {   
            myApplication = new Program();           
            Touch.Initialize(myApplication);
            Window mainWindow = myApplication.CreateWindow();
            myApplication.Run(mainWindow);
        }

        private Window mainWindow;

        public Window CreateWindow()
        {
            mainWindow = new clsTest();
            mainWindow.Height = SystemMetrics.ScreenHeight;
            mainWindow.Width = SystemMetrics.ScreenWidth;
            mainWindow.Visibility = Visibility.Visible;

            // Attach the button focus to the window.
            Buttons.Focus(mainWindow);

            return mainWindow;
        }
    }
}

Hi Gus,

Any update related above problem?

We have been very busy, will run the test ASAP.

Confirm, we see the problem, which is very strange! We will dig into it ASAP. I can’t even use USB when it happens but LED still works so code is still running!

Do you see the same?

I have observed the same problem and written at beginning of the post.

The code is working properly and even Rs232 port and SD card access is also functioning properly. The problem is with display and USB connection with PC. They are getting lost.

Please update the solution ASAP.

Hello!

I have a FEZ Cobra with 3.5" LCD display (as a part of the OEM package) which I am attempting to integrate into a product development. I am facing a problem with the LCD (I couldnt find a link to create a new forum post, so using the reply to an existing LCD issue which is similar).

My FEZ Cobra runs a program using SPI, HTTP request-response processing, SD card access and a simple UI window. A dispatch timer periodically updates the UI: What happens is that after about 20 - 30 mins of program run, the LCD turns white and the program stops. The module cannot be reached over USB (or ethernet). I noticed that the 3.3V regulator starts overheating. I have to power out the board, wait for few minutes and then on power-up the program runs fine and then after sometime (usually 20 mins or so, but It has also run longer or sometimes the problem appeared in few minutes). I have updated the firmware to 4.1.6 (30.June 2011). Has anyone faced this problem? I have tried both external power supply (6V DC), USB and regulator 5V connected to 5V in, but no luck.

Thanks for any help!

Ganesh

Your question will not get enough attention

http://tinyclr.com/forum/10/ “new topic” button is on top … you need to be logged in

Please repost it

Hi GUS,

This is Niraj (author of this post). Please update with solution of my problem. It is pending from a long.

Sorry for delay. We are trying to fix it for next release.

We sent you an email with testing instructions.

Thanks Mike for sending mail and updated firmware.

I have updated my board with attached files (CLR.HEX, CLR2.HEX, Config.HEX), with the help of .Net Micro Framework Deployment Tool. I have checked the version in FEZ and it is 4.1.6.1.

After updating my board, I could not able to deploy my test code through USB. In PC it starts the deploying process (from Visual C# express 2010), but the application restarts without deploying.

The same application is deploying properly with firmware version 4.1.3.0.

I am using FEZ Cobra with 3.5 LCD, with .Net Micro framework ver 4.1 and GHI SDK 4.1.

Please advice for next process.

Maybe some library is out of date. I tried the example that you posted and it works fine. Try that one.
Please show the debug output in Visual Studio output window or connect through MFDeploy and reboot the device. What messages do you get?

I am getting attached image message in debug output in visual studio.

Please guide me further.