Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Odd COM3 problem....
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
Genesis



Joined: 15 Jan 2006
Posts: 28

Posted: 16 January 2006, 4:23 AM    Post subject: Odd COM3 problem.... Reply with quote

Anyone else having problems writing to Parallax serial LCD from the ZX on COM3?

I've got an application that works perfectly on the Parallax 2Pe with the display at 19200 baud, and am trying to port it to the ZX. All the other I/O - a Dallas 1307 RTC chip, the TLC2543 ADC chip that I'm using, and a bunch of other hardware - all work fine. I've got those parts figured out.

However, writing to the Parallax serial LCD is flaky. The only thing their documentation states in terms of delays is that one must wait a given amount of time after issuing a "clear screen". Ok, no problem there.

But if I issue a bunch of writes of varying data, eventually I get a scrambled screen. Positioning commands fail to execute or move the cursor randomly, or other characters are garbled in transit (mostly positioning and other command codes though.)

The odd thing is that if I kick off the other tasks I intend to run on the ZX (so there are more tasks running) it gets worse - even though those tasks don't do any I/O to the LCD (they are talking to other devices in the system.)

Oddly enough as well, turning the baud rate down to 2400 stops it....

Anyone else seen something like this? Am I simply running into a hardware limitation - undocumented - on the Parallax LCD controller?
Back to top
DH*
Guest





Posted: 16 January 2006, 11:21 AM    Post subject: Reply with quote

I've never used that serial LCD but have found that all of the others I have used require a delay (20-25ms) after any positioning command.
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 665

Posted: 16 January 2006, 13:24 PM    Post subject: Re: Odd COM3 problem.... Reply with quote

Genesis wrote:
Anyone else having problems writing to Parallax serial LCD from the ZX on COM3?


I have been using COM3 with no problem (with 2 different serial displays, none are Parallax).

Maybe you have a problem with the queue size. Try making the ouotgoing queue as large as possible (for test purposes). Use a minimal incoming queue unless you are reading something off the LCD.

Does this change anything?

-Tony
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 16 January 2006, 16:39 PM    Post subject: Reply with quote

