How to enable SPDIF output on the VS1010d Developer Board?

Designing hardware and software for systems that use the VS1010 MP3 Audio DSP Microcontroller.
Post Reply
Rogier74
User
Posts: 7
Joined: Fri 2021-09-10 15:31

How to enable SPDIF output on the VS1010d Developer Board?

Post by Rogier74 »

(I tried to post this in another swection of the forum, probably this is a better place)

Hi,

First of all, I'm a newbe on the VS1010. (but I used a lot of VS1011E's in the past, but that's completely different...)


I tried with VSIDE to compile and run a demo, TreePlayer. It works, analogue audio is there, and I'm using that solution as a base for my own application.
I really need a SPDIF output (to connect to a TOSLINK transmitter) for my application.
I use the VS1010 Developer Board to start with, and then I will develop my own boards. Will be 250+ pcs.

But how can I enable the SPDIF output, I checked the handbook, Google and this forum? No clear answer...
Also on the oscilloscope no signals visible.

Please help me, thanks in advance.
User avatar
pasi
VLSI Staff
Posts: 1829
Joined: Thu 2010-07-15 16:04

Re: How to enable SPDIF output on the VS1010d Developer Board?

Post by pasi »

Hi,

The SPDIF in vs1010 is very similar (basically identical) to the one in vs1005g, with the same limitations.
The SPDIF frequency is derived from the core clock frequency (CLKI), so your application will limit which rates are possible.

- Would the spdif output reproduce the same signal as in the DAC?
- Would a fixed 48kHz rate be ok? (Regardless of DAC rate)
- Are you using USB?

(What would be needed is for a fixed CLKI and fixed 48kHz: configure spdif out, including the STX pin as peripheral, set the SRC resample rate and spdif out rates to 48kHz, then in the SRC interrupt copy data to spdif out.)
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
Rogier74
User
Posts: 7
Joined: Fri 2021-09-10 15:31

Re: How to enable SPDIF output on the VS1010d Developer Board?

Post by Rogier74 »

Hi Pasi,

Thanks for your reply.

- I think so... The goal is to produce the best spdif stream if it's possible. That's what my client wants... Their WAV files are 96k/32 bits. It plays well on analogue output of the VS1010D using TreePlayer demo.
- But I'm happy if I have some SPDIF of 48k.
- I'm not using USB, sources are WAV files from sd card, I already understood that working with USB limits the clock frequency that can be used for SPDIF output.

I will digg into the VS1005G. Thanks for pointing me out.
If you have a demo application available, it would be great!

Thanks!
User avatar
pasi
VLSI Staff
Posts: 1829
Joined: Thu 2010-07-15 16:04

Re: How to enable SPDIF output on the VS1010d Developer Board?

Post by pasi »

The VS1010 experts are not available today, but very quick untested suggestions to configure SPDIF out, SRC, and the interrupt routine to copy SRC (resampled DAC) to SPDIF out.

Code: Select all

#include <vs1010c.h>
void SRCInterruptForToslink(void); /* Prototype for the interrupt handler. */

void main(void) {
#define CLKX 5 /* use 5.0x core clock */
	SetPLL(CLKX); /* Make sure the core clock matches our SPDIF configuration setting. */
	
	PERIP(SRC_CF)=0; /*Stop SRC*/
	PERIP(SP_TX_CF) = 0; /*Stop Transmitter*/
	PERIP(GPIO1_MODE) |= GPIO1_SPDIF_OUT; //(1<<14)
	WriteToProgramRam(0x20+INTV_SRC, ReadFromProgramRam((u_int16)SRCInterruptForToslink-1));
	/* SPDIF channel status bits */
	PERIP(SP_TX_CHST0) = 1*SP_TX_CHST0_CP; //No copyright
	PERIP(SP_TX_CHST1) =
		0*SP_TX_CHST1_CLKA //29:28 - "00" 0.1%, "10" - variable pitch
		|1*SP_TX_CHST1_FS  //27:24 - Indicated rate - "0001": rate not indicated
		//|3*SP_TX_CHST1_CH  //23:20 - "0011" sub1:no chnum, sub2:no chnum
 		//|0*SP_TX_CHST1_CH  //23:20 - "0000" sub1:no chnum, sub2:no chnum
		|9*SP_TX_CHST1_CH  //23:20 - "1001" sub1:left, sub2:right
		|0*SP_TX_CHST1_SRC //19:16 - source number
	;
	/* Enable STX and SRC as in-sync as possible. To make sure you could Disable()/Enable() */
	//PERIP(SP_TX_CHST2) = 4*SP_TX_CHST2_CH2_WRDL | SP_TX_CHST2_TX_ENA;
	PERIP(SP_TX_CHST2) =
		0*SP_TX_CHST2_CH2_FSO      //original rate "0000"=not indicated
		| 5*SP_TX_CHST2_CH2_WRDL   //35:33 "101"=24/20bits
		| SP_TX_CHST2_CH2_WRDLM  //32 max sample word length 1=24bits
		| SP_TX_CHST2_TX_ENA;    //Transmitter enable
#if 0
	PERIP(SP_TX_CF) = CLKX*SP_TX_CF_CLKDIV | SP_TX_CF_IE | SP_TX_CF_SND; //96k CLKX=core clock
	PERIP(SRC_CF)=SRC_CF_ENA|SRC_CF_FS*(64-1); //96k
#else
	PERIP(SP_TX_CF) = 2*CLKX*SP_TX_CF_CLKDIV | SP_TX_CF_IE | SP_TX_CF_SND; //48k CLKX=core clock
	PERIP(SRC_CF)=SRC_CF_ENA|SRC_CF_FS*(128-1); //48k
#endif
	PERIP(INT_ENABLE1_HP)|=INTF1_SRC;
}

