View previous topic :: View next topic |
Author |
Message |
rnome
Joined: 18 Dec 2006 Posts: 20 Location: europe (Turkey)
|
two adc conversion problem |
Posted: Tue Feb 27, 2007 2:28 pm |
|
|
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
|
|
Posted: Tue Feb 27, 2007 2:36 pm |
|
|
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)
|
|
Posted: Tue Feb 27, 2007 4:25 pm |
|
|
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 |
|
|
|