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

Post by chupa »

Are you sure your doing the tutorials for the XC-1A and not the XC-1? Also make sure your opening the example projects for the 1A and not the 1. The XC-1 has similar tutorials and I made the mistake of opening the 1 , not the 1A examples when called to do so when I started.

I wish I could provide more guidance!


paverbeke
Junior Member
Posts: 4
Joined: Fri Jun 04, 2010 12:40 am

Post by paverbeke »

Hi,

I am sure I am opening the xc-1a. Here is the code generated by the wizard for the concurrent led project, as you can see it is for the xc-1a. However the previous errors pointed out are there.


/*
============================================================================
Name : xc1a-concurrent-led.xc
Description : Illuminate multiple LEDs concurrently on the XC-1A board
============================================================================
*/

#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;
}

Here is the code that I copied from the last post that is supposed to work, but only works once and does
not continue.


/*
============================================================================
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;
}

Again any help from anyone would be appreciated. It looks like it should work... Also would like answers to the other questions I posted previously.

Thanks.
simon
New User
Posts: 3
Joined: Mon Dec 14, 2009 4:37 am

Post by simon »

I'm a beginner myself, but the problem is in the line where you invert isOn. You need to use the bitwise negation ~isOn, which turns 0b01110000<->0b10001111, rather than !isOn which will turn 0b01110000->0b00000000<->0b00000001.

This one bit me at first (which was the other day - looking for help lead me to this thread). XMOS really should provide solutions to these exercises if they want them to be instructive in the very basics of programming in XC.
paverbeke
Junior Member
Posts: 4
Joined: Fri Jun 04, 2010 12:40 am

Post by paverbeke »

Well, I am happy that someone finally got back to me. Thanks for the information, I will give it a try. I had pretty much given up since there were no response to my request. I agree that XMOS needs to pay more attention to the details. If you can not get the examples working there is the underlying question what else has been left out... I think it is a good product with merit, but the needs of the beginner have to be addressed to allow them to progress.

Thanks again.

Paul
User avatar
Chendy
Active Member
Posts: 46
Joined: Tue Nov 02, 2010 4:53 pm

Post by Chendy »

Above code doesn't work for me. Has anybody tested it? Can anybody post a working solution?

Chendy
User avatar
bsmithyman
Experienced Member
Posts: 126
Joined: Fri Feb 12, 2010 10:31 pm
Contact:

Post by bsmithyman »

Just as a note, I notice that the above example uses a timer input inside the loop (i.e. tmr :> t is inside the while loop). While this may seem like a good idea at first, it can actually lead to a slight error in the frequency of the loop. There are a finite number of instructions required to get the time from the timer, and when you add the delay to that time, you're doing it after the additional cycles have passed. If instead you put the timer input before the loop, and just keep incrementing t by the delay inside the loop, it will cycle at the right rate (plus it's more efficient).
User avatar
lilltroll
XCore Expert
Posts: 956
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna

Post by lilltroll »

I cannot see the

Code: Select all

chan c...;
in the beginning of main. You need to described what cled0, cled1 ... is for the compiler. chan is a reserved word for the compiler, the same way as int is.

If you choose new project in XDE ver. 10.4.x, you can choose the example-code with the mouse.
Just choose the correct XC-1 or XC-1A, otherwise it will not run correctly.
Probably not the most confused programmer anymore on the XCORE forum.
User avatar
Chendy
Active Member
Posts: 46
Joined: Tue Nov 02, 2010 4:53 pm

Post by Chendy »

Oops. Realized that I was using a XC-1 board as opposed to a XC-1A. Sort of cleared up some of my problems.

Thanks for the replies - points noted!

Chendy
Post Reply