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 12F683

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



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

ADC 12F683
PostPosted: Fri Mar 31, 2006 11:22 am     Reply with quote

Hello everybody:
I�m using a 12f683 and reading ADC from a LM35, but the reading is always the same no matter what I read (GND or VCC) , I used all 3 AD inputs and set all analog. No success so far , I am using CCS 3.23 .
Thanks in advance to everybody.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 31, 2006 1:25 pm     Reply with quote

Quote:
I am using CCS 3.23

Post your complete compiler version. The version has 3 digits after
the decimal point. The version is given at the top of the .LST file.
You can find that file in your project folder.
javi.ar



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Fri Mar 31, 2006 2:08 pm     Reply with quote

Sorry Version is 3.235
I use read_adc() for reading ADC output.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 31, 2006 2:57 pm     Reply with quote

I don't see any problems with the A/D code or the CCS setup code
for your version of the compiler. So you need to post a test program.
Make it be complete but short. (like 20 lines, total).
javi.ar



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Fri Mar 31, 2006 9:27 pm     Reply with quote

Here is all the code...

#include <12F683.h>
#include <ini12F683.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES MCLR //Master Clear pin enabled
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled

#use delay(clock=4000000)

//#bit led = GPIO.2
#bit ledr = GPIO.5
#use rs232(baud=9600,parity=N,xmit=PIN_A4,bits=8)
data ()
{

int dato;
while (1)
{
dato = read_adc();
printf ("valor %2X ", dato);

if (dato < 0)

ledr = 1;
delay_ms(500);
}
}


void main()
{

setup_adc_ports(sAN2|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_us(100);

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_4MHZ);

//Funciones Personales

GPIO= 0b000000; TRISIO= 0b001100;
ledr = 1 ;

data ();

}

Thanks guys a lot...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 01, 2006 1:25 am     Reply with quote

One obvious problem is that you have configured the A/D port so that
pin AN2 is the analog input pin, but then you have selected channel 0
for the A/D conversion. They have to be the same. You need to
change it so that both lines are setup for channel 0, or both for channel 2.
Quote:

setup_adc_ports(sAN2|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
javi.ar



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Tue Apr 04, 2006 7:47 pm     Reply with quote

PCM programmer wrote:
One obvious problem is that you have configured the A/D port so that
pin AN2 is the analog input pin, but then you have selected channel 0
for the A/D conversion. They have to be the same. You need to
change it so that both lines are setup for channel 0, or both for channel 2.
Quote:

setup_adc_ports(sAN2|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);


I have done all modifications, but still reading 0x03 no matter what I place in input pin, 0v or Vcc (5v) any other hint, please.
I also switch the PIC for a brand new one, also same output value...

Thanks to all of you... great to be in a forum like this one..
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Apr 04, 2006 10:11 pm     Reply with quote

You defined the variable dato as an unsigned integer, its permissible range is 0-255.

Quote:

if dato < 0)

Will never get true.

Take away this line, let the compiler to do his job, or at least set the bits accordingly.
Ie: as show, bit 0 is an output, but you are trying to read from the analog input channel 0.
Quote:

GPIO= 0b000000; TRISIO= 0b001100;


Define the analog inputs that you are going to use:
setup_adc_ports(sAN0|sAN1|sAN2|sAN3|VSS_VDD);
Code:

set_adc_channel(1); // Select the channel you want to read:

while (1)
   {
    dato = read_adc();
    printf("A/D value = %2x\n\r", dato);
    delay_ms(500);
   }


Humberto
javi.ar



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Wed Apr 05, 2006 6:28 am     Reply with quote

Thanks Humberto... very kind ...
I�ll try it later, and let everybody know if it worked...

Saludos (Soy de Buenos Aires)
javi.ar



Joined: 17 Feb 2006
Posts: 59
Location: Argentina

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Thu Apr 20, 2006 8:00 pm     Reply with quote

javi.ar wrote:
Thanks Humberto... very kind ...
I�ll try it later, and let everybody know if it worked...

Saludos (Soy de Buenos Aires)


Finally I made it, with your help...

set_adc_channel(2) ;
instead of
set_adc_channel(sAN2) ;

I worked!!!! Great, so thank you all...
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