Strange, .s is not a supported suffix for the forum attachment....
toslinktransmitasm.s:

Code: Select all

#include <vs1010c.h>
//No STX interrupt needed, use SRC interrupt to feed STX
//SRC interrupt outputs directly to STX, must be configured to the same rate!

	.sect code,srcint
	.export _SRCInterruptForToslink
	jmpi _SRCInterruptForToslink,(i6)+1
	.export _SRCInterruptForToslink
_SRCInterruptForToslink:
	stx i0,(i6)+1	//do not save mr0 here
	stx a0,(i6)	; sty i2,(i6)

	ldc SRC_LEFT_LSB,i2   //From SRC to STX
	ldc SP_LDATA_LSB,i0
	LDP (I2)+1,a0
	STP a0,(i0)+1
	LDP (I2)+1,a0
	STP a0,(i0)+1
	LDP (I2)+1,a0
	STP a0,(i0)+1
	LDP (I2)+1,a0
	STP a0,(i0)
	/*
	  WITH VS1005/VS1010, do not touch mr0 (FRACT mode) before taking out P!
	  But we don't need the multiplier or mr0 in this one.
	 */
	ldx (i6)-1,a0	; ldy (i6),i2
	ldc INT_GLOB_ENA,i0
	reti
	STP i0,(i0)	; ldx (i6)-1,i0

	.end
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
Rogier74
User
Posts: 7
Joined: Fri 2021-09-10 15:31

Re: How to enable SPDIF output on the VS1010d Developer Board?

Post by Rogier74 »

It works !!!

Thanks a lot for your fast help!
Very much appreciated!!!

This is a good guidance, I can work on the application.
User avatar
pasi
VLSI Staff
Posts: 1829
Joined: Thu 2010-07-15 16:04

Re: How to enable SPDIF output on the VS1010d Developer Board?

Post by pasi »

Example routines with volume control. The volume can be controlled in 0.5dB steps by SetToslinkVolume(), negative values give higher than 1.0x gain (up to +6.0dB). The signal is saturated so the emphasizing volumes should behave rather okay even if full range.

toslink.c

Code: Select all

#include <vs1010c.h>

void SRCInterruptForToslink(void); /* Prototype for the interrupt. */
void SetPLL(u_int16 n);

extern u_int16 toslinkVol; /* unsigned f_int16 0x8000 is 1.0 */

void SetToslinkVolume(s_int16 vol) {
  static const u_int16 voltab[] = {
    65535,
    61858,   58386,   55109,   52016,   49097,   46341,
    43740,   41285,   38968,   36781,   34716,   32768
  };
  s_int16 sh = 0;
  if (vol < -12) {
    vol = 0;
  } else {
    vol += 12;
  }
  while (vol > 12) {
    vol -= 12;
    sh++;
  }
  toslinkVol = (voltab[vol] >> sh);
}

