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

adc in pic 16F877A

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



Joined: 17 Mar 2008
Posts: 1

View user's profile Send private message

adc in pic 16F877A
PostPosted: Mon Mar 17, 2008 1:31 am     Reply with quote

hi........
im newbie to microcontrollers and embedded systems ; no idea where to start ; some suggested me to start with a line follower
The hardware part is finished

im using
- pic 16F877A
- L239D motor driver
- LDR sensors

im now having a problem in coding it

i connected my LDR sensors to the A0 and A1 pins
Where i configured A ports as ADC ports


i was seeing some example codes for reading the values from ADC; and have some doubts

setup_adc(ADC_CLOCK_INTERNAL); //(can someone explain this? what is a ADC clock)
set_adc_channel(0); //(what does this line actually do, how does it know that it need to select A0 pin ; what if we configured B pins also as analog?)
value=read_adc(); //(what will be the value of the value variable (does it read the voltage at that pin ?); and doesn't the output be in 8bit form (digital)??)


Thanx in advance
__baltazar__
Guest







PostPosted: Mon Mar 17, 2008 2:31 am     Reply with quote

Very Happy Just spend a little time reading the MCU manual. It's freely downloadble from Microchip. But anyways, to give you a little satisfaction, ADC requires clock pulses for sampling the analog signal. In the ADCON0 register , you can select these required clock pulses from either the fractions of the MCU clock or ADC's own internal RC clock.
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

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

PostPosted: Mon Mar 17, 2008 5:55 am     Reply with quote

You need to look and study the manuel but the first line is a indication of the sampler that reads the analog value so you need to setup the ADC clock to sample your analog signal.
The second line is a indication of which analog port to read, on the 16 series only port a can read analog values but if you look at the header file you will see the required setup to set the correct ADC port for reading.
The final line is a statement where you equate the value on the analog port to a variable as to use it somewhere. It basically reads the volatage at that pin as long as that voltage lies in the correct range. If the voltage is between 0 and 5 volt and you set up that analog as an 8bit value 2.5volt would be read as 128 into the variable.

Best is to look at examples and then at the manuel of the PIC. It is also recomended that you look at the hardware schematic of the pic as to understand how an analog value is processed in the PIC.
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