Vous êtes sur la page 1sur 4

PROJECTS

Robotalk from an
ATtiny microcontroller
Gert Baars, g.baars13@chello.nl

Changing your voice into that of a robot is a task that is perfectly suitable for a microcontroller.
This circuit shows how this can be performed by a simple setup built around a small ATtiny45
microcontroller.

A voice changer that emulates a so-


called Cylon voice can be implement-
ed with the help of a small microcon- +5V
R1 C1
troller. Those of you who have watched
10k

the (recent or older) TV series of Battle- R2


56p
8

330k
VCC

PB5

star Galactica will immediately know K1 R3


R4
2
V+ PB3
470k

7
what we’re talking about. For the non-
220k

PB2 C2
5 R5
IC2 PBO IC1 3
SF fans amongst you, this is a metallic P1 P2 PB4 470R
1

C3 C4
7

3 2u2
sounding robot voice. C5 ATtiny45
5

500k 500k 10V


6
100n 100n LF356
The circuit can be used as a gadget, 2 6
GND

100n PB1
4

IN P3
but was originally designed to show R11 R12 R10 C7
4
470k

4k7

27k

how a simple digital circuit could be 2n2


R13 R9
used for audio processing. 50k C8 C6
33R

MIC1
1k

1u
0 16V 470n

Hardware GND

The hardware (Figure 1) consists of a


V+
pre-amplifier built round opamp IC2, C10 C9
which has a gain of about 70. This is K2 100u 10u
sufficient to amplify microphone sig- 16V 16V
1

R14 R15 R16 GND 3


6

V+ IC3 +5V C14


nals. R1 and K1 can be used to sup- 220 1k 4k7
8

OUT
5
V+ 78L05 IC4
ply the microphone with a DC voltage, 1 2 2 C17
100u
16V
4

which is required by electret types. C15 C16 C18 P4


LM386-N3
47n
3

C11 C12 C13


The pre-amplifier feeds the amplified 50k R18
10R

100n 22n 4n7


signal to the ADC input of the ATtiny45 100n 100n 22u
16V 0
controller, which then processes it.
GND GND
Since the clock for the controller
070859 - 11
doesn’t have to be very accurate the
internal RC oscillator has been used
as the clock generator. It has an out-
put with a frequency of about 8 MHz, Figure 1. The voice changer consists of a pre-amp, a microcontroller and a power amp.

40 elektor - 3/2008
which is doubled to 16 MHz by an in- mum input frequency is 5 kHz. As the quency. Since the ‘Cylon’ circuit usu-
ternal PLL. This method ensures that ‘Cylon’ circuit is meant for speech sig- ally operates with speech signals,
two inputs remain free on the 8-pin nals, this is more than sufficient. which are mostly below 3 kHz, there
controller for connecting the two po- The Nyquist Theorem isn’t that difficult is no need for an elaborate filter when
tentiometers. These are used to set the to understand if we first consider what sampling at 10 kHz.
required ‘Cylon’ effect. sampling does in the frequency do- After reading each sample the control-
If two other ADC channels were used main. During the sampling period the ler software carries out certain proc-
for reading the two potentiometers input signal can be thought of as mul- esses to obtain the ‘Cylon’ effect. The
it would mean that the audio input tiplied by ‘1’ and during the remaining result is then fed to the PWM output of
would be interrupted by the inter- period by ‘0’. This is in principle the the controller. This generates a square
nal MUX whilst reading those inputs, same as 100% AM modulation with a wave with a variable duty cycle at
which would be detrimental to the au- square wave, which results in an AM output PB4 of the ATtiny45. After inte-
dio quality. It is therefore preferable to spectrum as shown in Figures 2a and grating this through an RC filter (R14
read the potentiometers by timing the 2b. From these you can clearly see that to R16, C15, C16, C18) the audio signal
charging of an external capacitor. overlapping occurs when the sampling reappears.
The ‘Cylon’ software reads in the audio frequency is less than twice the high- This signal is then fed to audio amplifi-
signal with a sampling frequency of est input frequency, which leads to er IC4, which makes the sound audible
about 10 kHz. According to the Nyquist distortion. This goes to show how im- via a loudspeaker. Setting the jumper
Sampling Theorem the sampling fre- portant a good input filter is before the on header K2 to the other position by-
quency has to be at least twice that of ADC. This so-called anti-aliasing filter passes the power stage, so that the
the highest frequency in the input sig- blocks components that are higher in signal can be fed to the line input of,
nal. From this it follows that the maxi- frequency than half the sampling fre- for example, a computer.

f sample f sample
a b
A A

IN Aliasing Aliasing IN Aliasing Aliasing

f 070859 - 12a overlap at f 070859 - 12b


f s < 2x f in _max

Figure 2. This shows that overlapping occurs when the sampling frequency is less than twice the highest component of the input signal.

