mixing clocked input/output

Technical questions regarding the XTC tools and programming with XMOS.
kster59
XCore Addict
Posts: 162
Joined: Thu Dec 31, 2009 8:51 am

mixing clocked input/output

Post by kster59 »

I'm trying to input and output at the same time on a clock edge and something like this:

Code: Select all

out1 <: 1 @ count;
out1 @ (count+10) <: 0; 
in1 @ (count+10) :> myData;
//nextline...
However in the simulation it stalls on the in1 line and never gets to //nextline

Two outputs are ok and something like this works no problem:

Code: Select all

out1 <: 1 @ count;
out1 @ (count+10) <: 0; 
out2 @ (count+10) <: 0; 
However, an input and an output don't work it seems.

An input right after a clocked output doesn't infinite while loop but doesn't give the correct output as far as I can tell:

Code: Select all

out1 <: 1 @ count;
out1 @ (count+10) <: 0; 
in1 :> myData;
What's the correct way to do this? I need to output and input on the same edge.


User avatar
paul
XCore Addict
Posts: 169
Joined: Fri Jan 08, 2010 12:13 am

Post by paul »

Hi kster59,

It would be useful to be able to see how you configure your ports- to get a bit more visibility on what's going on. If the ports are not configured to be using the same clock block then you may encounter some issues.

A comment on your last code snippet - this code will read from in1 immediately after setting the port timer to trigger at a certain point. So it will do the following:

[1] set out1 to '1' and get the port timer value into count
[2] setup out1 to output '0' at count+10
[3] read from in1


None of these operations are blocking.

Cheers,
Paul

On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
kster59
XCore Addict
Posts: 162
Joined: Thu Dec 31, 2009 8:51 am

Post by kster59 »

I played with this some more and noticed:
1) it works fine in release -O3 mode (doesn't work in debug mode)
2) I had a few bit manipulation operations in between the @ counts. Basically in debug mode I couldn't have ANY statements then it works. In release mode it also works.

I think I can just live with no debug mode (which is sort of a pain). I think if I unroll the loop then it would be faster but then the code is much more prone to error...
User avatar
Woody
XCore Addict
Posts: 165
Joined: Wed Feb 10, 2010 2:32 pm

Post by Woody »

If the code works on -O3 but not with lower levels of optimization then the problem must be due to the execution time between lines. One way around this would be to have two threads perform the separate operations: I.e. one for output and one for input. The timestamps are the same no matter what thread reads the timestamp.

You may have a problem though with passing the input time between the threads in time to actually perform the read though, but I would have thought 100ns should be enough. If not, is there a way you can pass the read time to the input thread earlier?

This forum topic discusses some related issues and may be of interest (but also goes off topic a bit)
http://www.xcore.com/forum/viewtopic.ph ... 9&start=10
kster59
XCore Addict
Posts: 162
Joined: Thu Dec 31, 2009 8:51 am

Post by kster59 »

The problem I think is a bug in the Xc language.

The input on a clock edge in debug mode takes much longer than an output statement.

Commenting out the clock edge in debug mode works fine.

Making the input happen not on a clock edge also works fine.

Inserting the clocked input breaks the system.

I did several tests and found this is generally true. A few statements inserted between lines with a clocked input fails under debug mode but works fine for output.
User avatar
Woody
XCore Addict
Posts: 165
Joined: Wed Feb 10, 2010 2:32 pm

Post by Woody »

If you think there's a bug you should issue a support ticket: xmos.com/support/Create New Support Ticket