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

18F2431 ADC Problem

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



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

18F2431 ADC Problem
PostPosted: Mon May 07, 2012 1:12 pm     Reply with quote

Hi!
Excuse my bad English!
Compiler Version: 4.114
PIC 18F2431
This code, don't work properly.
Code:

#include <18f2431.h>
#DEVICE ADC=10
#fuses nowdt, hs, nomclr
#use delay(internal = 8M)
#use rs232(baud=9600,xmit=PIN_B0,rcv=PIN_B2)

void main(){

setup_adc(ADC_CLOCK_INTERNAL);
SETUP_ADC_PORTS(ALL_ANALOG VSS_VDD);
SET_ADC_CHANNEL(1);
delay_ms(1);
long int value;

while(true){
   value=read_adc();
   printf("\fADC_VALUE = %ld",value);
   delay_ms(150);
   }
}

I had test it at Isis Proteus.
The problem is that only thing appearing on the screen
is:ADC_VALUE = 0.
When I change the input voltage (via resistive divider) nothing different is printed on the screen.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon May 07, 2012 2:00 pm     Reply with quote

Forget Proteus. Kick it out. It's so full of bugs, few here will even attempt to help you.

Use REAL hardware, then try again.

Mike

PS Read the CCS forum guidelines.
Ttelmah



Joined: 11 Mar 2010
Posts: 19484

View user's profile Send private message

PostPosted: Mon May 07, 2012 2:07 pm     Reply with quote

Several comments:

1) _HS_ fuse implies an external crystal, _not_ the internal clock. Proteus doesn't complain about this, but in a real chip, it'll never work, since it won't start...
You need to be using the INTRC fuse, or INTRC_IO.
2) ADC_CLOCK_INTERNAL, is _not_ a legal ADC oscillator value above 1MHz operation. Again this needs to be changed - read the data sheet.
3) Don't declare variables inside the code. This is _not_ legal in C., Variables have to be defined at the start of a function, or at the start of a code block inside a function. CCS does not complain about this, but it often won't work.
4) As a 'comment', _do not_ enable analog inputs on pins you are not using. This makes the readings on the pins you do use, less accurate, as there is a tendency to pick up noise from other enabled pins through the multiplexer. Keep the number of enabled ADC pins to the minimum you need.
5) Your syntax for the ADC setup is wrong. The values need to be OR'ed together '|'. Currently you are selecting VSS_VDD, but not any channel (since in C, if multiple values are placed like this, it is the last one that is used).
6) Triple check you are connecting to the right pin. RA1, is pin 3.
7) to have any hope of actually 'learning' anything about the PIC, use real hardware, not Proteus. Proteus Isis, has the habit of allowing hardware combinations to be put together that will never work, and reporting that they do (hence the oscillator), and then of not working with combinations that are completely OK.

Best Wishes
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

re
PostPosted: Tue May 08, 2012 3:29 am     Reply with quote

Thank you guys, for valuable information!
I have no tried the PIC real work yet, but when I do that, I'm going to tell you what happened.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue May 08, 2012 11:28 am     Reply with quote

You were right!
The problem was into the ISIS.
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