Rockbox

Tasklist

FS#7178 - Sansa e200 FM tuner support

Attached to Project: Rockbox
Opened by Ivan Z (zivan56) - Wednesday, 16 May 2007, 23:11 GMT
Last edited by Michael Sevakis (MikeS) - Wednesday, 06 June 2007, 19:24 GMT
Task Type Patches
Category FM Tuner
Status Closed
Assigned To No-one
Operating System Sansa e200
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Initial support for the Sandisk Sansa e200 FM tuner (Sanyo LV24020LP).
It is initialized as soon as rockbox is started and there is no volume control (BEWARE if you use in ear headphones).

Still needs to be done:
- tuning (now tunes to around 91Mhz and AFC finds something nearby)
- volume control
- Recording

Datasheets:
http://www.rockbox.org/twiki/pub/Main/DataSheets/AN2400S04.pdf (explains in general how to tune)
http://www.semiconductor-sanyo.com/ds_e/ENA0070.pdf (registers for this specific tuner)

Make sure it put tuner_sanyo.c in the /firmware/ folder

If someone could look into the tuning details, as the datasheet is not very specific in some parts.
This task depends upon

Closed by  Michael Sevakis (MikeS)
Wednesday, 06 June 2007, 19:24 GMT
Reason for closing:  Accepted
Additional comments about closing:  Now part of SVN.
Comment by Charles Philip Chan (cpchan) - Thursday, 17 May 2007, 04:02 GMT
Hood work, it works. However, I can't seem to turn it off (I tried every single button).

Charles
Comment by Ivan Z (zivan56) - Thursday, 17 May 2007, 09:57 GMT
Tuning support!
1.Very crude and causes possible race condition (tune very slowly to avoid this).
2.Set the region to US/Canada for best results.
3. Not using specifications, so frequencies are a bit off and hackish; see the FM debug screen for actual frequencies.
4. Scanning is not supported.

Buttons now work correctly, volume still needs to be figured out.
Initial radio start needs to be done correctly as well, as it starts on the main menu instead of the actual FM screen.
Comment by Ivan Z (zivan56) - Friday, 18 May 2007, 22:37 GMT
Improved tuning with faster tune times and more precision. Now, very close to real frequency set, give it ~10 secs for AFC to centre the frequency.

Scanning is supported, and scan time is somewhat acceptable. No more race conditions hopefully when scanning.

Initial tuning takes some time, but not a problem after that

Still need to work on muting when tuning, along with starting radio at proper time.
Volume support also needs to be implemented.

Comment by Ivan Z (zivan56) - Monday, 21 May 2007, 02:56 GMT
Fixed:
- Volume control now implemented
- Play/pause works
- Synced with SVN

Did some code cleanup as well.

Overall, quite usable now. Still have to force stereo, as an algorithm for fine tuning is needed.
Setting the region to Europe and fine adjusting manually usually allows you to get stereo sound. Adding +0.2Mhz to desired frequency seems to be what works for me, but it may not be a fixed offset for all frequencies.
Comment by Michael Sevakis (MikeS) - Tuesday, 22 May 2007, 07:19 GMT
I'm for having this in SVN in order to facilitate getting the recording and input muxing properly enabled even if it's not perfect yet.
Comment by Ivan Z (zivan56) - Tuesday, 22 May 2007, 20:01 GMT
That would be nice. It would be great if someone could double-check the tuner init procedure and see if it is correct (I am sure it is not 100% right).
- Synced with SVN
- Lowered gain on line1 in so that people with IEMs don't get high pitched sounds
Comment by Ivan Z (zivan56) - Tuesday, 22 May 2007, 23:11 GMT
New algorithm for tuning, which greatly improves frequency centering and sound quality. However, it is still off by 0.2Mhz.
No more whining noises
Comment by Michael Sevakis (MikeS) - Thursday, 24 May 2007, 03:21 GMT
I just tried this out and it is 200kHz off but it also doesn't tune most of the major, strong stations in. US/Canada region.
Comment by Michael Sevakis (MikeS) - Thursday, 24 May 2007, 12:49 GMT
I think I've figured out how to work this thing and like most of these tuners, you have to compensate for the IF when setting the tuner frequency. I also tweaked up the bit driver to be more compact and auto-select the register block (only changes it when needed...less error prone, fewer write calls)...if you're interested in that I can post it.
Comment by David Maliniak (major_works) - Thursday, 24 May 2007, 15:37 GMT
I don't know if *he's* interested, but for what it's worth, if you've already got an improved version of the patch, *I'm* interested. Let 'er rip, I say...
Comment by Ivan Z (zivan56) - Thursday, 24 May 2007, 22:00 GMT
Please post it. I seem to have been unsubscribed from this patch for some reason.
Have you booted to the OF radio before? I commented out the init part of the code so that the OF takes care of setting it properly.
Comment by Michael Sevakis (MikeS) - Friday, 25 May 2007, 09:19 GMT
I'm not going to skip any init code and I'll see if I can just get it to work our own way for what rockbox requires. IMO, having to search for cap values to set the frequency implies "cheap as crap IC" otherwise you'd just be able to select it all directly. The fact this is all done in software says: "flexibility" = "cheap as crap so we don't add that circuitry". ;)

I'm guessing the Euro version doesn't have the radio is because the small 50kHz frequency steps required means scanning will be dismally slow there...OF is nastily slow here with 200kHz ones and misses all sorts of stuff it should pick up. I've used the OF radio and it's pretty lousy and slow but all OF radio code I've checked is just that and doesn't work worth a 5#17.

