Hi,
If you look at the ADCIN command in the PBP manual you'll see how it's done in its simplest form. Basicly you set the pin you want to use to be an input via the corresponding TRIS register then you set the pin to analog via the ADCON1 register. Look up the ADCON1 register in the datasheet.
Use a simple voltage divider between the solar PV (?) and the PIC pin. Take two resistors, one 2.2k and one 1k. Connect them in series across the 0-15V voltage with the 1k closest to ground. Connect the PIC pin to the junction between the two resistors. Don't forget that the ground from the solar PV must connected to the PICs ground. This will produce a voltage of 0 to 4.68V on the PIC pin for 0-15V from the solar PV. It will draw ~4.7mA from the solar PV.
So....
Code:
DEFINE ADC_BITS 10 'Set ADC to produce 10bits
DEFINE ADC_CLOCK 3 'Set ADC clock to internal RC
DEFINE ADC_SAMPLEUS 50 'Set conversion time to 50uS
TRISA.0 = 1 'Set RA0 (pin2) to input.
ADCON1 = %10001110 'Set RA0 to analog, internal Vref, result right justified. (See datasheet)
SolarVoltage var WORD 'Store AD conversion result here.
Loop:
ADCIN 0, SolarVoltage 'Read AN0, store result in SolarVoltage.
LCDOUT $FE, 1, #SolarVoltage 'Display value on LCD
Pause 500
Goto Loop
If you use the resistor values above the reading should vary somwhere around 0 - 958 give or take. (For a 0-15V input)
/Henrik Olsson.
Bookmarks