View previous topic :: View next topic |
Author |
Message |
ertansuluagac
Joined: 13 Jul 2017 Posts: 135 Location: IZMIR
|
With ADC you can make readings with multiple channels. |
Posted: Tue Nov 12, 2019 7:23 am |
|
|
hello there
I'm reading with multiple channels with adc. But ch1 has (4.9v) while ch2 pushes (4.5v )with (4.9v). Why is that? What is the source of this situation? This is NOT PARASITE. CH1 and CH2 voltage value are the same _________________ Es |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Tue Nov 12, 2019 7:39 am |
|
|
You need to tell us a huge amount more:
What chip?
What clock rate?
What Vref?.
Show the ADC setup you are using, and how you select the channel and
sample.
Are you doing anything else while reading?. |
|
|
ertansuluagac
Joined: 13 Jul 2017 Posts: 135 Location: IZMIR
|
|
Posted: Tue Nov 12, 2019 7:41 am |
|
|
Code: |
#include <18F45K22.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#use delay(clock=64MHz,crystal=16MHz)
#define LCD_ENABLE_PIN PIN_B0
#define LCD_RS_PIN PIN_B1
#define LCD_RW_PIN PIN_B2
#define LCD_DATA4 PIN_B3
#define LCD_DATA5 PIN_B4
#define LCD_DATA6 PIN_B5
#define LCD_DATA7 PIN_C5
#include <lcd.c>
void main()
{
float Voltage=0;
float SVoltage=0;
unsigned int16 AdcValue;
setup_adc_ports(sAN1 | sAN2, VSS_VREF);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_0);
lcd_init();
while(TRUE)
{
set_adc_channel(1);
delay_us(50);
AdcValue=read_adc();
Voltage = (5.0 / 1023)*AdcValue;
lcd_gotoxy(1,1);printf(lcd_putc,"%2.1f,",Voltage);
set_adc_channel(2);
delay_us(50);
AdcValue=read_adc();
SVoltage = (5.0 / 1023)*AdcValue;
lcd_gotoxy(1,2);printf(lcd_putc,"%2.1f",SVoltage);
}
} |
_________________ Es |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Tue Nov 12, 2019 8:53 am |
|
|
What compiler version?.
What is physically connected to give 4.9V?. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Tue Nov 12, 2019 9:26 am |
|
|
For test purposes, you should printout the raw ADC result.
This is your 'AdcValue' variable. Displaying the raw data allows us to see if the problem is the ADC setup, a math error, or possibly the Printf() function.
Jay |
|
|
ertansuluagac
Joined: 13 Jul 2017 Posts: 135 Location: IZMIR
|
|
Posted: Tue Nov 12, 2019 10:15 am |
|
|
complier 5.91
I apply a 0-5 volt voltage with an externally adjustable power supply. _________________ Es |
|
|
ertansuluagac
Joined: 13 Jul 2017 Posts: 135 Location: IZMIR
|
|
Posted: Tue Nov 12, 2019 10:31 am |
|
|
Well, here I'm applying voltage to the 1st channel. And I see voltage on channel one. This is normal. The real problem is why I see voltage even though I didn't apply any voltage to the 2nd channel. _________________ Es |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Tue Nov 12, 2019 10:33 am |
|
|
Maybe those pins are soldered together ?
Do you read same voltage with a DVM ?
Jay |
|
|
ertansuluagac
Joined: 13 Jul 2017 Posts: 135 Location: IZMIR
|
|
Posted: Tue Nov 12, 2019 10:34 am |
|
|
DVM? _________________ Es |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Tue Nov 12, 2019 10:43 am |
|
|
DVM = digital volt meter. Sometimes referred to as a digital multimeter (DMM) if it can also measure resistance, do continuity checks, measure capacitance, current, etc. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 478 Location: Montenegro
|
|
Posted: Tue Nov 12, 2019 12:47 pm |
|
|
I'd definitely check first with a multimeter if the voltages on those two pins are what you think they are. If they are not, you have a bad joint somewhere or a bad wire or hole, if it is a breadboard. If the voltages are ok, then I'd print out to LCD raw values of the AD conversion to see if they match the voltages on the pins, as Mr. Jay said. Apply the same level on both pins and see if the readings are the same or I should say, very close. If the readings are way different, then I'd suspect ADC setup is wrong. If those raw readings (AdcValue) are ok, but you get different results for Voltage and SVoltage, then it is either a problem with mathematics or with printf. As for the mathematics, I personally don't like this kind of division, 5.0/1023, even if it works in practice. I'd make it (5*AdcValue)/1023. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 13, 2019 4:59 am |
|
|
ertansuluagac wrote: |
The real problem is why I see voltage even though I didn't apply any
voltage to the 2nd channel. |
I find it surprising that you think the ADC has some mechanism to hold
the input pin at 0 volts, if nothing is connected to it. It doesn't.
If nothing is connected to an ADC pin, its reading is "undefined".
The leakage current of an Analog input is typically +/- 100na for PICs.
That's 0.1 microamps. So the input impedance is in the Megohm or 10's
of MegOhm's range. That's a floating input. It can take on the value of
an adjacent pin by capacitive coupling. Don't assume you will get any
useful reading from an unconnected ADC pin. |
|
|
|