![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
csshah
Joined: 28 Feb 2005 Posts: 24
|
Need help with ADC of PIC8720 |
Posted: Tue Mar 22, 2005 8:37 am |
|
|
Hi all
I am using a simple code to read an audio input on channel 0 of pic8720. I dont know what I am doing wrong but when i put REF voltage as VDD and VSS it gives me some fixed values like 0000 0001 0002 on screen eventhough I didnt connect any ref voltage on Vref+ pin, but when i put setup_port_a(VSS_VREF) it gives me some hex values which seems to be correct. I want to display dB value of audio signal on LCD screen.
Code: |
#include <18F8720.H>
#device *=16 ADC=10
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock = 20000000)
#include<math.h>
#include <stdio.h>
#include <LCD_4bit_test.c>
//setup_adc_ports(NO_ANALOGS);
//SET_TRIS_b(0xFF);
#define CURSOR '~'
#define menu PIN_B4
#define up PIN_B3
#define down PIN_B5
//#use RS232 (BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7)
void main (void){
int16 val;
float f;
int db;
lcd_init(); //LCD initialization
delay_ms(800);
set_tris_a(0xFF);
//setup_port_a( ANALOG_AN0_TO_AN5 | VSS_VREF);
setup_port_a( ANALOG_AN0_TO_AN5 | VSS_VDD);
setup_adc( ADC_CLOCK_DIV_32 );
while(1){
set_adc_channel( 0 );
delay_ms(10);
val=read_adc();
delay_ms(10);
printf(lcd_putc,"%Lx",val);
//lcd_putc(" ");
//f=(float)val*5/1024;
//printf(lcd_putc,"%2.3f",f);
//lcd_putc(" ");
//db=20*log10((f*0.707)/0.775);
// printf(lcd_putc,"%2.3f",(float)val*4.74/1024);
//printf(lcd_putc,"%ddB",db);
//delay_ms(1000);
//lcd_putc("\f");
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Best Wishes Guest
|
|
Posted: Tue Mar 22, 2005 11:05 am |
|
|
Start by connecting a reference voltage...
The ADC, will not work without a reference source. With the end of the ADC reference left floating, the values are just going to depend on 'luck' on the chip...
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
csshah
Joined: 28 Feb 2005 Posts: 24
|
|
Posted: Tue Mar 22, 2005 12:10 pm |
|
|
Hi
now I connected VREF+ and VREF- as +5 and -5 volts. but still in above program I am reading value of 8dB signal as 1023(val) now using this how can I display dB value on screen and is 1023 indicates number of samples per clock??
reply soon
thanks for help |
|
![](templates/subSilver/images/spacer.gif) |
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Tue Mar 22, 2005 1:09 pm |
|
|
PIC ADCs can't tolerate reference voltage more than a diode drop below ground. Typically VREF- is either ground or some voltage between ground and VREF+.
PIC ADCs are unipolar input only. If you aren't level shifting your audio signal, then you will never get the right answer. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|