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

With ADC you can make readings with multiple channels.

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



Joined: 13 Jul 2017
Posts: 135
Location: IZMIR

View user's profile Send private message Send e-mail

With ADC you can make readings with multiple channels.
PostPosted: Tue Nov 12, 2019 7:23 am     Reply with quote

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: 19512

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 7:39 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 12, 2019 7:41 am     Reply with quote

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: 19512

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 8:53 am     Reply with quote

What compiler version?.
What is physically connected to give 4.9V?.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 9:26 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 12, 2019 10:15 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 12, 2019 10:31 am     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 10:33 am     Reply with quote

Maybe those pins are soldered together ?
Do you read same voltage with a DVM ?

Jay
ertansuluagac



Joined: 13 Jul 2017
Posts: 135
Location: IZMIR

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 12, 2019 10:34 am     Reply with quote

DVM?
_________________
Es
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 10:43 am     Reply with quote

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: 479
Location: Montenegro

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 12:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 13, 2019 4:59 am     Reply with quote

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.
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