Serial audio device with AVR microcontroller.

Summary

Progetto in fase embrionale, ma intanto ho realizzato un AVR-micro che campiona l'audio da un ingresso ADC e lo invia come stream su RS-232. Lato pc รจ possibile ascoltare lo stream molto semplicemente con:

 play -1 -b8 -r 7940 -t raw -u --buffer 64 /dev/ttyS0

This project is still at its beginning. However I managed to have an AVR micro sampling audio from one of its ADC inputs. Then the stream is sent over RS-232. On the host (pc) side, you can listen to the stream with:

 play -1 -b8 -r 7940 -t raw -u --buffer 64 /dev/ttyS0

Note: bitrate 7940 is just experimental. Once the timing will be optimezed bitrate would be standard 8000 (or greater with other kinds of serial i/f). However bitrate setting doesn't prevent play from working, just changes sound pitch and introduces small time-lapse gaps.

In the photo you can see an avrnetio proto board. Network is not used in this project. The led shows sampling activity. Audio comes from the red clip, through a capacitor, and goes in the avr's ADC6 pin. Two resistors polarize the signal at about half range. Serial port is going to the pc.

Firmware

Firmware is very simple and not optimized. No warranty about this (open source) code:

#include <avr/io.h>
#include <avr/interrupt.h>

volatile uint8_t i;

void main(void) {

    cli();
    DDRA |= _BV(PA4)|_BV(PA5);	// as output		Debug Leds
    TCCR0 = _BV(CS01) ;            // timer setup CLK/8
    OCR0=249;
    TIMSK|=_BV(OCIE0);

	ADMUX=_BV(ADLAR);                   //adc setup
	ADMUX|=0b00000110;
	ADCSRA=_BV(ADEN)|_BV(ADIE)|_BV(ADPS1);

	UCSRA=_BV(U2X);               //uart setup
	UCSRB=_BV(TXCIE)|_BV(TXEN);
	UCSRC=_BV(URSEL)|_BV(UCSZ1)|_BV(UCSZ0);
	UBRRH=0;
	UBRRL=16;

	sei();

    while(1) {
    }

}

ISR(TIMER0_COMP_vect){				//8000 Hz
	TCNT0=0;
	PORTA |= _BV(PA4);
	ADCSRA|=(1<<ADSC);	//START CONVERSION
}

ISR(ADC_vect){
	ADCSRA &= ~(1<<ADIF);
	PORTA&=~_BV(PA4);
	PORTA|=_BV(PA5);
	i=ADCH;
	UDR=i;
}

ISR(USART_TXC_vect){
	PORTA&=~_BV(PA5);
}

Application

Possible application is VOIP device. I want to create a cheap voip device using an Aria or other embedded module, but it needs an external audio capture device.

Future expansion

  • Stream to audio signal using PWM or external R2R ladder DAC.
  • Improving of performances.
Navigation

Table of contents

Contact

For any info you can write to:
Per qualunque info potete scrivere a:
info[at]maetech[dot]it

Ads

Print/export
QR Code
QR Code projects:audio-device-avr (generated for current page)