Need help with XC-1A Concurrent tutorial

New to XMOS and XCore? Get started here.
User avatar
chupa
Member
Posts: 10
Joined: Fri Dec 18, 2009 8:05 am

Need help with XC-1A Concurrent tutorial

Post by chupa »

Just got my 1A board and am diving right in to learn. Is there a place around that has the "solutions" to the examples exercises? Ive hit a brick wall on the XC1A-Concurrent-LED-Project tutorial and I'm sure just seeing the right way to complete the task will answer all my questions.

Thanks!


User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Post by Andy »

Hi,

I don't think there are solutions available as such but let us know what problems you're having and we'll try to help.
User avatar
chupa
Member
Posts: 10
Joined: Fri Dec 18, 2009 8:05 am

Post by chupa »

The exercise is to make 4 LEDs flash concurrently.

What your given to start is:

Code: Select all

#include <platform.h>
#define PERIOD 20000000

out port cled0 = PORT_CLOCKLED_0;
out port cled1 = PORT_CLOCKLED_1;
out port cled2 = PORT_CLOCKLED_2;
out port cled3 = PORT_CLOCKLED_3;
out port cledG = PORT_CLOCKLED_SELG;
out port cledR = PORT_CLOCKLED_SELR;

void flashLED (out port led, int period);

int main (void) {
    par {
        on stdcore [0]: { cledG <: 1;
                            flashLED (cled0 , PERIOD);
                        }
        on stdcore [1]: flashLED (cled1, PERIOD);
        on stdcore [2]: flashLED (cled2, PERIOD);
        on stdcore [3]: flashLED (cled3, PERIOD);
    }
    return 0;
}
What ive come up with so far, which compiles but dosent work, is this:

Code: Select all

#include <platform.h>
#define PERIOD 20000000

out port cled0 = PORT_CLOCKLED_0;
out port cled1 = PORT_CLOCKLED_1;
out port cled2 = PORT_CLOCKLED_2;
out port cled3 = PORT_CLOCKLED_3;
out port cledG = PORT_CLOCKLED_SELG;
out port cledR = PORT_CLOCKLED_SELR;

void flashLED (out port led, int period){
	timer tmr;
    unsigned t;
    unsigned isOn = 1;
    tmr :> t;
	led <: isOn;
	t += PERIOD;
	tmr when timerafter (t) :> void;
	isOn = !isOn;
}

int main (void) {
    par {
        on stdcore [0]: { cledG <: 1;
                            flashLED (cled0 , PERIOD);
                        }
        on stdcore [1]: flashLED (cled1, PERIOD);
        on stdcore [2]: flashLED (cled2, PERIOD);
        on stdcore [3]: flashLED (cled3, PERIOD);
    }
    return 0;
}
User avatar
Woody
XCore Addict
Posts: 165
Joined: Wed Feb 10, 2010 2:32 pm

Post by Woody »

Hi Chupa and welcome,

You don't have a while(1) loop. Otherwise the code looks good to me.
User avatar
chupa
Member
Posts: 10
Joined: Fri Dec 18, 2009 8:05 am

Post by chupa »

How would that work exactly? I cant figure it out as your not aloud to put it around the par.

Also is it normal for the xmos to get hot? I didn't notice it until now... its hot to the touch. not burring, just hot.
User avatar
Woody
XCore Addict
Posts: 165
Joined: Wed Feb 10, 2010 2:32 pm

Post by Woody »

Hi apologies for not giving a more specific answer before.

If you put the while(1) in flashLED then all 4 threads continue forever. In the example below, the code just ran sequentially through flashLED once and then exited. When all the 4 threads spawned by the par finished, then main exited.

All I've done below is insert the while(1) into flashLED.

Code: Select all

#include <platform.h>
#define PERIOD 20000000