Well, I'll try to remedy that if possible.
Comment by Ivan Z (zivan56) - Friday, 25 May 2007, 18:47 GMT
I see someone has been reading the datasheet :)
The radio works decently in Europe, I don't live there, but it caught quite a number of stations when set to the World region. It has trouble finding some stations, especially if the station is very close to another one. The reason they don't have radio support in Europe is due to the EU Radio tax, which would add on to the price of the player. Either way, the OF still works better than what I have posted...
radio5.diff had a totally different approach to scanning, which didn't work tool well, but I though it *should* have considering it was going though all cap/osc values and seeing which ones match the frequency best.

It would be interesting to compare results with a Cowon D2, which seems to have the same Sanyo chip.
Comment by Michael Sevakis (MikeS) - Sunday, 27 May 2007, 09:05 GMT
I was going to go with the tax thing but it almost seems to absurd. :)

To summarize what I've worked on from your code:
1) make code style follow rockbox guidelines
2) use symbolic constants for everything - defined them completely for all registers
3) automatic reg block switching and OR default "1" bits into RADIO_CTRL1 automatically
4) shadow writeable registers - this leaves a few single-byte gaps but tracking which bits are set isn't needed
5) reverse the IF_PM_L bit as clearing the bit mutes it - init steps 2 and 3 work fine now
7) actually write the FM_OSC value calculated by the cap searching routine - it _tends_ more toward tuning correcly (details below)
9) remove some unneeded stuff like the pow function
10) start adding things needed by the radio interface in general
11) implement radio regions directly in the driver - the details of region setting for the radio ICs really are low-level and I plan to address that for all others - radio.c can still implement the frequency ranges and grid

There could be a problem with precision in the math that seems to make it tune the chip to the same frequency for several different specifiec ones. If so, I have no problem using 64-bit ints or perhaps rescaling calulations will work too. Overflow can be a problem too. A scheme to speed up the searching will definitely be needed.
Comment by Michael Sevakis (MikeS) - Monday, 28 May 2007, 04:15 GMT
Update: Tuning rock solid now. Does about 3 loops to find the cap and two to fine tune it within 32kHz so about 80ms to tune a station. The cap search should be able to be sped up I think.
Comment by Alessio Lenzi (lenzone10) - Monday, 28 May 2007, 20:00 GMT
Hello, synce december 2006, Sansa E200 FM Radio is available in Europe too.
I bought it one month ago in Italy.
Unfortunately I haven't development environment to compile Rockbox, otherwise I could tray to do it.
If you send me a compiled version, I'd be happy to test it.
Comment by Michael Sevakis (MikeS) - Wednesday, 30 May 2007, 09:54 GMT
This is my little bit added in. Hopefully it will tune well in other regions and won't need more precision so that it stay fast...it shoots for +/-16kHz.

Setting the input level down is too quiet compared to playback btw.

TODO recap:
* Improve tuning algorithms more over Sanyo's to actually converge better and faster on the desired frequencies.

* Perhaps allow a few hundred HZ slop in the IF_OSC setting since this register bounces around a bit and is hard to set accurately which just leads to longer radio init at times. I don't know why it stays more stable for long runs then seems to be unruly for long runs. OF seems to take awhile to set this as well. hrm.

* Perhaps retune IF_OSC to have less interference from internal noise when tuning weaker stations? The OF suffers this too but the interference drops away when it idles the cores. In Rockbox, button/scrollwheel activity seems to improve reception...wtf?

* Really implement station detection to be accurate for scanning.

* Do all the other work to properly integrate radio into the e200 audio system.
Comment by Michael Sevakis (MikeS) - Sunday, 03 June 2007, 16:50 GMT
Synced to recent keymap changes.
Comment by Jacob Brooks (jac0b) - Tuesday, 05 June 2007, 12:35 GMT
Can't get current SVN to build with this patch applied, also it give out an error when patching. I attached the .rej file.

patching file firmware/target/arm/sandisk/sansa-e200/ata-e200.c
Hunk #3 FAILED at 67.
Hunk #4 succeeded at 243 (offset 1 line).
Hunk #5 succeeded at 282 (offset 1 line).
Hunk #6 succeeded at 298 (offset 1 line).
Hunk #7 succeeded at 366 with fuzz 1 (offset -1 lines).
Hunk #8 FAILED at 417.
Hunk #9 FAILED at 434.
Hunk #10 FAILED at 499.
Hunk #11 succeeded at 580 (offset -1 lines).
Hunk #12 succeeded at 650 (offset -1 lines).
4 out of 12 hunks FAILED -- saving rejects to file firmware/target/arm/sandisk/s
ansa-e200/ata-e200.c.rej
Comment by Jacob Brooks (jac0b) - Tuesday, 05 June 2007, 12:37 GMT
DISREGARD THE ABOVE COMMENT. THIS IS THE CORRECT ERROR.
Can't get current SVN to build with this patch applied, also it give out an error when patching. I attached the .rej file.

patching file firmware/drivers/audio/as3514.c
Hunk #1 FAILED at 114.
1 out of 1 hunk FAILED -- saving rejects to file firmware/drivers/audio/as3514.c.rej
Comment by Jack Suter (chrisjs169) - Wednesday, 06 June 2007, 10:54 GMT
Yes jac0b, someone moved a few lines around in there (why?)

I'm working on getting a patch working
Comment by Jack Suter (chrisjs169) - Wednesday, 06 June 2007, 11:14 GMT
as3514.c has a lot of fuzz, because I didn't bother to change the line numbers, but it works.

Loading...