void main() {
#define CLKX 5
	SetPLL(CLKX); /* Make sure the core clock matches our SPDIF configuration setting. */

	PERIP(SRC_CF)=0; /*Stop SRC*/
	PERIP(SP_TX_CF) = 0; /*Stop Transmitter*/
	PERIP(GPIO1_MODE) |= GPIO1_SPDIF_OUT; //(1<<14);
	WriteToProgramRam(0x20+INTV_SRC, ReadFromProgramRam((u_int16)SRCInterruptForToslink-1));
	/* SPDIF channel status bits */
	PERIP(SP_TX_CHST0) = 1*SP_TX_CHST0_CP; //No copyright
	PERIP(SP_TX_CHST1) =
		0*SP_TX_CHST1_CLKA //29:28 - "00" 0.1%, "10" - variable pitch
		|1*SP_TX_CHST1_FS  //27:24 - Indicated rate - "0001": rate not indicated
		//|3*SP_TX_CHST1_CH  //23:20 - "0011" sub1:no chnum, sub2:no chnum
 		//|0*SP_TX_CHST1_CH  //23:20 - "0000" sub1:no chnum, sub2:no chnum
		|9*SP_TX_CHST1_CH  //23:20 - "1001" sub1:left, sub2:right
		|0*SP_TX_CHST1_SRC //19:16 - source number
	;
	/* Enable STX and SRC as in-sync as possible. To make sure you could Disable()/Enable() */
	//PERIP(SP_TX_CHST2) = 4*SP_TX_CHST2_CH2_WRDL | SP_TX_CHST2_TX_ENA;
	PERIP(SP_TX_CHST2) =
		0*SP_TX_CHST2_CH2_FSO      //original rate "0000"=not indicated
		| 5*SP_TX_CHST2_CH2_WRDL   //35:33 "101"=24/20bits
		| SP_TX_CHST2_CH2_WRDLM  //32 max sample word length 1=24bits
		| SP_TX_CHST2_TX_ENA;    //Transmitter enable
	PERIP(SP_TX_CF) = 2*CLKX*SP_TX_CF_CLKDIV | SP_TX_CF_IE | SP_TX_CF_SND; //48k CLKX=core clock
	//PERIP(SRC_CF)=SRC_CF_ENA|SRC_CF_FS*(32-1); //192k
	PERIP(SRC_CF)=SRC_CF_ENA|SRC_CF_FS*(128-1); //48k
	PERIP(INT_ENABLE1_HP)|=INTF1_SRC;
}
toslinktransmitasm.s

Code: Select all

#include <vs1010c.h>

//No STX interrupt needed, use SRC interrupt to feed STX
//SRC interrupt outputs directly to STX, must be configured to the same rate!

	.sect data_x,toslinkvol_x
	.export _toslinkVol
_toslinkVol:
	.word 0x8000	//1.0x unsigned f_int16

	.sect code,srcint
	.export _SRCInterruptForToslink
	jmpi _SRCInterruptForToslink,(i6)+1
	.export _SRCInterruptForToslink
_SRCInterruptForToslink:
	stx i0,(i6)+1	; sty i2,(i6)	//do not save mr0 here
	stx a2,(i6)+1	; sty b2,(i6)
	stx a0,(i6)+1	; sty a1,(i6)
	add null,p,a	; stx mr0,(i6)+1
	stx a0,(i6)+1	; sty a1,(i6)
	stx b0,(i6)	; sty b1,(i6)
	/*
	  VS1005/VS1010, do not touch mr0 (FRACT mode) before taking out P!
	 */
	ldc 0x200,mr0
	ldc _toslinkVol,i0
	ldc SRC_LEFT_LSB,i2   //From SRC to STX
	ldx (i0),a1	; LDP (I2)+1,a0
	muluu a0,a1	; LDP (I2)+1,a0
	ldc SP_LDATA_LSB,i0
	add null,p,b
	and b1,null,b1	; mv b1,b0	//>>16 unsigned
	mulsu a0,a1	; LDP (I2)+1,a0
	macuu a0,a1,b	; LDP (I2)+1,a0
	sat b,b		//saturation supports gains over 1.0
	STP b0,(i0)+1
	add null,p,b	; STP b1,(i0)+1
	and b1,null,b1	; mv b1,b0	//>>16 unsigned
	mulsu a0,a1
	add b,p,a	; ldy (i6),b1
	sat a,a		//saturation supports gains over 1.0
	STP a0,(i0)+1	; ldx (i6)-1,b0
	STP a1,(i0)
	ldx (i6)-1,a0	; ldy (i6),a1
	resp a0,a1
	ldx (i6)-1,mr0
	ldx (i6)-1,a0	; ldy (i6),a1
	ldx (i6)-1,a2	; ldy (i6),b2
	ldc INT_GLOB_ENA,i0
	ldy (i6),i2
	reti
	STP i0,(i0)	; ldx (i6)-1,i0

	.end
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
Gibbons
User
Posts: 2
Joined: Wed 2021-10-13 15:49

Re: How to enable SPDIF output on the VS1010d Developer Board?

Post by Gibbons »

Great, thanks for sharing this.
Post Reply