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 CCS Technical Support

ADC question

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



Joined: 01 May 2005
Posts: 2
Location: Lithuania

View user's profile Send private message Visit poster's website

ADC question
PostPosted: Tue May 03, 2005 11:01 am     Reply with quote

I have PIC18f42 and I want to convert analog value to digital. Now I tested everything with my development board and it works. I measured 4,91V and I got the right result. But I am interested if I will have lets say -6V going to my R0 pin how I need to modify my programm to get right value ? First time posting to this forum, so sorry for possible errors Smile
Here is my program:
Code:

#include <18F452.h>
#device ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

int8 laikinas[100];
signed int8 i;

void main()
  {
     //test
     printf("labas visiems ");

     i=0;

     setup_port_a( AN0 ); //A0 pin
     setup_adc( ADC_CLOCK_INTERNAL );
     set_adc_channel( 0 );

     while(i<98)
       {
         laikinas[i]=read_adc();
         delay_us(10);
         ++i;
       }
       
     i=0;
       
     while(i<98) 
       {
         printf("  %u\n\r",laikinas[i]); //div 52 and we have result (255/4.91)
         ++i;
       }
   }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 03, 2005 12:02 pm     Reply with quote

Quote:
If I will have lets say -6V going to my R0 pin

Read section 22.0 of the 18F452 data sheet:
Quote:
Absolute Maximum Ratings:
Voltage on any pin with respect to VSS (except VDD, MCLR, and RA4) ..... -0.3V to (VDD + 0.3V)

VSS is ground. This means the lowest voltage you can have on RA0
is -0.3 volts. So you can't directly measure negative voltages.

You could use an opamp circuit to invert the negative voltage so it's in
a positive range.

Or, you could use two resistors to make a voltage divider. About
half-way down the following page, there is a schematic diagram which
shows how to do this. Though, the resistor values they use are too
large for the PIC's A/D input requirements. You would need to divide
those resistor values by 10. Also, depending on the maximum negative
voltage you expect to apply, the ratio of the resistors might be different.
http://www.analog.com/library/analogDialogue/archives/33-01/chip/
BaidareW



Joined: 01 May 2005
Posts: 2
Location: Lithuania

View user's profile Send private message Visit poster's website

PostPosted: Tue May 03, 2005 1:20 pm     Reply with quote

Thank you for your reply. It is sad that I need to have more things to do ADC besides my PIC Smile So the minimum voltage I can have is -0.3 and maximum 13.25V.. if I want something more I need to play with all this for a while..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 03, 2005 1:34 pm     Reply with quote

Quote:
So the minimum voltage I can have is -0.3 and maximum 13.25V.

That's wrong. When you read a data sheet, you need to read it very
closely. The data sheet says:
Voltage on MCLR with respect to VSS (Note 2) ..... 0V to +13.25V

That 13.25v maximum only applies to the MCLR pin. Most other pins
have a much lower max allowable voltage. MCLR is special. It's used
to reset the PIC and to put it into programming mode.

To find the maximum voltage allowed on A/D pins, look in this section:

TABLE 22-21: A/D CONVERTER CHARACTERISTICS

It says the maximum analog input voltage is: AVDD + 0.3V
If you're using Vdd (likely +5v) as the analog reference, then this
means you can have a maximum of 5.3v on your A/D pins.
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