Nerdy notes » History » Version 5

Giulio Moro, 2016-03-08 12:54 AM

1 1 Giulio Moro
h1.  Nerdy notes 
2 1 Giulio Moro
3 1 Giulio Moro
This is just a collection of notes from/for developers. Sometimes it is also useful to know the mistakes that others made so not to waste your time when we already wasted ours. Note that if you attempt any of the hacks here it might void your warranty. Do not do this, please.
4 1 Giulio Moro
5 1 Giulio Moro
h2. Media clock on the Beaglebone Black with BeagleRT cape
6 1 Giulio Moro
7 1 Giulio Moro
The media clock is hardcoded to 44.1kHz. This can be changed by changing the PLL values in I2c_codec::startAudio.
8 1 Giulio Moro
Current settings are as follows
9 2 Giulio Moro
10 1 Giulio Moro
<pre>
11 1 Giulio Moro
writeRegister(0x02, 0x00)	// Codec sample rate register: fs_ref / 1
12 1 Giulio Moro
writeRegister(0x03, 0x91)	// PLL register A: PLL enabled, Q=2, P=1
13 1 Giulio Moro
writeRegister(0x04, 0x1C)	// PLL register B: J= 7
14 1 Giulio Moro
writeRegister(0x05, 0x52)	// PLL register C: D=5264, part 1
15 1 Giulio Moro
writeRegister(0x06, 0x40)	// PLL register D: D=5264, part 2
16 1 Giulio Moro
</pre>
17 2 Giulio Moro
18 1 Giulio Moro
Notes:
19 2 Giulio Moro
For extensive reference check the TLV320AIC3104 Audio Codec reference manual http://www.ti.com/lit/ds/slas510d/slas510d.pdf, pages 45-46
20 1 Giulio Moro
Q is not relevant as PLL is disabled 
21 1 Giulio Moro
J range is 1 to 63
22 1 Giulio Moro
D range is 0 to 9999
23 1 Giulio Moro
P range is 1 to 8
24 1 Giulio Moro
R range is 1 to 16
25 1 Giulio Moro
K=J.D=7.5264
26 1 Giulio Moro
P=1
27 1 Giulio Moro
R=1
28 1 Giulio Moro
PLLCLK_IN uses MCLK
29 1 Giulio Moro
CLKDIV_IN uses MCLK
30 1 Giulio Moro
PLLCLK is 12MHz
31 1 Giulio Moro
These values plugged in
32 1 Giulio Moro
  f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P)
33 1 Giulio Moro
will give 44100
34 2 Giulio Moro
35 1 Giulio Moro
36 1 Giulio Moro
The media clock can be changed setting different values for J and D. As it is currently structured, the PRU loop does not allow you to get much faster than 48000kHz (J.D=K=8.1920) as you will start getting underruns.
37 1 Giulio Moro
38 5 Giulio Moro
h3. Measure media clock drift with respect to the CPU 
39 4 Giulio Moro
40 4 Giulio Moro
On the BeagleRT cape the 12MHz clock is generated by the same master clock that drives the CPU, so these are going to be synced forever and ever (that is, do not expect any drift to occur between the media clock and the system clock).
41 4 Giulio Moro
To verify that this actually is the case, the follwing patch to PRU.cpp allows to log the time that takes for the PRU to get back to the ARM audio thread.
42 3 Giulio Moro
<pre>
43 3 Giulio Moro
		static RTIME elapsedTime; // in nanoseconds
44 3 Giulio Moro
		static RTIME startTime=0;
45 3 Giulio Moro
		static long long int count=0;
46 3 Giulio Moro
47 3 Giulio Moro
		while(pru_buffer_comm[PRU_CURRENT_BUFFER] == lastPRUBuffer && !gShouldStop) {
48 3 Giulio Moro
			rt_task_sleep(sleepTime);
49 3 Giulio Moro
		}
50 3 Giulio Moro
		xenomai_gpio[GPIO_SETDATAOUT] = TEST_PIN_MASK;
51 3 Giulio Moro
		elapsedTime=rt_timer_read();
52 3 Giulio Moro
		xenomai_gpio[GPIO_CLEARDATAOUT] = TEST_PIN_MASK;
53 3 Giulio Moro
		if(count==0){
54 3 Giulio Moro
			rt_printf("values=[\n");
55 3 Giulio Moro
			startTime=elapsedTime;
56 3 Giulio Moro
		}
57 3 Giulio Moro
		if((count&16383)==0 && count!=0){
58 3 Giulio Moro
			elapsedTime=elapsedTime-startTime;
59 3 Giulio Moro
			rt_printf("%llu\n", elapsedTime);
60 3 Giulio Moro
		}
61 3 Giulio Moro
		count++;
62 3 Giulio Moro
</pre>
63 3 Giulio Moro
64 3 Giulio Moro
Ideally it should be @elapsedTime==numAudioBufferSamples*16384.0/samplingRate*1e9 ±0.25*sleepTime@
65 1 Giulio Moro
assuming that @sleepTime==numAudioBufferSamples/SamplingRate/4.0@
66 1 Giulio Moro
Experimental results show that it is the case (see attached files clockanalysis.m , logovernightInPru.m, error.png)
67 5 Giulio Moro
68 5 Giulio Moro
h2. Preparing the board for building Supercollider
69 5 Giulio Moro
Updated 8/3/2016
70 5 Giulio Moro
71 5 Giulio Moro
* Resize the partition so that you have at least 1GB available.
72 5 Giulio Moro
* You need an internet connection from the Beaglebone. Good luck with it. 
73 5 Giulio Moro
* Run this to fix an error that you would encounter when apt-get update (Error: W: There is no public key available for the following key IDs:
74 5 Giulio Moro
9D6D8F6BC857C906 )
75 5 Giulio Moro
<pre>
76 5 Giulio Moro
$ sudo apt-get install debian-keyring debian-archive-keyring
77 5 Giulio Moro
$ sudo apt-key update
78 5 Giulio Moro
</pre>
79 5 Giulio Moro
* Try 
80 5 Giulio Moro
<pre>
81 5 Giulio Moro
$ sudo apt-get update
82 5 Giulio Moro
</pre>
83 5 Giulio Moro
If you are getting an error like "Release file expired", make sure the date on your BeagleBone is set correctly (e.g.: by running)
84 5 Giulio Moro
<pre>
85 5 Giulio Moro
ntpdate -b -s -u ntp.org
86 5 Giulio Moro
</pre>
87 5 Giulio Moro
* follow instructions here http://supercollider.github.io/development/building-beagleboneblack.html from step 3 onwards