View previous topic :: View next topic |
Author |
Message |
javi.ar
Joined: 17 Feb 2006 Posts: 59 Location: Argentina
|
ADC 12F683 |
Posted: Fri Mar 31, 2006 11:22 am |
|
|
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
|
|
Posted: Fri Mar 31, 2006 1:25 pm |
|
|
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
|
|
Posted: Fri Mar 31, 2006 2:08 pm |
|
|
Sorry Version is 3.235
I use read_adc() for reading ADC output. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 31, 2006 2:57 pm |
|
|
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
|
|
Posted: Fri Mar 31, 2006 9:27 pm |
|
|
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
|
|
Posted: Sat Apr 01, 2006 1:25 am |
|
|
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
|
|
Posted: Tue Apr 04, 2006 7:47 pm |
|
|
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
|
|
Posted: Tue Apr 04, 2006 10:11 pm |
|
|
You defined the variable dato as an unsigned integer, its permissible range is 0-255.
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
|
|
Posted: Wed Apr 05, 2006 6:28 am |
|
|
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
|
|
Posted: Thu Apr 20, 2006 8:00 pm |
|
|
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... |
|
|
|