void ad7606()
{
configure_clock_rate(clk,100,1);
//configure_port_clock_output(p_clk_out, clk);
configure_out_port(cva, clk, 0);
configure_out_port(cvb, clk, 0);
configure_out_port(cs,clk,0);
configure_in_port(busy,clk);
configure_out_port(rd,clk,0);
os0 <:0x0; os1 <:0x0; os2 <: 0x0;
rage <:0x1;
cva<:0x1; cvb<:0x1;
cs<:0x1; rd<:0x1;
start_clock(clk);//start_clock(clk1);//start_clock(clk2);
unsigned short int temp, advalue=0;
// unsigned int ts;
// unsigned int delay=1000;
unsigned int tm,b;
while(1)
{
printf("while..\r\n");
//delay_milliseconds(1000);
cs<:0x1;
cva<:0x0 @ tm;cvb<:0x0;
tm+=3;
cva @ tm <:1; cvb @ tm <:1;
busy when pinseq(1) :>b;
//if(b) printf("busy\r\n");
//b=1;
select
{
case b=> busy when pinseq(0) :>b @ tm:
tm+=2;
cs @tm<:0;
for(int i=0;i<8;i++)
{
rd <:0 @tm;
tm+=2;
rd @tm<:1;
tm+=20;
ad4 @tm:>temp;
advalue=temp;
ad3:>temp;
advalue=(advalue<<4)|temp;
ad2:>temp;
advalue=(advalue<<4)|temp;
ad1:>temp;
advalue=(advalue<<4)|temp;
//c<:advalue;
printf("[%d]advalue=%d \r\n",i,advalue);
}
//cs<:1;
//cva<:0x0 @tm;cvb<:0x0;
//cva @tm+2 <:1; cvb @tm+2 <:1;
//delay_milliseconds(1);
break;
}
}
}
OUTPUT:
while..
[0]advalue=0
[1]advalue=6440
[2]advalue=6443
[3]advalue=6474
[4]advalue=6442
[5]advalue=6455
[6]advalue=6452
[7]advalue=6476
while..
Why this program is executed only once?
xmos XA board - AD7606 sampling
-
- New User
- Posts: 3
- Joined: Sun Jun 28, 2015 9:07 am
-
- XCore Legend
- Posts: 1913
- Joined: Thu Jun 10, 2010 11:43 am
Suspecting that tm (counter period) is expiring by the time you reach your 2nd iteration of the loop due to the very slow printf call at the start of the loop.
So, probably locking here (on the 2nd iteration):
cva<:0x0 @ tm;
As a work around, you could increase the value of tm at the end of your loop to a much larger value before you hit the break. However, read on for better ideas.
The use of printf is very slow unless you are following these recommendations:
https://www.xmos.com/support/tools/docu ... component=...
Suggestions:
1) to debug, remove the use of printf and save the values into a local array.
2) use a debug build of your program and set breakpoints to examine the contents of the array after reading.
The idea is to remove the large delays related with printf. You can follow the above article on how to improve the use of printf (debug in real-time using printf).
Some excellent short articles worth reading are posted here:
http://www.xmos.com/support/examples
So, probably locking here (on the 2nd iteration):
cva<:0x0 @ tm;
As a work around, you could increase the value of tm at the end of your loop to a much larger value before you hit the break. However, read on for better ideas.
The use of printf is very slow unless you are following these recommendations:
https://www.xmos.com/support/tools/docu ... component=...
Suggestions:
1) to debug, remove the use of printf and save the values into a local array.
2) use a debug build of your program and set breakpoints to examine the contents of the array after reading.
The idea is to remove the large delays related with printf. You can follow the above article on how to improve the use of printf (debug in real-time using printf).
Some excellent short articles worth reading are posted here:
http://www.xmos.com/support/examples