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
Posted: Mon Mar 17, 2008 2:31 am
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
Posted: Mon Mar 17, 2008 5:55 am
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.
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