Binary to Decimal

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Binary to Decimal

Post by rp181 »

I am reading a bunch of ADCs, an 8 channel one. The ADC gives out data on 8 pins, where each pin is a channel. For example, assuming a 5 bit number, the ADC gives:

Code: Select all

Channel 1 is 10100
Channel 2 is 01110
Channel 3 is 11101

then the 8 bit port will report:
101    (The first digits)
011    (The second digits)
111
010
001
In reality, it is a 10 bit ADC, so I will be reading it in as shorts (correct?). I need a FAST way to convert this into decimal. What I am thinking of now is to bitmask the first digits out, and bitshift. E.G:

Code: Select all

: 
Bitmasked data: 1,0,1,0,0
char i = 0;
for all digits:
   if(digit == 1){
    i++;
}
    i << 1;
Is there a more efficient way? This, among doing other things, needs to run at an excess of 100kHz, and hopefully, up to 1MHz.

EDIT: Also, how many streaming channels can you have in a G4?
EDIT: Ok, so I found that it has 5 links. However, when i try and compile, it says

Code: Select all

Core 0 in node "0" has 4 streaming channels and 4 non-streaming. This will deadlock the pswitch.
Shouldn't 4 be ok?


User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

rp181 wrote:
EDIT: Also, how many streaming channels can you have in a G4?
EDIT: Ok, so I found that it has 5 links. However, when i try and compile, it says

Code: Select all

Core 0 in node "0" has 4 streaming channels and 4 non-streaming. This will deadlock the pswitch.
Shouldn't 4 be ok?
Each core has 4 links to the switch. You can have 4 streaming channels in total but you will not be able to use additional regular channels in that case. If you want to use regular channels in addition to streaming limit the number of streaming channels to three. This does not go up for streaming channels between two threads on the same core: you can use as much of them as you want because the traffic is not passing the switch.
User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Post by rp181 »

Ok, thanks. Also, what is it called when a thread is listening to multiple channels, but it is first come first serve, instead of blocking? E.G:

Code: Select all

//4 threads of these
chan <: blah;

//1 thread
void rec(c1,c2,c3,c4){
//listen to c1-c4, but not neccesarily c1 first, whatever is available first
}
User avatar
TSC
Experienced Member
Posts: 111
Joined: Sun Mar 06, 2011 11:39 pm

Post by TSC »

To do that, you need a select statement with guards.

Code: Select all

//1 thread
void rec(c1,c2,c3,c4){
  int rcv = 0;
  select{
    case c1 :> rcv:
      //Do stuff
      break;
    case c2 :> rcv:
      //Do stuff
      break;
etc...
    default:
      // This runs when none of the previous cases are triggered.
      break;
  }
}
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Generically

Code: Select all

void rec(c,x){
  int rcv = 0;
  select {
    case c[0] :> rcv:
    //do stuff
    break;
.....
  case c[x] :> rcv
    //do stuff
    break;
  }
}
Where x is number of receivers/ADC channels and c is a channel array

But maybe using buffered 1 bit ports for the ADC channels in the first place might be more efficient than a single port, it would also lead to a different aggregation/processing scheme.

Can you use single bit ports?

P.S. what's the ADC yo are using? and could you use 8 bit ADCs instead?

regards
Al