out port cled0 = PORT_CLOCKLED_0;
out port cled1 = PORT_CLOCKLED_1;
out port cled2 = PORT_CLOCKLED_2;
out port cled3 = PORT_CLOCKLED_3;
out port cledG = PORT_CLOCKLED_SELG;
out port cledR = PORT_CLOCKLED_SELR;

void flashLED (out port led, int period){
	timer tmr;
    unsigned t;
    unsigned isOn = 1;
    while(1)
    {
      tmr :> t;
      led <: isOn;
      t += PERIOD;
      tmr when timerafter (t) :> void;
      isOn = !isOn;
    }
}

int main (void) {
    par {
        on stdcore [0]: { cledG <: 1;
                            flashLED (cled0 , PERIOD);
                        }
        on stdcore [1]: flashLED (cled1, PERIOD);
        on stdcore [2]: flashLED (cled2, PERIOD);
        on stdcore [3]: flashLED (cled3, PERIOD);
    }
    return 0;
}
User avatar
chupa
Member
Posts: 10
Joined: Fri Dec 18, 2009 8:05 am

Post by chupa »

Thanks! that helped clear some questions I had.

I compiled it and sent it to my XC-1A yet I get no action from the LEDs. Not sure what im missing here.
User avatar
leon_heller
XCore Expert
Posts: 546
Joined: Thu Dec 10, 2009 10:41 pm
Location: St. Leonards-on-Sea, E. Sussex, UK.
Contact:

Post by leon_heller »

The G4 chip on the XC-1 and XC-1A does run hot. There's nothing wrong with it.
User avatar
chupa
Member
Posts: 10
Joined: Fri Dec 18, 2009 8:05 am

Post by chupa »

Ah I got it!

Thanks!

Code: Select all

#include <platform.h>
#define PERIOD 100000000
#define PERIODA 20000000
#define PERIODB 300000000
#define PERIODC 400000000

on stdcore [0] : out port cled0 = PORT_CLOCKLED_0;
on stdcore [1] : out port cled1 = PORT_CLOCKLED_1;
on stdcore [2] : out port cled2 = PORT_CLOCKLED_2;
on stdcore [3] : out port cled3 = PORT_CLOCKLED_3;
on stdcore [0] : out port cledG = PORT_CLOCKLED_SELG;
on stdcore [0] : out port cledR = PORT_CLOCKLED_SELR;

void flashLED (out port led, int timeout){
   timer tmr;
    unsigned t;
    unsigned isOn = 0b01110000;
    while(1){
      tmr :> t;
      led <: isOn;
      t += timeout;
      tmr when timerafter (t) :> void;
      isOn = !isOn;
    }
}

int main (void) {
    par {
        on stdcore [0]: { cledR <: 1;
                            flashLED (cled0 , PERIOD);
                        }
        on stdcore [1]: flashLED (cled1, PERIODA);
        on stdcore [2]: flashLED (cled2, PERIODB);
        on stdcore [3]: flashLED (cled3, PERIODC);
    }
    return 0;
}
paverbeke
Junior Member
Posts: 4
Joined: Fri Jun 04, 2010 12:40 am

Post by paverbeke »

Hi,

I am also new to XMOS. I tried the example from the XC-1A documentation and it did not work... When I lifted the code from this thread that implemented FlashLed with the infinite loop (last post) it worked for one iteration and then stopped. Almost as if the while loop was not there. Not sure what to do... I was hoping the examples would be complete. The project was originally built using the wizard for the XC-1A but looks like it was for a single processor device since the cores were not defined.

Is the code available for the demo program that comes with the XC-1A?

I am also experiencing some problems with the board being detected in the run settings screen Sometimes it is there and others it is not detected and does not appear in the list. I have not had enough experience running the IDE to pin it down to a particular sequence.

Any help would be appreciated. As a newbie it helps to have all of this working out of the box. It, for me at least tends to make the experimenting more exciting when things are working as expected.
It is easy for someone with more experience to pinpoint the problem. Also please advise if this is the proper place to be posting this.
Post Reply