karawin / Ka-Radio

A wifi webradio with only low cost boards ESP8266 and VS1053 by Jp Cocatrix
Other
426 stars 91 forks source link

VS1053b AAC & WMA internal frequency is too high #80

Open enjoyneering opened 5 years ago

enjoyneering commented 5 years ago

VS1053_WriteRegister(SPI_CLOCKF,0xB8,0x00); // SC_MULT = x1, SC_ADD= x1

Because all VS1053 registers are 16-bit the SPI_CLOCKF value is 0xB800=0b1011 1000 0000 0000 where 15..13-bits is clock multiplier, 12..11-bits addition to multiplier (see p.43):

SC_MULT=0b1010 0000 0000 0000=0xA000= x4.0 not x1 SC_ADD=0b0001 1000 0000 0000=0x1800= x2.0 not x1

The equation for internal clock CLKI at normal speed: CLKI = XTALI x SC_MULT = 12.288 x 4.0 = 49.152MHz. It is OK, because the maximum VS1053 frequency is 55.3MHz (see. p7) But when chip is trying to decode AAC & WMA it may automatically choose to use addition to multiplier SC_ADD. The equation for internal clock at boost speed: CLKI = XTALI x (SC_MULT + SC_ADD) = 12.288 x (4.0 + 2.0)=73.728MHz with recommended maximum 55.3MHz!!!

Recommended SC_MULT=x3.5, SC_ADD=x1 (SCI_CLOCKF=0x8800)

VS1053_WriteRegister(SPI_CLOCKF,0x88,0x00); // SC_MULT = x3.5, SC_ADD = x1

Do not forget your SDI speed is CLKI/4=49.152/4=12.288MHz & SCI speed is CLKI/7=49.152/7=7.02MHz

karawin commented 5 years ago

ok thanks. i will modify it.

karawin commented 5 years ago

You mean? VS1053_WriteRegister(SPI_CLOCKF,0x88,0x00); SC_MULT = x3,5, SC_ADD= x1

enjoyneering commented 5 years ago

Yes 0x88 not 0xB88. But 0x88, 00 will work only for 12.288MHz crystal oscillator aka XTALI. The full equation for different crystals is more complicated & you have to change 2 registers, not one.

I'm working on new VS1053 driver for your awesome project. Will share it some time next month.

P.S. The VS1053 can work with crystal oscillator 12-13MHz & 24-26MHz with some limitations. The recommend frequency is 12.288MHz. It gives you the highest sample rate 48KHz=12.288/256

enjoyneering commented 5 years ago

sorry for off topic

loop Delay(1) in vs1053.h, how much is it in usec or msec? thank you.