Hardware Reference
In-Depth Information
This divider can be a fractional number and adjusted up and down by tiny bits to make
your sound.
Alas, it turns out that to keep your sound playing smoothly, you need to regularly
adjust the rate, and the Raspberry Pi isn't very good at that. The Pi can run more than
one program at a time, but it has only one processor. It does this by quickly switching
between running programs (multitasking). This normally works well, but in this case,
if another program is running when the clock rate needs adjusting, there will be a glitch
in the sound.
To combat this problem, you can use the Direct Memory Access (DMA) controller. You
can give the DMA controller a list of things to do (e.g., what rate to adjust the sound
to at each point in time), and then it does it in the background, even if the main pro-
cessor is busy running other programs. The PiFM program just makes a list of things
for the DMA controller to tell the clock generator to do and then gets it going.
Accessing Hardware
The Python library calls a C program (provided both precompiled and in source form).
The C program maps the peripheral bus ( 0x20000000 ) in physical memory into virtual
address space using /dev/mem and mmap . To do this, it needs root access, hence the sudo .
Next, it sets the clock generator module to enabled and sets it to output on GPIO4 (no
other accessible pins can be used). It also sets the frequency to 103.3 Mhz (provided
from PLLD@500Mhz , divided by 5), which provides a carrier. At this point, radios will
stop making a “fuzz” noise and become silent.
Modulation is done by adjusting the frequency using the fractional divider between
103.325 Mhz and 102.275 Mhz, which makes the audio signal. The fractional divider
doesn't have enough resolution to produce more than ~6 bit audio, but since the Pi is
fast, you can do PWM to provide about 10 additional bits, giving a total resolution of
16 bits, matching the audio input.
Fun with FM
Here are some ideas of things you might be able to try with PiFm:
Make a repeated playlist (easy)
A simple loop in Python calling play_sound on different sound files should let you
play an entire list of files one at a time.
Make a “mystery sound” game (medium)
Play a sound, and the player must guess which household object makes the same
sound. They can take their radio round the house to try to find a matching sound.
Search WWH ::




Custom Search