View previous topic :: View next topic |
Author |
Message |
radiofm
Joined: 12 Jan 2006 Posts: 9 Location: Poland
|
Reading audio signal |
Posted: Wed Dec 06, 2006 9:11 am |
|
|
Hello
i want to read voltage of audio signal <20 KHz - two channel and send this to RS232 output
I want to use PIC16F877A (analog inputs in this PIC)
i am a newbie - please tell me witch example i must use in PCM ?
i think than firs channel i must connect to RA0 input, second channel to RA1 input
IN RA3 i must set reference voltage ?? (becouse it's a audio signal ?)
Thanks
Sorry for my english |
|
|
Ttelmah Guest
|
|
Posted: Wed Dec 06, 2006 10:42 am |
|
|
Seriously, this is a hard project, and may not even be possible!.
What 'word' size do you intend to sample the ADC with?. Even if you use 8 bit sampling, you will be generating 40000 bytes/second, which will need a serial rate of over 400Kbps. Getting the timing right at this srt of rate, will be _hard_. To generate a baud rate that is accurate at this sort of speed, will require chosing a non-standard oprating frequency for the PIC. Few PC UARTs, can be set to this sort of rate either...
You need external circuitry to scale the audio to a reasonable range (perhaps +/-2v), and offset it, so that idle it sits at +2.5v. Provided your 5v supply is smooth, you do not need an external Vref, but you need extremely careful design round the processor if noise is not going to be a problem. Getting the loop timing right, an this fast, will probably require you to synchronise the sampling to a timer.
You should consider starting with something much simpler first. learn how to send a low frequency signal, from something like a joystick, and the difficulties/circuitry involved, before trying to tackle something this complex.
Best Wishes |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Dec 06, 2006 1:12 pm |
|
|
What do you mean by "read the voltage of audio signal"? Do you want to digitally sample it and export the samples so it could be reconstructed? Or do you just want to measure its amplitude? If the latter do you want a peak reading or peak to peak? Or do you need to calculate the RMS value (total energy)? _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
radiofm
Joined: 12 Jan 2006 Posts: 9 Location: Poland
|
|
Posted: Wed Dec 06, 2006 3:33 pm |
|
|
hello
first - sorry for my english - sometime i have a problem explain what i need
OK - my project it's a FM tuner
in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=28918
i start working at this
now hardware working - and i try write a software for this.
i can set this tuner to frequency (thanks PCM programmer !)
now i want to control the situation when music stop playing
No music - no voltage on tuner output
probably easier to do is a change AC audio voltage to DC using Full Wave Rectifier and measure DC voltage i PIC
Robert |
|
|
radiofm
Joined: 12 Jan 2006 Posts: 9 Location: Poland
|
|
Posted: Thu Dec 07, 2006 12:30 pm |
|
|
ok - i do measuring audio signal using full wave rectifier and preamp with 2 diodes 1N4148 and 1 op amp NE5532. this convert ac audio signal in input to DC signal and this going to PIC.
program:
Code: |
#include <16F877A.h>
#device adc=10
#fuses HS, NOWDT, NOPROTECT
#use delay(clock=10000000)
#use rs232(baud=19200, xmit=PIN_C1, rcv=PIN_C2, bits=8, parity=N)
#use i2c(sda=PIN_C4,scl=PIN_C3)
long freq,pll;
// now i start DS1621
void temp_config(byte data)
{
i2c_start();
i2c_write(0x90);
i2c_write(0xac);
i2c_write(data);
i2c_stop();
delay_ms(11);
}
void init_program()
{
i2c_start(0);
i2c_write(0x90);
i2c_write(0xee);
i2c_stop();
temp_config(8);
//now we set radio to frequency
freq = 930; // i want to listen radio at 93 MHZ
pll = freq+107;
pll= pll/0.05; //step = 50 KHz
i2c_start(); //start i2c
i2c_write(0xC2); //adress TSA5511 Philips PLL
i2c_write(pll/256/10); // DB1
i2c_write(pll/10); // DB2
i2c_write(0x80); //CB
i2c_write(0x00); //PB
i2c_stop();
//now i start analog input i want to measure voltage
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
set_adc_channel(0);
}
// now i measure temperature with DS1621
byte read_temp()
{
byte datah,datal;
long data;
i2c_start();
i2c_write(0x90);
i2c_write(0xaa);
i2c_start();
i2c_write(0x91);
datah=i2c_read();
datal=i2c_read(0);
i2c_stop();
data=datah;
datal=data;
return(datal);
}
main()
{
byte temp;
init_program();
do
{
temp = read_temp();
// this is a RS232 output
// temperature
printf("\n\r@TEMP=%u",temp);
delay_ms(500);
// input voltage in mV
printf("\n\r@LEFT=%Lu",((Read_ADC())*49)/10);
delay_ms(500);
}
while (TRUE);
}
|
(code to DS1621 i found in internet)
I using only one channel of analog input in PIC16F877A
please tell me - is it possible to read simultaneously 2 channels ?
i don't know how to configure this.
now i have in rs232 output: somethig like:
@TEMP=22 //now 22 degress in my room
@LEFT=2111 //2111 mV on left channel output
i want to add Right channel for example:
@TEMP=22
@LEFT=2111
@RIGHT=2322
thanks for help
i am a newbie
Robert |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Dec 07, 2006 12:46 pm |
|
|
You can't read two channels simultaneously.
But you can try to read both fast.
look at fig 11-1 of the spec. All the analog pins are muxed into ONE a to d converter. Thus no simultaneous read.
But you could try to
1.set chan A
2.read
3.set to chan B
4.read
5.loop |
|
|
radiofm
Joined: 12 Jan 2006 Posts: 9 Location: Poland
|
|
Posted: Thu Dec 07, 2006 12:55 pm |
|
|
thanks for reply
something lihe that ?
Code: |
set_adc_channel(1);
printf("\n\r@LEFT=%Lu",((Read_ADC())*49)/10);
delay_ms(500);
set_adc_channel(2);
printf("\n\r@RIGHT=%Lu",((Read_ADC())*49)/10);
delay_ms(500);
|
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Dec 07, 2006 1:28 pm |
|
|
You need a short delay between switching channels and reading like:
Code: |
set_adc_channel(1);
delay_ms(1);
printf("\n\r@LEFT=%Lu",((Read_ADC())*49)/10);
set_adc_channel(2);
delay_ms(1);
printf("\n\r@RIGHT=%Lu",((Read_ADC())*49)/10);
|
_________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|