XC-1A tutorial: Flash multiple LEDs concurrently (help!)

New to XMOS and XCore? Get started here.
User avatar
Chendy
Active Member
Posts: 46
Joined: Tue Nov 02, 2010 4:53 pm

XC-1A tutorial: Flash multiple LEDs concurrently (help!)

Postby Chendy » Sun Nov 07, 2010 2:09 pm

I have been following the XC-1A examples within eclipse, but I am stuck on the "Flash multiple LEDs concurrenty" problem.

I have lifted the following code from this post, but it doesn't compile.

Should this code work? Has anybody tested it? Can anybody post a working solution for the XC-1A board?

Note sure what to try next, any help greatly appreciated

Chendy

Code: Select all

/*
============================================================================
Name : xc1a-concurrent-led.xc
Description : Illuminate multiple LEDs concurrently on the XC-1A board
============================================================================
*/
#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;
}
User avatar
waluigi
Member++
Posts: 22
Joined: Sun Nov 07, 2010 6:33 pm

Postby waluigi » Sun Nov 07, 2010 6:36 pm

What error message do you get? It compiles for me.

You need "isOn = ~isOn;" instead of "isOn = !isOn;" though for it to flash.
User avatar
Chendy
Active Member
Posts: 46
Joined: Tue Nov 02, 2010 4:53 pm

Postby Chendy » Sun Nov 07, 2010 7:06 pm

Hi waluigi,

Thanks for the response.

I have changed !isOn to ~isOn (I understand the difference).

I am not sure what this means: The code does seem to compile, and upload to the board (as far as i can tell, as the lights on the board change), but nothing seems to happen on the board, just two leds are on constantly. Also before and after compilation the XMOS IDE (eclipse) underlines 3 lines of code in the main loop, each line annotated as a "syntax error" (see attached picture).
XMOS XC-1 problem.png
I have now realized that I in fact have a "XC-1 1V0" board not a XC-1A. Maybe this is the source of some of the problems.
You do not have the required permissions to view the files attached to this post.
User avatar
waluigi
Member++
Posts: 22
Joined: Sun Nov 07, 2010 6:33 pm

Postby waluigi » Sun Nov 07, 2010 10:52 pm

Dont worry about the syntax errors in the IDE - that's just the Eclipse text editor getting confused about some XC syntax.

If you've got a "XC-1" not "XC-1A" you need totally different code. See the XC-1 tutorial.
User avatar
Chendy
Active Member
Posts: 46
Joined: Tue Nov 02, 2010 4:53 pm

Postby Chendy » Mon Nov 08, 2010 11:03 am

Hi again,

I have found the XC-1 examples. They all work fine. I will now see if I get the multicore xc-1a example working on the xc-1.

Thanks for the help

Chendy

Who is online

Users browsing this forum: No registered users and 1 guest