Using an external clock

Technical questions regarding the XTC tools and programming with XMOS.
PeterMechEng
New User
Posts: 3
Joined: Wed Jul 18, 2012 1:55 pm

Using an external clock

Post by PeterMechEng »

Hi all,

Firstly I would just like to say that I've only started using XMOS microcontrollers so I'm very inexperienced. So please bear with me!

I have a question regarding the use of an external clock. I'm hoping to use a C++ computer program to send a clock signal to a XC-1A board via a USB connection.

In my XC program I have two threads running on stdcore[0]. One thread is used to receive either bytes of data or bits from the external clock. The other thread is used for processing the input data and outputting the correct signals to the output ports.

My question is this... how can I set up a clock on one thread and then stream the signal via a channel to the other thread? If my code was all running on one thread I know that I would set up the clock as follows:

Code: Select all

out buffered port:4 LEDs = XS1_PORT_4C;     // Button LEDs 1,2,3,4
in port RXD = PORT_UART_RX;                     // setting up RXD to be the IN port
clock clk = XS1_CLKBLK_1;                          // Clock block identifier

void foo(in port RXD, out port LEDs)
{
     configure_clock_src(clk, RXD);
     configure_out_port(LEDs, clk, 0);

     start_clock(clk);

}
If I have the LEDs port being used on another thread though, how do I send the clock signals to it? I can't place

Code: Select all

configure_out_port(LEDs, clk, 0)
in the same thread as the one that I have

Code: Select all

configure_clock_src(clk, RXD)
written because using the LEDs port violates the parallel usage rule. Ideally I would like to output the clock signal to a streaming chanend.

Any help or advice would be greatly appreciated. Thanks.

Peter


User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Post by rp181 »

AFAIK, you can't literally stream a single. What you are suggesting is sharing a hardware resource through a channel, which isn't supported. Channels are used to send data (variables).

Your receiving thread could be on a constant loop of reading the channel, which the source thread would send 1 or 0s on a state change. I don't understand exactly what you're trying to do.
receive either bytes of data or bits from the external clock
Clocks are merely for synchronization, so they don't carry data. Furthermore, why are you trying to send a clock signal through USB?
PeterMechEng
New User
Posts: 3
Joined: Wed Jul 18, 2012 1:55 pm

Post by PeterMechEng »

Thank you for your quick response.

So basically, I want to be able to send the clock signal via USB because the XMOS needs to be able to control devices that are tightly synchronised with other processes that are being performed on the master computer.

I have created my XC program so that the user can send bytes of information (i.e. 8 bits at a time) to configure the output devices, and then once the user wants to actually run the devices my program is triggered to simply receive a continuous stream of alternating bits (10101010... etc) at the known baud rate (1MHz) which I want to use as my external clock signal.

My problem is setting up the clock because I have the output ports on a different thread to the thread which is used for the input port. The only way I can think of solving it is by creating an output port on the receiving thread which is then wired to an input port on the device controlling thread and having the clock signal sent across it. I think it would be better if it could be done using channels however. Maybe this isn't possible though?
User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Post by rp181 »

There's no reason the second thread needs the clock signal. The first thread receives the data, and can send the data on to the second thread. The second thread then processes it as it is received. Synchronization of the threads happens automatically with the sending and receiving of data through channels.
PeterMechEng
New User
Posts: 3
Joined: Wed Jul 18, 2012 1:55 pm

Post by PeterMechEng »

When setting up a clock in XC is it possible to configure a channel output? e.g. instead of writing

Code: Select all

configure_out_port(port_output, clk)
you could have something like the following (I know this function doesn't exist but is there something to the same effect?):

Code: Select all

configure_out_channel(chan_output, clk)
From what I've seen it appears that clocks can only be configured with ports (please correct me if I'm wrong!).

How would I go about receiving the clock signal on one thread and then sending it to another thread using a channel?
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

I highly doubt that what you are trying to do is very sane, but here's
a simple way to do it: make some I/O port clocked by your clock, do
a read from it on thread A (so this waits for the clock); then write a
value (say, 0) into the channel. On thread B, read from the channel
(discarding the value read, 0 isn't very interesting); when the read
completes, you know the clock has pulsed.

You can also wait for the (1-bit) port on which the clock comes in
to change value, directly. That saves a clock block (if you do not need
the clock for anything else, of course).