3/2008 - elektor 41
PROJECTS VOICE CHANGER

instruction is the record head, and a near 250 Hz sounds about the same as
IN OUT load instruction is the play head. the original 'Cylon' robots.
The amount of delay is set using P1.
P2
The position of P1 is used by the soft-
P1 ware to set the position of the tap in
Construction
the ring-buffer. P2 is used to set the Figure 4 shows the board layout for
td = N x ts N>0
strength of the delayed feedback sig- the voice changer. Populating the
N=0
nal. With a larger feedback signal the board should be simplicity itself, with
decay becomes less resulting in a all components clearly laid out. The
070859 - 13 stronger effect. controller can be obtained ready-pro-
P1 is used to set the tap to positions grammed from Elektor Shop as item
between 1 and 200 in the ring-buffer. 070859-41. If you prefer, you could
Figure 3. Graphical representation of the FIFO register,
The delay is therefore variable from program it yourself (software 070859-
configured here as a ring-buffer.
100 Ms to 20 ms. Since the delayed sig- 11, but make sure you use the correct
nal is fed back in a loop the damped settings for programming the chip, as
Software resonances will become noticeable shown in the inset).
when the damping is small enough. If you use an electret microphone you’ll
The software has to carry out a number This is the so-called 'Cylon' effect. The need to place a jumper across K1. The
of tasks. The main one is the reading, frequency of these resonances is 1/de- jumper on K2 selects the type of output
processing and outputting of the audio lay-time and can therefore be set be- signal (pins 2-3 uses the output ampli-
signal, but there are also two potenti- tween 50 Hz and 10 kHz. A setting fier, pins 1-2 for a line output signal).
ometers that have to be read. As the
ADC is fully occupied with reading the
audio signal, an internal counter and
comparator are used to read in the po-
070859-1
tentiometer values. First of all, C1 is (c) Elektor C12 - +
C9

C11
discharged. Then an internal counter IC2 C13 C10

OUT
R2
R11
R3

is started and C1 is charged via the po- R10


IC3
C1

R16
C15
C6
R4
tentiometer to a certain voltage, when
0 R1

0
C16
R5
C2
R9
the counter is stopped. The resulting
C5

C17
R12

C18
IC4
counter value is then dependant on the
R14

R15
R18 C14
resistance of the potentiometer. K1 C4 C8
K2
IN

C3 P3 P2 IC1 C7 R13 P1 P4
To put it simply, the ‘Cylon’ effect is ob-
tained by mixing a delayed version of
the input signal with the direct input
signal, and delaying the resulting sig-
nal again, and so on.
The same principle can be used to ob-
tain an echo effect, but then the delay
of the input signal needs to be at least
Figure 4. A small PCB has been designed for the voice changer, which makes the construction very easy.
100 ms, whereas in the ‘Cylon’ version
the delay is much smaller. The inter-
nal FIFO buffer used for obtaining the
delay is 200 bytes long, so with a sam-
pling frequency of about 10 kHz the COMPONENTS LIST
maximum delay can only be 200/10 kHz C1 = 1µF 25V
C9 = 10µF 25V
= 20 ms. Resistors C10,C14 = 100µF 25V
In Figure 3 you can see a graphical R18 = 107 C13 = 22µF 25V
representation of this method. The R9 = 337 C7 = 2nF2
R14 = 2207 C16 = 22nF
wheel ‘turns’ anti-clockwise with one R5 = 4707
revolution every 20 ms and represents R13,R15 = 1k7 Semiconductors
the FIFO buffer, configured as a ring- R12,R16 = 4k77 IC1 = ATtiny45, programmed, Elektor Shop
buffer. The input signal is mixed with R1 = 10k7 # 070859-41
R10 = 27k7 IC2 = LF356
the delayed output signal (shown here R4 = 220k7
using a potentiometer), creating a new IC3 = 78L05
R2 = 330k7 IC4 = LM386-N3
output signal that is fed back again to R3, R11 = 470k7
the start of the ring-buffer. P1,P2 = 500k7 Miscellaneous
The same effect can also be achieved P3,P4 = 50k7 K1 = 2-way SIL pinheader
mechanically with the use of magnet- K2 = 3-way SIL pinheader
Capacitors MIC1 = electret microphone
ic tape and separate record and play C1 = 56pF PCB, ref. 070859-1, see www.elektor.com
heads, with the latter having a variable C2 = 2µF2 25V Project software, 070859-11.zip, free
position to set the delay time. C18 = 4nF7 download from www.elektor.com
C17 = 47nF PCB layout, free download from www.ele-
The software is in effect a simulation of C6 = 470nF
this method, where the memory is the ktor.com
C3,C4,C5,C11,C12,C15 = 100nF
equivalent of the magnetic tape, a store

