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

PIC16F877-A ADC random values.

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



Joined: 29 Jun 2005
Posts: 13

View user's profile Send private message

PIC16F877-A ADC random values.
PostPosted: Sun Aug 07, 2005 5:15 am     Reply with quote

I am using pic16f877A and on pin A1 I have a analog input. the code is:


Code:
#include "C:\Program Files\PICC\Termometru\termometru1.h"
#include <LCD.C>
#include <stdlib.h>

void main()
{

unsigned long val;
   setup_adc_ports(AN0_AN1_VSS_VREF);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_psp(PSP_DISABLED);
   set_adc_channel(1);

   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   lcd_init();

delay_ms(200);
lcd_putc("Termometru...\n   Asteptati...");
while(1){
   delay_ms(2000);
   val = read_adc();
   delay_ms(100);
   printf(lcd_putc,"\fADC Val: %ld",val);
  }

}


Termometru1.h is:

Code:
#include <16F877A.h>
#device adc=10
#use delay(clock=4000000)
#fuses NOWDT,XT, PUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT



on pin A1 I connected a 50K variable resistor (connected between the power supply 5V and ground).

Even if I don't modify the resistor I get strange results on my LCD: sometimes I get 1023 (the maximum value) sometimes I get 0. Also i get other values: 512, 640, 1 etc without modifying the resistor.
Any Ideas ?
thanks
Humberto



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

View user's profile Send private message

PostPosted: Sun Aug 07, 2005 7:42 am     Reply with quote

setup_adc_ports(AN0_AN1_VSS_VREF);

Is expecting the Vrefh in PIN_A3. Are you getting the Vref HIGH to this pin ?

Check the possible constants used in SETUP_ADC_PORTS() in the 16F877A.H file.

Best wishes,

Humberto
meme



Joined: 29 Jun 2005
Posts: 13

View user's profile Send private message

PostPosted: Sun Aug 07, 2005 8:08 am     Reply with quote

that was it. thanks !
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