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 support@ccsinfo.com

two adc conversion problem

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



Joined: 18 Dec 2006
Posts: 20
Location: europe (Turkey)

View user's profile Send private message

two adc conversion problem
PostPosted: Tue Feb 27, 2007 2:28 pm     Reply with quote

hi everybody

i m using an analog joystick to control a mobile robot but i cant read joysticks potentiometer values truly.

i wrote these codes

#include <16F877.h>
#device ADC=8
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#include <lcd.c>

void main()
{
int data_a0, data_a1;

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_8);

for(;;)
{
set_adc_channel(0);
read_adc(ADC_START_ONLY);
delay_us(100);
data_a0=read_adc(ADC_READ_ONLY);

set_adc_channel(1);
read_adc(ADC_START_ONLY);
delay_us(100);
data_a1=read_adc(ADC_READ_ONLY);

lcd_init();
lcd_gotoxy(1,1);

printf(lcd_putc, "%03u 1.axis\n",data_a0);
printf(lcd_putc, "%03u 2.axis\n",data_a1);
delay_ms(200);
}
}


Problem is although i move joystick on one axis other axis is effecting from this movement.

i checked the hardware many times and i cant find any problem.

also i make a Proteus simulation and it works perfect. i mean on software axises aren't effecting from others movement


_________________
live fast, never rest and do your best


Last edited by rnome on Tue Feb 27, 2007 4:07 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 27, 2007 2:36 pm     Reply with quote

Quote:
set_adc_channel(0);
read_adc(ADC_START_ONLY);
delay_us(100);
data_a0=read_adc(ADC_READ_ONLY);

set_adc_channel(7);
read_adc(ADC_START_ONLY);
delay_us(100);
data_a1=read_adc(ADC_READ_ONLY);

Your schematic shows connections to A/D channels 0 and 1.
Your code lists a (non-existent) channel 7.

Also, you don't need the start and read only stuff.
Just do it like this:
Code:

set_adc_channel(0);
delay_us(20);    // Short delay after changing the channel
data_a1 = read_adc()
rnome



Joined: 18 Dec 2006
Posts: 20
Location: europe (Turkey)

View user's profile Send private message

PostPosted: Tue Feb 27, 2007 4:25 pm     Reply with quote

hi mate

the conflict between my schematic and program codes is not important i noticed it and edited but your second advice solve the problem completely. god bless u=)
_________________
live fast, never rest and do your best
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