Problem with LCD & multitasking with NXC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
mindcharlie1
Posts: 4
Joined: 17 Mar 2011, 08:12

Problem with LCD & multitasking with NXC

Post by mindcharlie1 »

I got problems as below, hope someone could help me, I really appreciate your time.

(1)If I have two “Precedes()” commands used in the program, will the program execute as I want?
(2)With command below, the “5” will not be display on the screen, only “1234” will be displayed. One character will occupy 6 pixels wide. For 5 numbers, 30 pixels will be occupied. But why is the “5” not displayed?
NumOut(70, LCD_LINE1, 12345);
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Problem with LCD & multitasking with NXC

Post by mattallen37 »

I don't know, how do you want it to execute? It should run two tasks at the same time just fine.

If you use 70 for the x value, that may be to close to the edge to display. If you try to display with a character hanging over the edge by even 1 pixel, it won't display that character. Try reducing the x value.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Problem with LCD & multitasking with NXC

Post by afanofosc »

I can't tell what you mean by two Precedes statement. These are compiler directives rather than executable code, per se. They tell the compiler how to generate an RXE which contains task scheduling information that the VM uses to start tasks appropriately. One per task is sufficient. Each Precedes statement should contain a list of all the tasks that you want to start running when the current task ends.

Pixels on the LCD are numbered from 0 to 99 - not 0 - 100. So a text string that requires 30 pixels to display will need to start at pixel 69 rather than pixel 70. Otherwise the last character in the string will be clipped by the firmware LCD drawing routines.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
ricardocrl
Posts: 117
Joined: 27 Dec 2010, 19:27

Re: Problem with LCD & multitasking with NXC

Post by ricardocrl »

afanofosc wrote:
Pixels on the LCD are numbered from 0 to 99 - not 0 - 100. So a text string that requires 30 pixels to display will need to start at pixel 69 rather than pixel 70. Otherwise the last character in the string will be clipped by the firmware LCD drawing routines.

John Hansen
I also have the some question, because starting at pixel 70th, should give space for 30 pixels, ending in the 99th. If we needed to write 100 pixels, we would have to start in the 0th pixel. Isn't that right?

Cheers
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Problem with LCD & multitasking with NXC

Post by afanofosc »

Yeah, I guess you are right. Sounds like the standard and enhanced firmware text drawing routines have an off-by-one error in the clipping code, perhaps.

I just checked this in the source code and it is exactly that.

Code: Select all

    //Calculate X coordinate of the right edge of this character.
    //If it will extend past the right edge, clip the string.
    X += FontWidth;
    if (X >= DISPLAY_WIDTH)
      break;
It looks like this should be checking for > since X is the starting pixel of the next character. If the starting pixel of the next character is 100 (i.e., equal to DISPLAY_WIDTH) then that means the current character will fit on the LCD since it ends at 99.

I have made this change in the enhanced firmware. NOTE: this will introduce a difference in behavior between the what draws successfully with the standard firmware vs what draws successfully with the enhanced firmware. More than likely this defect will never be fixed in the standard firmware. If you want your program to work on the standard firmware you will need to limit your output to 99 pixels wide rather than 100.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mindcharlie1
Posts: 4
Joined: 17 Mar 2011, 08:12

Re: Problem with LCD & multitasking with NXC

Post by mindcharlie1 »

Thanks very much for your help. And the first question is actually as below:
If I have two “Precedes()” commands used in the program, will the program execute as I want?
Case1:
task 1()
{*****}
task 2()
{*****}
task 3()
{*****}
task main
{
for(i=0;i<20;i++)
{precedes(1,2);}
for(j=0;j<20;j++)
{precedes(1,3);}
}
Case2:
task 1()
{*****}
task 2()
{*****}
task 3()
{
precedes(1,2);
}
task main
{
precedes(1,3);
}
Is that possible to use multitasking like two cases above?
Case3:
task 1()
{*****}
task 2()
{*****}
task 3()
{ ***}
task main
{
precedes(1,2,3);
}
In case 3, how to set the priorities for task 1, 2 and 3?
m-goldberg
Posts: 73
Joined: 29 Sep 2010, 12:05

Re: Problem with LCD & multitasking with NXC

Post by m-goldberg »

Here is some basic info about tasks and Precedes:

1. Do nor name tasks with numbers. Tasks must be named with valid identifiers.
2. The Precedes statement is not executable -- it is as John said a compiler pragma (instruction to the compiler) -- it does not generate NXT code, so don't put it any kind of an executable loop.
3. The Precedes statement does not establish priorities among tasks.

According to the NXC Programmers Guide, you can adjust task priority with the priority statement
3.3.5.4 The priority statement

You can adjust the priority of a task using the priority statement.
Setting task priorities also requires the enhanced NBC/NXC firmware. A task’s priority is simply the number of operations it will try to execute before yielding to another task. This usually is 20 operations.

priority task_name, new_priority;
I have not used this statement, so I can not say anything about it effectiveness.
Regards, Morton
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests