How to use the Sine Test on the VS1053b

Writing software for systems that use VLSI Solution's devices as slave codecs to a host microcontroller.
Post Reply
jtlechem
User
Posts: 16
Joined: Tue 2022-05-10 23:54

How to use the Sine Test on the VS1053b

Post by jtlechem »

Hi there,

Two questions, hopefully simple:
1. Can the Old Sine Test output a frequency of 25Hz?
2. For the New Sine Test, how do I find/know/set the Fs value? (in order to use the equation given for what to write to SCI_AICTRLn)

Background: I'm using the VS1053b on a breakout board from Adafruit (https://www.adafruit.com/product/1381). Controlling the vs1053 with an Arduino Uno and writing a program in a .ino script. I'm using the Adafruit VS1053 Library from github to help code (https://github.com/adafruit/Adafruit_VS1053_Library).

Just trying to use the sine test following the vs1053 datasheet pg. 67-68 (https://www.vlsi.fi/fileadmin/datasheets/vs1053.pdf). Trying both the old test and the new test.

Old Sine Test:
Can the sine test output a sine wave of 25Hz?
To make sure I'm even using it right, here's what I wrote to play a sine at test frequency of about 1000Hz.

Code: Select all

void sineTest() {
  int n = 0b1111011;  // ~1000Hz. FsIdx = 0b111 = 7 which makes Fs = 12000. 
                      		// S = 1000Hz*128/12000 = 11(ish) = 0b1011. So n = 0b1111011
  reset();	// hard reset.
  sciWrite(0x0, 0x0020);  // 0x0 is the SCI_MODE register. 0x0020 is 0b10000 which assigns 1 to the SM_TESTS bit (bit 5)
  spiwrite(0x53);
  spiwrite(0xEF);
  spiwrite(0x6E);
  spiwrite(n);
  spiwrite(0x00);
  spiwrite(0x00);
  spiwrite(0x00);
  spiwrite(0x00);
}
The equation, F = Fs*S/128, seems to be limited by the lowest Fs of 11025Hz and a value "S" of only 1. Is there a way to have S be lower than one to get a lower frequency? or is there a way to have a lower Fs?


New Sine Test
I believe I know what to write in my script for this, except I'm lost at the samplerate (Fs) value.
What is the value to use for Fs in the equation SCI_AICTRLn = Fsin * 65536/Fs ? Do I need to assign a samplerate on the chip before starting the sine test? If so, how? Can the New Sine Test do a 25Hz sine wave?
User avatar
pasi
VLSI Staff
Posts: 2016
Joined: Thu 2010-07-15 16:04

Re: How to use the Sine Test on the VS1053b

Post by pasi »

Note that by writing 0x0020 to SCI_MODE you're also turning off the NEWMODE bit. That means the Serial Data Interface no longer uses xDCS and the same CLK and SI pins as the Serial Control Interface.

1.The lowest possible non-zero sine frequency for the "old" sine test is 1/128*12000Hz = 93.75Hz (n = 0xe1). You could potentially first start the test with these parameters and then write 3200 (0x0c80) as a samplerate to SCI_AUDATA to get 25Hz. (Disclaimer: I didn't test this or look at the source code, so it might not work.)

2. The new sine test uses the samplerate that is active at a time. By default after reset the rate is 8000Hz and can be read from SCI_AUDATA. You can set a rate by writing to SCI_AUDATA before starting the new sine test. Because the frequency control value(s) has more bits, the new sine test can certainly produce 25Hz with various samplerates.

SCI_MODE = 0x4c00 //our setup uses the shared mode with just one chip select shared between SCI and SDI
SCI_CLOCKF = 0x8000
SCI_AUDATA = 0xbb80
SCI_AICTRL0 = 0x0580 //1031.25Hz @ 48000Hz
SCI_AICTRL1 = 0x0580
SCI_AIADDR = 0x4020

For example 0x89 at 12kHz rate gives 25.085Hz, 0xcd at 8000Hz gives 25.024Hz, etc.

You can use SCI_VOL to adjust the volume.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
jtlechem
User
Posts: 16
Joined: Tue 2022-05-10 23:54

Re: How to use the Sine Test on the VS1053b

Post by jtlechem »

Thank you for the help, I was able to get the sine test running and can control the volume on demand.
pasi wrote: Thu 2022-07-21 10:03 Note that by writing 0x0020 to SCI_MODE you're also turning off the NEWMODE bit. That means the Serial Data Interface no longer uses xDCS and the same CLK and SI pins as the Serial Control Interface.
You're right - it looks like it should be 0x820, which is 0b100000100000, which sets SM_TESTS (bit 5) to "allowed" and SM_SDINEW (bit 11) to "yes".

Thank you for the help with the New Sine Test, I went with that one since it can get the 25 Hz. I didn't bother trying to get it with the Old Sine Test.

For others' future reference, these 6 lines start the New Sine Test. Simply write the desired values to these specified sci registers. In this case, I chose 8000 Hz samplerate, which required AICTRL0/1 to be 205 to get an output frequency close enough to 25Hz.

Code: Select all

/*  
  Notes:
  - Use the "New Sine Test" from vs1053b datasheet pg. 68. https://www.vlsi.fi/fileadmin/datasheets/vs1053.pdf
  - SCI_AICTRL0 sets left channel frequency.
  - SCI_AICTRL1 sets right channel frequency.
  - SCI_AICTRLn = F_sin*65536/samplerate
  "n" refers to either 0 or 1 (left or right channel) which can be set to unique frequencies.
  "samplerate" is selected by user by writing it to SCI_AUDATA
*/
musicPlayer.sciWrite(VS1053_REG_MODE, 0b100000100000);  // SM_TESTS (bit 5) is "allowed", and SM_SDINEW (bit11) is "yes" (0x820 = 0b100000100000)
musicPlayer.sciWrite(VS1053_REG_AUDATA, 8000);  // Choose samplerate. 0x1F40 = 8000Hz samplerate
musicPlayer.sciWrite(VS1053_SCI_AICTRL0, 205);  // left channel frequency. 205*8000Hz/65536 = 25.024Hz
musicPlayer.sciWrite(VS1053_SCI_AICTRL1, 205);  // right channel frequency
musicPlayer.setVolume(50, 50); // left and right channel volumes
musicPlayer.sciWrite(VS1053_SCI_AIADDR, 0x4020);  // Start sine test
The musicPlayer object, register definitions, setVolume() function, and sciWrite*() function are all specific to my hardware setup (Arduino Uno + Adafruit VS1053 Breakout). Using the Adafruit VS1053 Library for Arduino, #include <Adafruit_VS1053.h>
jtlechem
User
Posts: 16
Joined: Tue 2022-05-10 23:54

Re: How to use the Sine Test on the VS1053b

Post by jtlechem »

When I write to the SCI to change the volume values, should I expect to measure a different voltage out of the Lout and Rout pins of the headphone jack?
I'm not measuring any change in voltage there when I change the volume, so it just got me curious what exactly is creating the louder or quieter volume of the output signal?
User avatar
pasi
VLSI Staff
Posts: 2016
Joined: Thu 2010-07-15 16:04

Re: How to use the Sine Test on the VS1053b

Post by pasi »

Are you measuring DC or AC?

The outputs are biased around 1.23V (or 1.65V if you managed to set the higher reference). If you measure in DC mode against the ground, you'll probably see a value around that. (Depending on your headphone connection, you could try measuring between GBUF and LEFT.)
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
Post Reply