Reading voltages via ADC ports

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Reading voltages via ADC ports

Post by TedO »

Hello,
I have tried my hand at designing a solar charge controller based on the 0-15V voltmeter that Martin (Medelec) posted to the forum, I have tweaked certain formulas to obtain certain readings to make it work on 24V, however, I am experiencing some difficulties mainly due to inexperience and am asking for some kind assistance please.
Have not used this before to read voltages.

The controller works on two 12V batteries connected in series (24V) and the PV panel is open circuit at 36V.
I have chosen voltage dividers as follows to give me a range of 33V each for Battery and PV panel: (Do not know if this is correct??)
33V
|
330K
|______ To ADC port This giving me 33 volts at 5v on the ADC
|
100K
|
------
My problem is that this program works perfectly on the simulator, however, having built the circuit complete, I find that the voltage dividers and my modified formulas are not registering correctly in real life scenario with change in voltages.

Am posting my flowchart, any help would be greatly appreciated!!!

Kind regards
Ted
Attachments
Solar Controller 16F690 LCD 24V.fcfx
(22.06 KiB) Downloaded 306 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Reading voltages via ADC ports

Post by Benj »

Hi Ted,

Your using the internal RC oscillator but not configuring it so by default this will run very slowly.

To run the device at 8MHz (the max available internal speed) add this code to the start of your program in a C icon.

Code: Select all

//Flowcode v6
osccon= 0x70;

Code: Select all

//Flowcode v7 & 8
OSCCON = 0x70;
Also remember to change the clock speed in the Build -> Project Options to 8000000.

Hopefully this is all you need to do but let us know how you get on.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Reading voltages via ADC ports

Post by medelec35 »

Hi Ted,
in relation to voltage divider.
Using resistors you stated:

Code: Select all

100/(330+100)*33 = 7.67V
Although with 330K there sould not be any damage to port, we need to get the calulation of resistors correct.

To calculate resistor values to give you approximately 5V when the input is 33V
For example If we say 500uA is a safe current to flow when input voltage exceeds 5V. then upper resistor (from +33V to I/P pin) =

Code: Select all

(33-5)/500x10E-6 = 56000= 56K 
The lower resistor(from I/P pin to 0V) =

Code: Select all

5/500x10E-6 = 10000=10K
To Confirm:

Code: Select all

Vout = Rlower /(Rupper+Rlower) x Vin

Code: Select all

Vout = 10/(56+10) x 33 = 5
Spot on!

Martin
Martin

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Re: Reading voltages via ADC ports

Post by TedO »

Hi Ben and Martin

Thanks for your advice with my project, it is greatly appreciated.

I have modified the flowchart to include the C code Ben and have changed the frequency to 8Mhz. Martin I have changed the voltage divider resistors as advised. Reprogrammed the chip and all is well............great stuff guys!!

Thanks once again.

Regards
Ted

Post Reply