42 elektor - 3/2008
The circuit doesn’t require much cur-
rent, which depends mainly on the
output amplifier (between 25 mA and
150 mA). You could therefore us a 9 V
battery as long as you don’t use the
circuit for long periods. When you don’t
use the output amplifier stage the
current consumption drops to about
25 mA.
When you first switch it on it is best to
set the effect to minimum. When you
hear an undistorted audio signal you
know that the circuit functions proper-
ly, so you can then increase the amount
of effect. Too much effect eventually
results in no audio at all (as you can
work out from Figure 3). This can be
set precisely using P1, giving a good
effect whilst keeping the speech clear-
ly understandable.
(070859-I)

Settings for programming the controller P1 and P2 settings


Fuses: - Brown-out detection disabled: BODLEVEL=111 - P1: Smaller value  higher frequency.
- PLL clock: CKSEL=0001, SUT=11 - P2: Larger value  bigger effect.

Advertisement

&*$$! !,!$'%!&* $) *)  !))!) !)* (+'%!&*

'/4 :.+ (+9: 9:'8: =/:. !:'8: +>6+8/3+4:/4- ".+ '! ,+':;8+9
 3/)85)54:8522+89 =/:. 85(5:/)9 =/:. :.+ ' 25-/) '4'2?9+8 =/:.
=/:. /1852+1:854/1'9 .  85(5: 1/: 9+8/'2 (;9 *+)5*/4-
)/ *+<+2563+4: 54:'/49 +<+8?:./4- 59)/2259)56+ 6'::+84
9?9:+3 /-.96++* 8+7;/8+* :5 (;/2* =.++2 -+4+8':58 96+):8;3
#!  685-8'33+8 '4* :8')1('9+* 85(5:9 '4'2?9+8 ).'8: 8+)58*+8
/4)/8);/: *+(;--+8 '4* '4* )'88? 5;: ' 2'8-+ '4* 97;'8+='<+%
62+4:/,;2  *+</)+9 54 8'4-+ 5, ,;4 +>6+8/ -+4+8':58 /4 54+ 25=
54+ (5'8* ,58 A 3+4:9 ,58 A )59: /49:8;3+4: ,58 A

!/3/2'8 (5'8*9 '<'/2'(2+ ,58     $  *9 '4* :.+8 85(5: 1/:9 '<'/2'(2+ ('9+* 54    $  += 8'4-+ 5, ./-.96+)/,/)':/54 25-/) '4'2?9+89 ,853
!5 62;9 )536':/(2+ '**54 (5'8*9 '4* )536/2+89 ! !:'36 '4*  62;9 2'8-+ 8'4-+ 5, '))+9958/+9 &+852;9 45= '295 '<'/2'(2+

&*$ /)*!%)  +*&$  +*) $)  **/'&#

".+ 
 3'1+9 +9/-4+* 96+)/,/)'22? ".+  /9 ' 25=
'4 /*+'2 62':,583 ,58 ,58 :+')./4- '(5;:   )59: */-/:'2 )/8);/: 2'(
*+<+256/4- '4* /362+ 3/)85)54:8522+89 :.+ /4)58658':/4- ' 2'8-+
3+4:/4- ';:53':/54 
 /4)58658':+9 952*+82+99 (8+'*(5'8*
'662/)':/549 =/:. /:9  ' ;9+,;2 8'4-+ 5,   65=+8 9;662?
8+2'? 5;:6;:9  56:5 *+</)+9 '4* )53+9 ,;4):/54 -+4+8':58 <52:
/952':+* /46;:9 '4* )5362+:+ =/:. *+:'/2+* 3+:+8 '4* ;9+,;2
:.+84+: )54:8522+8 ,58 +>'362+ 685-8'39 ,58 9=/:).+9 '4* */962'?9
A A ,58 A

 =/*+ 8'4-+ 5, 3/)85)54:8522+8 '4* ('9+* )54:852 :.+8 :8'/4/4- 9?9:+39 '<'/2'(2+ ,58 3/)85)54:8522+8 '4* %+ 9:5)1 685:5:?6/4- 685*;):9 ,853 (8+'*(5'8*9 :5
(5'8*9 '4* '**549 '8+ '295 '<'/2'(2+ +2+):854/)9 :+')./4- '*<'4)+* */-/:'2 '4* '4'25-;+ )/8);/: 2'(9

$!)! )!! + +' *! -!)*! * ---'$*&.% " !,!& %! &!- ' +*)
'2:854/> /3/:+* #4/:
526./4 '4+
/-. !:8++: !5;:.'36:54 !  @ "+2    @ '>   @ 3'/2 9'2+96'2:854/>)53
!+);8+ 542/4+ 58*+8/4- '058 )8+*/: '4* *+(/: )'8*9 '))+6:+* 8/)+9 +>)2;*+ *+2/<+8? '4* $"

3/2008 - elektor 43

Vous aimerez peut-être aussi