How to use one bit of 4b port as PORT_I2S_DAC0 (PORT_I2S_ADC0)

Sub forums for various specialist XMOS applications. e.g. USB audio, motor control and robotics.
Post Reply
susanyin0501
Active Member
Posts: 45
Joined: Thu Apr 20, 2017 9:00 am

How to use one bit of 4b port as PORT_I2S_DAC0 (PORT_I2S_ADC0)

Post by susanyin0501 »

Hi all
In xmos official release source code, just use 1b pin as PORT_I2S_DAC0, like
<Port Location="XS1_PORT_1M" Name="PORT_I2S_DAC0"/>
<Port Location="XS1_PORT_1L" Name="PORT_I2S_ADC0"/>

In my project, 1b port is not enough for ADC and DAC data pins, we shall use every bit of 4b port as ADC and DAC data pins ( at the same time some 1b ports are used as ADC and DAC data pins too)
I'd like to transfer a sample data ( TDM mode, there is 16 channels data in every TDM frame for ADC or DAC ) with one bit ( P4C0, P4C1,P4C2, P4C3) of 4b port ( P4C),

if i write like the following line, compile error will happen
<Port Location="XS1_PORT_4A0" Name="PORT_I2S_DAC0"/> // just one bit of 4A port used DAC0,

what shall we do? thanks


alexjaw
Active Member
Posts: 35
Joined: Wed Jan 24, 2018 9:13 am

Post by alexjaw »

I don't know where you have found your definitions. Have you checked XMOS-Programming-Guide, specifically I/O chapter page 60?
As you need 4 individual lines, you the need to pick 4 1b ports, from the guide: "a 4-bit port is not designed to drive 4 independent signals (e.g. the clock and data lines of a serial bus) - it is better to use independent 1-bit ports".

An example from main.xc in AN00162_i2s_loopback_demo:

on tile[0]: out buffered port:32 p_dout[4] = {XS1_PORT_1M, XS1_PORT_1N, XS1_PORT_1O, XS1_PORT_1P};
on tile[0]: in buffered port:32 p_din[4] = {XS1_PORT_1I, XS1_PORT_1J, XS1_PORT_1K, XS1_PORT_1L};
susanyin0501
Active Member
Posts: 45
Joined: Thu Apr 20, 2017 9:00 am

Post by susanyin0501 »

Hi alexjaw

Thanks for your reply

I know the defination is wrong, and can't compile successfully.

As i said that we had not enough 1 bit port for data line, we should use 4b port as data line.
colin
Experienced Member
Posts: 74
Joined: Mon Dec 16, 2013 12:14 pm

Post by colin »

Hi Susanyin0501,

You can declare a 4-bit port as normal and then use bit shifting to toggle the bits on the port that you want to send. The XS1 function peek is also useful in this instance to maintain the state of the other bits of the port. EG:

on tile [0]: out port my_shared_port = XS1_PORT_4B;

#define MY_SHARED_PORT_BIT_0 0
#define MY_SHARED_PORT_BIT_1 1
#define MY_SHARED_PORT_BIT_2 2
#define MY_SHARED_PORT_BIT_3 3

...
unsigned int data = peek(my_shared_port); //Get current status of 4-bit ports
data |= (1 << MY_SHARED_PORT_BIT_3); //Change only MY_SHARED_PORT_BIT_3 of the 4-bit port
my_shared_port <: data; //Drive out the new data (which has maintained the state of the other 3-bits.
...

As long as you are careful to maintain state its fairly straightforward to use a 4-bit port as 4 one bit ports.

Colin
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

susanyin0501, we had a similar conversation some time ago here http://www.xcore.com/viewtopic.php?p=32248#p32248 where I provided some sample code to use 16ch in/out using 4x4b ports.

How did that go? Are you now saying you would like 4b port support for TDM?
susanyin0501
Active Member
Posts: 45
Joined: Thu Apr 20, 2017 9:00 am

Post by susanyin0501 »

Colin, thanks for your solution! I'll try it.
susanyin0501
Active Member
Posts: 45
Joined: Thu Apr 20, 2017 9:00 am

Post by susanyin0501 »

infiniteimprobability,yes, we'd like to use every bit of 4b port support for TDM ( 16 channel data in every TDM frame), at the same time use 1b port support TDM too.
In our project,
P4C0 - P4C3 send 4 TDM stream independently (DAC)
P4E0 - P4E3 receive 4 TDM staram independently (ADC)
P1H0 send 1 TDM stream (DAC)
P1I0 receive 1 TDM stream (ADC)

How to do it ? thanks
Post Reply