|
|
View previous topic :: View next topic |
Author |
Message |
btklister
Joined: 16 Jul 2009 Posts: 14
|
Another ADC multiple channel reading problem. |
Posted: Sat Feb 06, 2010 7:59 pm |
|
|
Hello.
I have a problem that i can't find solution. Using 2 channels for adc, the adjacent channels affect each others, if i had a input on AN0 and read AN1, the input appears in adc read. I already put delays after the channel selection, but does no effect.
there's the code:
Code: | #include <18F4550.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES NOLPT1OSC //Timer1 configured for higher power operation
#FUSES XINST //Extended set extension and Indexed Addressing mode enabled
#FUSES PLL12 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4 //System Clock by 4
#FUSES NOUSBDIV //USB clock source comes from primary oscillator
#FUSES NOVREGEN //USB voltage regulator disabled
#FUSES NOICPRT //ICPRT disabled
#use delay(clock=31000)
void main()
{
char x,y;
setup_adc_ports(AN0_TO_AN1|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,154,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_31KHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF);
// TODO: USER CODE!!
while(1)
{
set_adc_channel(0);
delay_ms(5);
x=read_adc()/17;
set_adc_channel(1);
delay_ms(5);
y=read_adc()/17;
set_pwm1_duty(1+x);
set_pwm2_duty(1+y);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 07, 2010 1:40 am |
|
|
Try running the PIC at a normal frequency, such as 4 MHz. Disable all
the PLL stuff in the #fuses. See if you still get the problem.
Also, you have XINST in the #fuses. Change this to NOXINST.
Do this in all your programs.
Did you read all the other threads, which said that the maximum
impedance of the external circuit which supplies the analog voltage
is 2.5K ohms ? Does your circuit meet that requirement ? |
|
|
btklister
Joined: 16 Jul 2009 Posts: 14
|
|
Posted: Sun Feb 07, 2010 8:55 am |
|
|
I have made all the changes and the problem still:S |
|
|
Ttelmah Guest
|
|
Posted: Sun Feb 07, 2010 10:57 am |
|
|
I think you need to understand the ADC, and why the answer to the last part of PCM programmers questions, is critical.
As far as an external circuit is concerned, the PIC ADC, is 'seen' as a resistor in series wth a capacitor to ground.
When you perform the 'set_adc_channel' function, this circuit is connected to the external source, and the capacitor starts charging.
When you perform a reading, the connection is removed, and it is the voltage on the capacitor that is 'read'. This is done relative to the voltage used as the Vref source.
If you then connect to another channel, the capacitor starts already charged to almost the voltage on the last channel.
Now, interference between channels, then appears from basically two places:
1) The total source impedance, being too high, so that the capacitor doesn't actually charge to the correct voltage. The specified maximum, for your chip, to cope with internal leakage, and charge the capacitor to within half a bit of the target voltage, is 2.5KR.
2) The Vref (in your case the supply), itself being too low impedance, or being affected by other events in the circuitry.
If you have simplified the code, as described by PCM programmer, then you are left with one of these as the problem...
Best Wishes |
|
|
btklister
Joined: 16 Jul 2009 Posts: 14
|
|
Posted: Sun Feb 07, 2010 1:16 pm |
|
|
Problem solved.
I was testing only one channel each time, leaving the other unconnected (high impedance) resulting in bad readings. If the 2 channels were connected to the target all goes normally.
Thank you all! |
|
|
|
|
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
|