This example divides a 25 volt source into about 4.38 volts for the PIC's A/D converter to handle.

The ratio of the voltage divider is (R1+R2)/R2. To scale up the A/D reading you just multiply the value times the total resistance of the divider (R1+R2) then divide that number by R2.

If the input is 25Vdc then the output voltage will be 25v/((R1+R2)/R2) or 25v / ((4700+1000)/1000)) = about 4.38 Vdc. With 10-bit A/D you should get an ADCin of around 898. If you first scale that A/D value up to match the voltage divider ratio, you can then calculate the voltage the same way you would if you were reading 0-5 V.

898 * 5700 / 1000 = 5118 This is what the A/D would be if it could actually read 0-25 volts directly.

Now then, for 1 decimal place, multiply that by 50 and divide by 1023. For 2 decimal places, multiply by 500 instead.

5118 * 50 / 1023 = 250 or 25.0Vdc

The program below is one way to do it in PBP.

HTH,

Darrel

Res1 Var Word Res2 Var Word Rt Var Word Volts Var Word AD Var Word GetReadings: ADCin 0, AD Res1 = 4700 ' Change these to match your Voltage divider Res2 = 1000 ' resistor values for the Solar Cell Gosub CalcVoltage LCDout $FE,2,"Solar= ",DEC Volts/10,".",DEC1 Volts Dig 0," Vdc" ADCin 1, AD Res1 = 2200 ' Change these to match your Voltage divider Res2 = 1000 ' resistor values for the Battery Gosub CalcVoltage LCDout $FE,$C0,"Batt = ",DEC Volts/10,".",DEC1 Volts Dig 0," Vdc" goto GetReadings CalcVoltage: Rt = Res1 + Res2 ' Total resistance of Voltage Divider Volts = AD * Rt ' Scale the AD reading accordingly Volts = DIV32 Res2 Volts = Volts * 50 ' Convert AD to Voltage Volts = DIV32 1023 Return

## Re: MRF90XAM9A interfacing help

Been awhile since I been here and found this post while trying to bring the same module to life.

LinkMTech Yesterday, 19:52After a lot of reading and comparing "working" code not in PBP, I found that a lot of confusion...