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
Reading voltages via ADC ports
Moderator: Benj
-
- Posts: 79
- Joined: Sat Mar 14, 2015 7:52 am
- Has thanked: 46 times
- Been thanked: 26 times
- Contact:
Reading voltages via ADC ports
- Attachments
-
- Solar Controller 16F690 LCD 24V.fcfx
- (22.06 KiB) Downloaded 306 times
- 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
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.
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.
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;
Hopefully this is all you need to do but let us know how you get on.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
Hi Ted,
in relation to voltage divider.
Using resistors you stated:
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) =
The lower resistor(from I/P pin to 0V) =
To Confirm:
Spot on!
Martin
in relation to voltage divider.
Using resistors you stated:
Code: Select all
100/(330+100)*33 = 7.67V
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
Code: Select all
5/500x10E-6 = 10000=10K
Code: Select all
Vout = Rlower /(Rupper+Rlower) x Vin
Code: Select all
Vout = 10/(56+10) x 33 = 5
Martin
Martin
-
- 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
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
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