I don't have a specific answer to your question but a couple of things come to mind. Firstly, the Stamp and the ZX handle serial I/O in fundamentally different ways. The Stamp's I/O is unbuffered. When you output a character, the processor outputs each bit of the frame and then proceeds to the next command. With the ZX, the character is put into a queue of characters to be sent and the processor proceeds to the next command immediately. The actual outputting of the character is handled in the background and the timing for that process is derived from a series of precisely timed interrupts. The downside is that foreground commands that disable interrupts can interefere with the serial transmission and reception process. To determine if this may be occurring in your system you can disable all other activity (the #if 0 ... #endif pair is useful for this).

Note that with the Stamp, it is best to run the serial I/O at the fastest possible rate because that minimizes the delay incurred by your program for each character transmitted or received. For the ZX, it is best to run the serial I/O as the slowest possible rate because that reduces the overhead and makes it less sensitive to periodic disabling of interrupts by other operations. The fact that the problems seem to disappear when you slow down the I/O to 2400 baud may suggest a serial timing intereference problem.

Dave's suggestion of a required delay is worth investigating. Your observation that lower I/O speed fixes the problem may indicate that a missing delay is the problem.
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 665

Posted: 16 January 2006, 19:32 PM    Post subject: Reply with quote

dhouston wrote:
I've never used that serial LCD but have found that all of the others I have used require a delay (20-25ms) after any positioning command.


I have used a variety of displays: The netmedia 16x2 serial, 20x4 serial from Sparkfun, and 16x2 parallel optrex units.

I have never had to build-in any delay on my own. I would imagine that the serial interface hardware (usually a PIC), keeps track of all that stuff. If it does not then it is pretty crappy.

When I interface directly to the LCD in parallel mode, then I simply read the "busy" bit in a loop until it clears, then I can write the next character. Simple, easy, and never wrong.

If you do not read the "busy" bit, then timing can be touchy. To add to the complexity, otherwise identical units might have different timing needs. As far as I know, all the Hitachi-type interfaces will allow reading of the "busy" bit. Any serial interface to the LCD should take care of the timing homework by itself. It should also provide a good size incoming buffer so you do not have to do much buffering on the ZX.

I have been pleased with the Sparkfun serial LCD interface. It is "generic" and will work with all 14 or 16 pin hitachi-compatible displays.

The interface for the Sparkfun serial LCD interface is one of the API's that I uploaded a while back.

-Tony
Back to top
Genesis



Joined: 15 Jan 2006
Posts: 28

Posted: 18 January 2006, 4:00 AM    Post subject: Reply with quote

dkinzer wrote:
I don't have a specific answer to your question but a couple of things come to mind. Firstly, the Stamp and the ZX handle serial I/O in fundamentally different ways. The Stamp's I/O is unbuffered. When you output a character, the processor outputs each bit of the frame and then proceeds to the next command. With the ZX, the character is put into a queue of characters to be sent and the processor proceeds to the next command immediately. The actual outputting of the character is handled in the background and the timing for that process is derived from a series of precisely timed interrupts. The downside is that foreground commands that disable interrupts can interefere with the serial transmission and reception process. To determine if this may be occurring in your system you can disable all other activity (the #if 0 ... #endif pair is useful for this).

Yep - I understand how it works - I come from a multitasking background so the concepts here are familiar.

Thing is, I can cause the corruption to occur quite easily during initialization - before anything else gets going. That is, a "clear screen" (with the appropriate wait) followed by a series of positioning commands and writes, if set up at 19200 to display a "splash screen" comes up with the last line scrambled. No other processes have started yet...

The scrambling gets considerably WORSE though once the other tasks kick off..... so maybe there IS something there. I am using semaphores to lock critical regions and in a couple of places locktask() is also being called (specifically when I do I2c or SHIFTIN/SHIFTOUT I/O), but I wouldn't think that would cause interrupt problems - it should just prevent the scheduler from preempting me, correct?

What shuts off interrupts on the ZX from user code space (assuming I'm not manipulating the ATMEL registers directly - which I am not)? That's not clear from the documentation, unless I missed it somewhere..... I'm aware of the issue of tampering with the system Timers (esp Timer2 for I2c stuff) but the fact that my I2c and serial ADCs are working perfectly seems to indicate that I'm not doing anything to screw up interrupt processing... otherwise I'd think that those were get screwed as well, since they're dependant on the relationship between clock and data signals....

One other question - I'm not particularly staying away from any of the pins on the ZX - I did note that some are marked as being potential sources for interrupt inputs, but that requires that I configure for it, yes? That is, using the low pins (e.g. 5 & 6) for general I/O isn't going to get me in trouble - or will it? On the Parallax stuff there are no "special" pins so the design just started with their first I/O and worked upwards - as a consequence I'm using pins 5-15, all as general-purpose digital I/Os (e.g. 5 & 6 are the SDA and SCL pins, 7 & 8 are being used for keypad buttons, 9-11 are being used to clock data into and out of an ADC chip, etc....)

Quote:

Note that with the Stamp, it is best to run the serial I/O at the fastest possible rate because that minimizes the delay incurred by your program for each character transmitted or received. For the ZX, it is best to run the serial I/O as the slowest possible rate because that reduces the overhead and makes it less sensitive to periodic disabling of interrupts by other operations. The fact that the problems seem to disappear when you slow down the I/O to 2400 baud may suggest a serial timing intereference problem.

The testing I've done (resulting in a scrambled startup screen) indicates that its not an interference issue with other code and interrupts being shut off, since it happens even when there is only the initialization routine running (the other tasks haven't been started yet.)

Quote:

Dave's suggestion of a required delay is worth investigating. Your observation that lower I/O speed fixes the problem may indicate that a missing delay is the problem.

I think its more serious than that, to be honest.

Putting delays in after any positioning command helps - but doesn't solve it. That is, without them the scrambling happens immediately. With them it happens more slowly - but still happens. It smells like either a timing botch in the ZX OR a buffer overrun in the LCD board. I can jack queue size without any change in behavior at all, and besides - running out of queue space should just produce either a pause (if the message will fit but not until the queue drains) or a deadlock (if I try to write something larger than the free queue space when its empty.)

The reason I'm interested in the Parallax LCD is both size and money - its reasonably priced AND the daughter board is quite small. I have an application where depth behind the display is at a premium and most of the "backpack" manufacturers pay exactly zero attention to this matter, adding all sorts of ballyhoo stuff on the back of the board which is great if you have unlimited depth - but results in a display that in some cases is nearly 2" deep! That just won't do in my application.... I'm not terribly impressed with the current draw on the Parallax part (~20ma backlight off, ~100ma backlight enabled - the backlight off number seems quite high to me, and this is a battery-powered application so power counts) but I can live with it - if it otherwise works.

I'll investigate this "Sparkfun" controller - that looks quite dainty (good!) and also has backlight PWM control in software (excellent) All my I/O is contained in subroutines so changing the code for different LCD command sets is pretty trivial to accomplish.....
Back to top
DH*
Guest





Posted: 18 January 2006, 12:04 PM    Post subject: Reply with quote

I believe the Parallax LCD controller was designed by Wirz Electronics and originally sold as SLI-OEM for mating with the LCD of your choice.

The SLI-OEM documentation stated...

Code:
Direct LCD Control

Commands can be sent directly to the HD44780 controller by first sending a 0x0FE or 254d character to the SLI. The next command will be passed directly to the HD44780 as an instruction (not data to be displayed). 0x0FE or 254d should never be sent to the SLI as data.

This method of sending control data to the SLI must be used with caution. The commands are not parsed, and the internal variables in the SLI controlling the behavior of the LCD (i.e. scrolling, backspacing, etc.) are not always updated. This may lead to unexpected results after sending data.

Before moving the cursor explicitly, it is recommended that either a Form Feed or Carriage Return is sent to the SLI to ensure that any subsequent data writes do not cause an inadvertent scroll of the display.

It's been a few years but I have used the SLI-OEM, as well as serial LCDs from Crystal Fontz, Matrix Orbital, Seetron and the original NetMedia LCD+ and I found it prudent to incorporate delays. Some of the manufacturers indicated they were required in their documentation.
Back to top
Genesis



Joined: 15 Jan 2006
Posts: 28

Posted: 18 January 2006, 14:39 PM    Post subject: Reply with quote

You may have a point here..... the only way to insure that a delay will be taken is for the code to wait for the queue to drain before writing the positioning command, then write it and wait for the queue to drain again - THEN take the delay.

Otherwise you can't be sure that the delay actually occurs before other character(s) go down the pipe.....

I'll try that and see if it makes the problem go away....thing is the Parallax docs only note a delay requirement for a clear screen command - not for anything else.... it doesn't ball up when connected to a BS2Pe, but the stamp may be slow enough that it can't provoke the problem......

I ordered up a couple of other displays and that other "backpack" noted above, as they have much more friendly power numbers. Going from 30ma to about 5ma with the backlight off turns into a BIG difference in battery life......
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 18 January 2006, 15:09 PM    Post subject: Reply with quote

I too have a serial LCD driver (LCD07 from Dr. Anderson) which shows a similar problem. If I drive it too fast, the PIC resets itself which takes 2-3 seconds to bring back the display. This is VERY annoying when I'm trying to use the display to monitor the status of my 10Hz robot control loop. There is no flow control or any method to find out if the PIC or LCD is busy and the last thing I want is to delay my control loop waiting for the LCD display.

I now have a more expensive LCD driver that I'm going to try in the next few weeks.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 18 January 2006, 16:43 PM    Post subject: Reply with quote

Quote:
What shuts off interrupts on the ZX from user code space (assuming I'm not manipulating the ATMEL registers directly - which I am not)? That's not clear from the documentation, unless I missed it somewhere


The System Library routines that disable interrupts have a note to that effect in their respective sections of the System Library Manual. For example, the Resource Usage section of the description of ShiftOut() says:

Quote:
Interrupts are disabled during the shifting process.


Since the software UARTs derive their timing from a timer interrupt, having interrupts disabled for too long can interfere with transmission and reception. As a general rule, having interrupts disabled for more than 10% of a bit time incurs risk of introducing timing problems in the serial I/O. The point at which actual problems will occur depends to some extent on the timing (accuracy and phase delay) of the transmitter/receiver on the other end of the channel.

Quote:
I did note that some are marked as being potential sources for interrupt inputs, but that requires that I configure for it, yes? That is, using the low pins (e.g. 5 & 6) for general I/O isn't going to get me in trouble - or will it?


Your are correct that special configuration is required to use the alternate functions of the dual-function pins. Using pins 5-20 for I/O, their primary function, is straightforward.
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 665

Posted: 18 January 2006, 17:33 PM    Post subject: Reply with quote

mikep wrote:
I too have a serial LCD driver (LCD07 from Dr. Anderson) which shows a similar problem. If I drive it too fast, the PIC resets itself which takes 2-3 seconds to bring back the display. This is VERY annoying when I'm trying to use the display to monitor the status of my 10Hz robot control loop. There is no flow control or any method to find out if the PIC or LCD is busy and the last thing I want is to delay my control loop waiting for the LCD display.

I now have a more expensive LCD driver that I'm going to try in the next few weeks.


Well, I have not used his serial LCD interface, but the price is good.

I mentioned the sparkfun serial interface. I have used it pretty extensively. It works well for me. I have never made it gag. But then I never had trouble with the Netmedia LCD+ either.

I do not know all the details, but I do know that the sparkfun device has an 80 character internal queue. I do not know of any flow control that the device uses.

-Tony
Back to top
Genesis



Joined: 15 Jan 2006
Posts: 28

Posted: 31 January 2006, 0:37 AM    Post subject: Reply with quote

The Sparkfun interface has one MAJOR problem - its backlight control is severely broken in that it cannot be shut completely off!

Specifically, 124 128 is supposed to turn it OFF. It does not - it turns it on full.

All the OTHER settings (129-157) appear to work as described.

This is nasty, as the backlight is a huge part of the power consumption of these displays. While shutting it "almost off" can be done, you get a LOT of (very visible) flicker interface with the refresh on the display, leading to some interesting moire effects.

Anyway, just thought folks should know about this - I'mupset about it because it makes the interface, for my purposes, completely useless - I've got two soldered-up boards that are of course non-returnable and neither works right.

Oh, I also get occasional freak-outs with it at 9600 bps, and it doesn't support 2400 - at all.

There went a quick $50 in the toilet.

Grrrr.....

Any other ideas?
Back to top
Genesis



Joined: 15 Jan 2006
Posts: 28

Posted: 01 February 2006, 2:02 AM    Post subject: Question on how to get around the COM3 issues.... Reply with quote

Ok, so assume I need to talk to something async - and can't use the system port, because I need it available for programming and data dump.

So - if I must use a software port, is there a way around the timing problems?

Let's assume I can afford a task that "keeps the processor" for a millisecond at a time (1 character at 9600bps)

I think there is, no? What if I was to use SHIFTOUTEX instead of the build-in async I/O routines? SHIFTOUTEX holds interrupts off during its execution, yes - therefore, there should be no timing problem.

Will this work? Or am I shooting at a target that WON'T work?

It appears - from what I can determine - that if I was do something like this, it SHOULD work:

Data byte to output = 0x20 (ascii " ")

register.timerspeed1 = (what goes in here to get a 1/20th ms bit time?)
outb = 0x20
outb = outb or &H100 ' Add start bit
outb = shl(outb, 1) ' Make space for the stop bit
outb = outb or 1 ' Add the stop bit
shiftoutex(datapin, garbagepin, 10, outb, &H04, 2) ' 2 = 1/10th ms bit time


Should work, no - and should avoid timing problems with async serial on the other end.... or am I missing something?

If I then have a task that does GETQUEUEs and, when it sees bytes, outputs them using the above, I've got a bit-time-invarient serial output routine - I think!
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 665

Posted: 01 February 2006, 3:39 AM    Post subject: Reply with quote

Genesis wrote:
The Sparkfun interface has one MAJOR problem - its backlight control is severely broken in that it cannot be shut completely off!

Specifically, 124 128 is supposed to turn it OFF. It does not - it turns it on full.

All the OTHER settings (129-157) appear to work as described.

This is nasty, as the backlight is a huge part of the power consumption of these displays. While shutting it "almost off" can be done, you get a LOT of (very visible) flicker interface with the refresh on the display, leading to some interesting moire effects.

Anyway, just thought folks should know about this - I'mupset about it because it makes the interface, for my purposes, completely useless - I've got two soldered-up boards that are of course non-returnable and neither works right.

Oh, I also get occasional freak-outs with it at 9600 bps, and it doesn't support 2400 - at all.

There went a quick $50 in the toilet.

Grrrr.....

Any other ideas?


Iwow, I am sorry to hear that the board I had likes was not good for you. I must admit, that I am using the serial adapter on their 16x4 display which has NO backlight, so I never had the opportunity to try out this function.

I am surprised that something so simple as turning it off does not work!

I would hope that if the product is defective (i.e. will not turn off the backlight) that they would return your $$. The product should be suitable for all the intended purposes, and being able to execute its own commands ought to be the minimum expectation of "intended" purpose.

Did you contact them about this? My impression of them is that they have good product support and service. But I never needed to get a refund either.

Yes, these displays DO suck up the juice in the backlight. However, I just ordered 2 of the newer Optrex displays which use a black backgound and light letters. The backlight draws 45ma at "nominal" bright backlight, compared to 240ma for the older optrex displays. These are the larger ones which are 99.6mm wide for the visible part of the 16 character wide display. The smaller ones would draw less power, I suppose.

Also, I have never had my serial adapter glitch at 9600 baud. Maybe I never stressed it enough, but I have sent lots of stuff without ever worrying about the pacing of the data, and I never had a problem. So far.

-Tony
Back to top
Genesis



Joined: 15 Jan 2006
Posts: 28

Posted: 01 February 2006, 4:26 AM    Post subject: Reply with quote

I have posted to their forums on the issue - and got back stony silence.

The code in the unit is CLEARLY not what is published either. What's on their web page shows two commands that they do not document in the data sheet (turn on and turn off the backlight, at the saved value) which also do not work.

I got one of the blue-on-white LCDs and it draws MUCH less power with the backlight on - I'm down to ~5ma with the backlight at "minimum" and ~60ma with it on "full", which is far better than the Parallax display - which pulls ~20ma with the backlight OFF, and north of 100ma with it on!

But - the glitching problem is still there. I've put delays in positioning commands, which I know can cause this, but one of the major problems with the glitches is that if you get the wrong kind of glitch you can scramble the controller's settings due to the passthrough commands - you now have an UNRECOVERABLE situation with the display (without power-cycling.)

Under stress I can reproduce this quite easily.

That's unacceptable for obvious reasons.

Problem is, I'm not sure I have a better solution available no matter who I go to in terms of buying something.

I've yet to find a better "backpack" type device - there are a couple more but none support the backlight, and I need that capability.

It appears I may be left with the unpleasant requirement to talk to the LCD controller directly thorugh some circuitry of my own - due to wiring constraints (the display is at the end of a cable) I can't really do it in nibble mode directly of the ZX - it has to be through some kind of serial link.

This application is one in which I cannot live with having to power down the controller during use. That's flatly impossible when the unit is in actual use - the power connection is going to be inside a sealed container and not available to user at that point!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Goto page 1, 2  Next
Page 1 of 2

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group