CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Need help with ADC of PIC8720

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
csshah



Joined: 28 Feb 2005
Posts: 24

View user's profile Send private message

Need help with ADC of PIC8720
PostPosted: Tue Mar 22, 2005 8:37 am     Reply with quote

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");
     
   }
}
Best Wishes
Guest







PostPosted: Tue Mar 22, 2005 11:05 am     Reply with quote

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
csshah



Joined: 28 Feb 2005
Posts: 24

View user's profile Send private message

PostPosted: Tue Mar 22, 2005 12:10 pm     Reply with quote

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
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 22, 2005 1:09 pm     Reply with quote

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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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