Issue
110, September 1999
Talking
Back: Adding Speech to Embedded Applications
by
Rodger Richey
Training
embedded apps to process speech may be as easy as
finding the right 8-bit micro. Don't let what Rodger
has to say about using an ADPCM algorithm and PWM
output to generate speech to go in one ear and out
the other.
PERIPHERAL
SPEECH CODER
A
simple encoder/decoder peripheral can be implemented
around a PIC12C672 or a PIC16C556A. The first thing
to consider is the communication interface between the
PIC and the main processor.
Lower
end micros dont have any type of serial or parallel
peripherals but they can be easily implemented in firmware.
The complete code shows routines that can perform I2C,
SPI, and RS-232 communications with a host processor,
and Figure 3 shows a block diagram for an I2C
implementation on a PIC12C672.
Figure 3The PIC12C672 provides
the smallest solution for a serial coder peripheral.
In addition to the I2C signals SDA
and SCL, this device features an interrupt and
encode/decode select signals.
|
Because
the microcontroller is implementing the serial interface
in firmware, the application must ensure a good handshaking
method to keep the micro from overflowing. A parallel
interface routine is much easier to develop than the
serial protocols, and Figure 4 shows an example of the
parallel interface to a PIC16C556A.
Figure 4The PIC 16C556A provides
a cost-effective parallel-interface solution to
a speech coder peripheral. In addition to the
standard parallel interface signals, it provides
an interrupt and encode/decode select signals.
|
The
master I2C routine uses approximately 77
words of program memory and 5 bytes of data memory.
MPASM must also be used to assemble this file.
One
consideration when designing a system based around this
routine is the transfer rate. If the PIC is the master
of the interface, then the transfer rate is solely determined
by the clock source to the microcontroller. If the PIC
is a slave on the interface, then the transfer rate
depends on the clock source as well as the firmware
overhead to sample the incoming data.
The
SPI slave routine uses approximately 16 words of program
memory and 2 bytes of data memory. The same consideration
concerning clock rate applies to this routine as well.
Because of the overhead of sampling the SDI pin, the
maximum clock frequency for SPI slave is at least 18
instruction cycles, where one instruction cycle is the
oscillator frequency divided by four.
The
RS-232 routine uses approximately 54 words of program
memory and 3 bytes of data memory. Although you should
check to make sure that the micro has plenty of overhead,
the transfer rate of RS-232 is usually much less than
the PICs oscillator frequency.
This
routine only requires the user to define the oscillator
frequency and the transfer rate. Several equations allow
MPASM to calculate the necessary delays for bit times.
After
the communication protocol is chosen, you have to put
all the pieces together. First you need to implement
some type of data request from the main processor to
the micro (for master) or from the PIC to the main processor
(for slave).
The
micro must control the flow of data to/from the main
processor because the communication interface is implemented
in firmware and not hardware. Otherwise, data may be
lost. For a slave implementation, a single I/O line
from the PIC connected to an external interrupt pin
on the host processor easily accomplishes this.
The
other important piece of information is the type of
operation to be performed: encode or decode. This step
can be accomplished two ways. First, a unique command
from the host processor to the microcontroller can set
the operation to follow. The host processor then initiates
an encode or decode sequence by sending the command
for encode or decode.
For
an encode sequence, the host processor sends two 16-bit,
2s complement samples to the PIC. The PIC then
responds with two 4-bit ADPCM codes packed into one
byte. A decode sequence reverses the order. One byte
of ADPCM codes are sent to the PIC, which responds with
two 16-bit, 2s complement samples.
The
second method is to use an I/O line from the host to
the PIC to indicate an encode operation (I/O pin pulled
low) or a decode operation (I/O pin pulled high). Note
that encode and decode operations should not be mixed
together.
All
of the data to encode or decode should be sent consecutively
to the micro. Once all of the data has been processed,
the host processor can change the type of operation
to be performed.
This
requirement is due to the fact that the ADPCM algorithm
processes the next data based on previous data. Anytime
the operation is switched, the encoder or decoder is
initialized to a cleared state.
One
other consideration is the selection of clock source
to drive the PIC. The PICs oscillator structure
is flexible so either an external clock from the host
processor or a local oscillator can be connected to
it.
If
your application has one system clock that drives all
devices on the board, this same signal can be driven
into the oscillator input on the PIC. Otherwise, a standard
oscillator circuit can be used to provide the clock
signal.