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

problem with ADC in PIC18LF4620

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



Joined: 14 Aug 2006
Posts: 4

View user's profile Send private message

problem with ADC in PIC18LF4620
PostPosted: Mon Dec 18, 2006 10:24 pm     Reply with quote

Hi friends.
Below source is me coding.
At every read_adc(), value incorrect.

This source is definitely correct?

Thank you.


#include <18F4620.h>
#device adc=10
#fuses H4, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP
#use delay(clock=40000000)

void main()
{
int16 value;

set_tris_A(0x03);

setup_adc_ports(AN0_TO_AN1 | VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_4);

output_bit(pin_a2,1);
output_bit(pin_a3,1);
output_bit(pin_a5,1);

while(1){
set_adc_channel(4);
delay_us(10);
value = read_adc();
delay_us(10);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 18, 2006 10:35 pm     Reply with quote

Quote:
At every read_adc(), value incorrect.

Look at the two statements shown in bold below. Do you see
anything that's not correct ?
Quote:

void main()
{
int16 value;

set_tris_A(0x03);

setup_adc_ports(AN0_TO_AN1 | VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_4);

output_bit(pin_a2,1);
output_bit(pin_a3,1);
output_bit(pin_a5,1);

while(1){
set_adc_channel(4);
delay_us(10);
value = read_adc();
delay_us(10);
}
}
vi_ni_ta



Joined: 11 Dec 2006
Posts: 7

View user's profile Send private message

PostPosted: Tue Dec 19, 2006 5:13 am     Reply with quote

why do people use int16 and int32 for ADC conversion instead of just int.
my adc part is compiling but the function is not done when i simulate it because i use just int.
if i use int16 i am unable to print it.
kindly help me ASAP pls
davekelly



Joined: 04 Oct 2006
Posts: 53
Location: Berkshire, England

View user's profile Send private message

PostPosted: Tue Dec 19, 2006 6:03 am     Reply with quote

vi_ni_ta wrote:
why do people use int16 and int32 for ADC conversion instead of just int.

A lot of the devices have 10 bit or more resolution.

If you only want to use 8 bits, use
Code:
#DEVICE ADC=8


Look in the manual for the function read_adc()

You can easily print a 16 bit value using the correct printf specifier, eg
Code:
sprintf (str, "%Lu", value16);
vi_ni_ta



Joined: 11 Dec 2006
Posts: 7

View user's profile Send private message

PostPosted: Tue Dec 19, 2006 8:49 pm     Reply with quote

Thanks dave. I figured tat out rightaway as soon as i posted my query. but there still is one big bug. i've coded it right. my complier says no error. but when i simulate it my ADC conversion does not do a good job. will pass on the code and hopefully in a short while post a solution too..
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