Timestamp Output on 4bit port Topic is solved

If you have a simple question and just want an answer.
JohnDoe
Junior Member
Posts: 6
Joined: Mon Aug 08, 2016 5:06 pm

Timestamp Output on 4bit port

Post by JohnDoe »

Hi everyone,

I am trying to use the timed output on a 4bit port, but when I am timestamping another port assignment as reference, the code seems to get stuck. Please see the code below:

Code: Select all

unsigned  lr_mask = 0x80000000;
out buffered port:32 p_lrclk = XS1_PORT_1G;
out port p_my_lrclk = XS1_PORT_4D;

int count = 0;

while(1){
lr_mask = ~lr_mask;
p_lrclk <: lr_mask @ count; //<-- Here the code seems to get stuck

count += 500;

p_my_lrclk @ count  <: lr_mask; 
}
Sorry for this newbie question, maybe someone knows if timestamping is possible at all for 4bit port outputs.

Best regards
John
View Solution
User avatar
johned
XCore Addict
Posts: 185
Joined: Tue Mar 26, 2013 12:10 pm

Post by johned »

Hi John,
You need to use a "select" to support multiple events.
There are a number of app notes here that will help :
https://www.xmos.com/support/examples?secure=1
A good place to start is : AN10075: How to use a select function.
Also the programming guide : https://www.xmos.com/support/tools/prog ... ent=17653.
Best regards,
John
JohnDoe
Junior Member
Posts: 6
Joined: Mon Aug 08, 2016 5:06 pm

Post by JohnDoe »

Hi John,

thank you for your response. I still don't understand how to delay the assignment for 500 clock cycles as I actually don't want to have multiple events.

Best regards,
John
User avatar
johned
XCore Addict
Posts: 185
Joined: Tue Mar 26, 2013 12:10 pm

Post by johned »

Ah, I think I understand, John,
You need to use a timer.
This should help : https://www.xmos.com/download/private/A ... rc4%29.pdf

All the best,
John
JohnDoe
Junior Member
Posts: 6
Joined: Mon Aug 08, 2016 5:06 pm

Post by JohnDoe »

Hi John,

thank you very much, this looks much better. As far as I can see this seems to be blocking (i.e. this is like a sleep_us command). I have some more code in my actual while loop (simplified the example for Q&A) which I would like to be executed, though I need the output to be delayed with respect to the output of

Code: Select all

 p_lrclk <: lr_mask; 


The actual code looks something like

Code: Select all


while(1){
p_lrclk <: lr_mask;
p_my_lrclk <: lr_mask; //do this after x cycles

someFancyFunctionsCalledHere();  //uses approx some 1-2k ClockCycles
}

Is there any way to do this without having to count clock cycles in the "FancyFunctions"?

Best regards
John
User avatar
johned
XCore Addict
Posts: 185
Joined: Tue Mar 26, 2013 12:10 pm

Post by johned »

Hi John,

There are a number of timer related app notes here : https://www.xmos.com/support/examples?secure=1

Including AN10045: How to periodically perform an action using a timer.

Best regards,
John
JohnDoe
Junior Member
Posts: 6
Joined: Mon Aug 08, 2016 5:06 pm

Post by JohnDoe »

Hi John,

thanks for the link to the ressources. I found a workaround for the original code which I am going to share here in case someone else has the same problem:

Code: Select all

unsigned  lr_mask = 0x80000000;
out buffered port:32 p_lrclk = XS1_PORT_1G;
out port p_my_lrclk = XS1_PORT_4D;

int count = 0;

while(1){
p_my_lrclk <: lr_mask @ count; //capture timestamp here 
lr_mask = ~lr_mask;
p_lrclk <: lr_mask; 

count += 500;

p_my_lrclk @ count  <: lr_mask;
}
which works good enough for me. Appearently capturing a timestamp from a buffered port does not work or there is an issue with cross-timestamping between different ports.

Thank you for your support,

Best regards
John
User avatar
infiniteimprobability
Verified
XCore Legend
Posts: 1164
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

there is an issue with cross-timestamping between different ports.
Yes - there is no guarantee that the port counter will have the same value. It all depends which clock they are attached to (default 100MHz ref clock) and when they were started.

You can guarantee that they are the same by doing something like:

Code: Select all

clock clkblk = XS1_CLKBLK_1;

set_clock_ref(clkblk); //Connect to 100MHz ref
set_port_clock(p_one, clkblk);
set_port_clock(p_two, clkblk);

start_clock(clkblk); //All timers of connected ports will be zeroed and will be in perfect sync
Much of our IP (including SDRAM and I2S) uses this trick
User avatar
larry
Respected Member
Posts: 275
Joined: Fri Mar 12, 2010 6:03 pm

Post by larry »

As infiniteimprobability explained, starting a clock block makes times of all ports attached to the clock block synchronised (reset to 0).