xTIME studio programming problems

Technical questions regarding the XTC tools and programming with XMOS.
prichner
Junior Member
Posts: 7
Joined: Tue Jan 28, 2014 8:42 am

xTIME studio programming problems

Post by prichner »

Hi

I use xTIMEcomposer for programming. I have a XMOS XS1-L1-128.
The problem is, that I can assign manually only one of the 8 cores. I wrote in my program the same commands how in the examples, but it doesn't work.
The error message is this: index of array exceeds its upper bound
My programm is in the exhibit.

Can you help me please?

Thanks, prichner
You do not have the required permissions to view the files attached to this post.


User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

you're nearly there - stdcore is the old way of saying "tile" (and cores used to be called threads). XMOS changed it's nomenclature a while back but there are still examples of stdcore around. So you are asking the compiler to place the two tasks on different tiles. FIne if you have an L16, but no good for an A8-dev like on the startkit for example.

Either remove "on stdcore[n]:" bit or change to "on tile[0]" for both..
prichner
Junior Member
Posts: 7
Joined: Tue Jan 28, 2014 8:42 am

Post by prichner »

I find also funny, that an example in the XC programming guide doesn't work. It has mistakes, if I want to compile them.

Another question: How can I then define, that for each program part an own thread is responsible? I must know it, because I must make a project, where I need very high speed, and there I need more than one thread.

Thank you for the answer, prichner

note: I use the XK-1A development kit.
User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

Post by sethu_jangala »

prichner wrote: Another question: How can I then define, that for each program part an own thread is responsible? I must know it, because I must make a project, where I need very high speed, and there I need more than one thread.
The following document gives you more information about the XS1 Architecture:
https://www.xmos.com/en/download/public ... 50D%29.pdf
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

Code: Select all

#include <xs1.h>
#include <stdio.h>
#include <platform.h>

on tile[0] : out port led1 = XS1_PORT_4A;
on tile[0] : in port button1 = XS1_PORT_1K;

void dataIn(chanend c, port button1)
{
    int b_1;
    while(1)
    {
        button1 :> b_1;
    }
}

void dataOut(chanend output, port led1)
{
    while(1)
    {

    }
}

int main(void)
{
    while(1)
    {
        chan c;
        par
        {
            on tile[0] : dataIn(c, button1);
            on tile[0] : dataOut(c, led1);
		}

    }

    return 0;
}
Try this. DataIn and DataOut will run on two different hardware threads on the same tile.
Each tile supports 8 hardware threads (and the XK-1A has a one-tile chip).

Which example does not work?
prichner
Junior Member
Posts: 7
Joined: Tue Jan 28, 2014 8:42 am

Post by prichner »

I understand now. I meaned, that the XK-1A have 8 tiles and everyone have one thread. Ok now it is much easier.
Thank you.

The example who doesn't work is in my exhibit; Perhaps it is for an other uC, I don't know. The errors are behind the code

friendly greetings
prichner
You do not have the required permissions to view the files attached to this post.
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

This example assumes a 2-tile device.
Changing stdcore[1] to stdcore[0] should make it work (better change stdcore[] to tile[] too, since stdcore[] is deprecated)
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

Which example does not work?
Yes please - do point us at this error so it can be fixed.
prichner
Junior Member
Posts: 7
Joined: Tue Jan 28, 2014 8:42 am

Post by prichner »

The example is in the XC programming guide page 34.
These two statements doesn't work:
data = waitForKeyStroke(keys );
transmitByte (tx , data );

I think the prototype are missing.

An other question:

I want to make a PWM-signal in one thread. In an other thread I read a button and change with this button the proportion from the PWM-signal(example: 1/2,1/3,...). My problem is: if the thread with the button have a delay or it takes more time, until the thread has finished his programmpart, the PWM-signal has a bigger cycle duration. How can I make, that the PWM-signal have always the same frequency, independent how long the button-thread have.
Here is my code:

Code: Select all

#include <xs1.h>
#include <stdio.h>
#include <platform.h>

out port led1 = XS1_PORT_4F;
in port button1 = XS1_PORT_1K;
out port PWM_signal = XS1_PORT_4C;

void doReadButton1(chanend channel)
{
    int dat,flag_button=0,dat2;
    while (1)
    {
        button1 :> dat2;
        if(dat2 == !flag_button)
        {
            button1 :> dat;
            channel <: dat;
        }
        dat2 = flag_button;
    }
}

void doReadButton2(chanend channel2)
{
    int dat,flag_button=0,dat2;
    while (1)
    {
        button2 :> dat2;
        if(dat2 == !flag_button)
        {
            button2 :> dat;
            channel2 <: dat;
        }
        dat2 = flag_button;
     }
}


void PWM_Signal(chanend channel, chanend channel2)
{
    int cnt =0,data1, data2;
    unsigned int width=64;
    while(1)
    {
        channel :> data1;

        if(!data1)
            width += 5;

        channel2 :> data2;
        if(!data2)
            width  -=5;

        if (cnt < width )
            PWM_signal <: 0b0010;
        else
            PWM_signal <: 0b0000;

        cnt++;
        cnt %= 128;
        width %= 128;
    }
}

int main(void)
{
    while(1)
    {
        chan c,b;
        par
        {
            doReadButton1(c);
            doReadButton2(b);
            PWM_Signal(c,b);
        }
    }
    return 0;
}
Here is the codeblock, where the problem is:

Code: Select all

void doReadButton1(chanend channel)
{
    int dat,flag_button=0,dat2;
    while (1)
    {
        button1 :> dat2;
        if(dat2 == !flag_button)
        {
            button1 :> dat;
            channel <: dat;
        }
        dat2 = flag_button;
        delay_milliseconds(10);  // problem, cause PWM-duration is now changed
    }
}
Could I make it with a timer interrupt or with master/slave?

Ask, if there are questions about the code.
Thanke you for your answer
prichner
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

A regular read from a chanend will block if there is no data available.
To make it unblocking you can use a select statement with a default case.
Something like:

Code: Select all

select {
  case channel :> data1:
    if(!data1)
      width += 5;
    break;
  case channel2 :> data2:
    if(!data2)
      width  -=5;
    break;
  default:
    break;
}
Also you are bitbanging your PWM, so your PWM output depends on the instruction execution speed and branches. This is not the recommended way to do it. XMOS has better ways to do this like timed outputs and buffered ports. See the XC documentation.