Microcontroller based intercom

Thread Starter

ryaowe

Joined May 26, 2015
2
I'd like to make a multi-room intercom for my house that can be used from my Android phone, or from the intercom stations. I've been trying to accomplish this with a PIC32 with a mic connected to an ADC pin, and PWM output to a speaker (with a r/c low-pass filter), and an ESP8266 to send/receive over wifi.

My first step was to try to make the PIC32 read from the ADC and immediately write it out with PWM. But this seems to give me really poor quality audio. I'm not sure if that is from the PIC32's 10-bit ADC, or from the PWM, or something else (mic/speaker quality?). The audio is also way too quiet, but I should be able to solve that with an audio amplifier (maybe an LM386?).

Anyway, I feel like I'm in way over my head with audio input/output. Maybe PIC is the wrong platform. Does anyone have any recommendations on a better microcontroller or peripherals for audio in/out?

Maybe it would be better to do a simple FM-based intercom, and have a raspberry-pi with a receiver that can be the bridge between android and the intercom? I'd be a little worried about privacy with a simple FM transmitter/receiver solution...

My overall goal is for it to be as cheap as possible (so I can afford to make several units for several rooms), and for it to be small enough to fit into a 1-gang electrical box so it can take the place of a light switch (and hopefully I can find a nice small light switch or relay to cram in there with it).

I'm still tinkering with my PIC32+ESP8266 approach, but I'm hoping someone smarter than me can point me in a better direction.
 

AnalogKid

Joined Aug 1, 2013
10,987
Streaming digital audio is not exactly a beginner's task. 10 bits is enough amplitude for voice quality, but you don't say anything about the sampling rate, the other digital contributor to signal quality. Also, what can the D/A handle in terms of word width and sample rate?

As for the volume, you might need a preamp for the microphone ahead of the A/D input. What is the microphone, and what is the peak-to-peak input voltage range of the A/D for full scale? Let's make sure the digital stream is being used to its maximum potential before looking at the output stage.

Separate from that, what is your control protocol for a multi-station intercom? Is there a push-to-talk button at each station? Are all messages broadcast to all stations?

ak
 

Thread Starter

ryaowe

Joined May 26, 2015
2
The PIC32 I'm using (http://ww1.microchip.com/downloads/en/DeviceDoc/60001168F.pdf) says the ADC's max sample rate is 1.1 Msps, but I'm sampling from the PWM timer interrupt, which ends up being about 40kHz.

For D/A, I'm using PWM with a duty cycle of 256 to simulate an 8-bit DAC. I shift off the 2 least significant bits from the 10-bit value read from the ADC. I've played with different resistor and capacitor values for the r/c filter, but haven't been able to notice any difference. The PWM completes ~40000 duty cycles per second. If I construct a sine wave and output it with PWM, it sounds decent, but very quiet.

For the mic, I'm using one that supposedly has a built-in pre-amp: http://www.adafruit.com/products/1063 datasheet: http://www.adafruit.com/datasheets/MAX4465-MAX4469.pdf

I haven't got to the protocol yet... I've been stuck on getting audio input/output to work, and finding a good/cheap platform to build it on. But the goal is to have a push-to-talk button at each station, and all messages broadcast to all stations. My thought was to have a master station (maybe running on a linux box) that all stations send data to over wifi+TCP with the ESP8266. The master station would resend it via TCP to all of the other stations. But I'm definitely open to alternatives. If raw PCM ends up being too big, I was going to consider something like http://www.digikey.com/product-detail/en/WM8510GEDS/RV/WM8510GEDS/RVCT-ND/5036754

I'm not married to PIC32; it's just what I have handy (and happen to have a programmer for). If its ADC is too poorly suited for audio, then maybe dsPIC would be better? Or AVR/ATMega? Maybe a more complete system that has built in audio in/out support?
 

AnalogKid

Joined Aug 1, 2013
10,987
In round numbers, 8 bits amplitude quantizing and 8 kHz sample rate define telephone quality, good enough for the first pass at an intercom.

If you run out of processing bandwidth in the PIC, the codec certainly has everything you need. With it, your only tasks are streaming management and talk control.

Sticking with your original idea of doing it all inside a PIC: For the volume problem, look at the audio signal amplitude entering the PIC and compare this to the A/D setup register values to make sure you are getting full range use out of the PIC. One way to verify this is to test the positive and negative values against two trigger level values set to 90% or 95% of full range and flash an LED if they are exceeded, like a clipping indicator. Or store a sample of the data and examine it manually. Either way, I would first make sure the A/D is giving me reasonable data values, then adjust the D/A and maybe an external amp.

ak
 
Top