level of battery

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

level of battery

Post by homayon50 »

Hello I am student ( sorry for my english )

I am in last year of high school and I need your help for my project coefficient 12.

I will make a short, i working on a remote controlled véhicle (Reference:
1:10 EP "Deathwatcher" 4WD RtR) and my job consist in setting a bargraph , permetting to know the power level of the battery with a Led bar-graph type:( https://www.sparkfun.com/products/9938 ) I need to using flowcode to programming and then compile the program on a pic "16F877A".

I don't know where to start ..
Here is some additional information:
I Have flowcode v5 .

there are 20 tab on the barograph

-Car battery 7.2v

characteristic bar-graph maximum voltage etc. ..: http://www.farnell.com/datasheets/1683489.pdf

please help me. :(

cordially.

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: level of battery

Post by medelec35 »

Hi homayon50

First the input range for a 16F877A is 0 to 5 Volts maximum.
Therefore you will need some way of dropping or level shifting from 0 - 8 (allow for a new or fully charged battery) to 0 to 5V.
Perhaps a resister divider network.
E.g with two resistors the same value say 10K connected in series between Battery in and GND then the voltage across the junction of resistors and GND = V/2
so if the battery voltage is 7.5V, then If the ADC is connected to the resistors junction, Max ADC = 7.5/2 = 3.75
If you want a better resolution then you can use say 8/5 = 1.6 as a ratio for the potential divider resistor network, so that will enable you to calculate correct resistances.
When calculating correct value don't go too high for resistor that's connected between ADC i/p and GND otherwise ADC value will be wondering.
With the value connected between battery and ADC don't go too low otherwise damage could occur to microcontroller if resistor connected between ACD i/p and GND becomes open circuit.

Then next you can produce a table of actual battery voltage verses number of illuminated LED's
An ADC component will then be required to convert measured voltage to a value.
If ReadAsByte is used then value will be between 0 and 255. Resolution is 5/256 = 19.5mV
If ReadAsInt is used then value will be between 0 and 1023. Resolution is 5/1024 = 4.88mV

Next determine the maximum value that will be measured by ADC e.g 0 to 200 or 0 to 800 as an example.
If using 0 to 200 then finally you will need to use decision icons so the value can be converted into number of LEDs that should be lit.
e.g If ADC >= 50 & ADC <20 then Value = 7
The 7 comes into the equation form the following:
If you connect all the anodes via a limiting resistor to each 8 pin of 8bit port e.g portD (connect all the cathodes to GND)

With the port there is 8 bits so thats 0 to 7
The number to add is derived from 2 to power of bits.

Code: Select all

2^0  = 1
2^1 = 2
2^2 = 4
2^3 = 8
....
2^7 = 128  
for 1st LED's you require the value to be 1
the 1st and 2nd LED's you require the value to be 1 + 2 =3
the 1st 2nd and 3rd LED's you require the value to be 1 + 2 + 4 =7

You will need to limit the current though each LED to about 5 to 10mA no more, since you must not exceed the maximum current rating of microcontroller or LED's.

To learn more about Flowcode you can visit the learning center here:
http://www.matrixmultimedia.com/lc_index.php?p=24
Where you will find loads of useful information including a beginners course and other online courses.

Hope this is helpful.

If you try and create a flowchart and get stuck, or you would like us to have a look at what you have done so far then just post your flowchart and I will take a look at it for you.

Martin
Martin

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

Hi Martin

thank you for your answer. I saw that i need to predict the resistance, but for now my big problem is the part of progrmation.
I made a shema: Image
I have 1 program it's not bad, I need to change the setting, you can see that her :
http://www.mediafire.com/download/4528b ... oject_.fcf

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: level of battery

Post by medelec35 »

You have still got a a little way to go before working on your flowchart.
You need to work out the two resistors in your potential divider, so you can calculate PD voltage v Battery voltage then v how many LED's you want to light.
Re Flowchart:
You only require one ReadAsInt not two.
Point A connection point is not required, as it's better practice to use a continuous Loop.

You have got the principle of ADC to LED just fine.
You just need to determine whats correct Voltage of ADC V battery as stated earlier.
Martin

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

Further to my problem of English , unfortunately I do not understand all .. :(
I show you calculates them that I makes with my teacher:
voltage starting pic 16F877A = 5v
I= 20 mA I = 20/1000 =0.02 A
Led max V = 2.5
U= 2.5 v
R = 2.5/0.02 = 125 Ω

Car battery = 7.2 v
pic 6F877A need a 5V so we have = 2.2 v
I do not know how to calculate the resistance for 2.2 v

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: level of battery

Post by medelec35 »

homayon50 wrote: Car battery = 7.2 v
pic 6F877A need a 5V so we have = 2.2 v
I do not know how to calculate the resistance for 2.2 v
Personally I would not use 2.2V from a 7.2V battery because the ratio of 2.2/7.2 = 0.3
so if the battery dropped by .2V to 7V then the 2.2V will drop by 60mV

What you want to do is have Vout = 5V when Vin = 8V like this:
Potential Divider.png
(2.95 KiB) Downloaded 9474 times
To determine value of R1 and R2, I would do is decide a safe level current if R2 was to become open circuit say 500uA.
I should not give anything else away since I should not be doing your project for you.
I have calculated two resistanc values I would use.
So if you can calculate them I can let you know If I agree or not.

Martin
Martin

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

I know that it belongs not to you to make my project, thank you really, I am on holidays and I try to move forward my project, thank you again, I made one calculates, say I if it is just:

I = 500 mA or 0.5 A
U = 5v for r2
so R2 = u /I = 5/0.5 =10Ω

U=7.2v-5v =2.2v
U = 2.2v for R1
I=0.5A
R1= 2.2/0.5 = 4.4 Ω

I dont know so it is just or not :oops:

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: level of battery

Post by medelec35 »

homayon50 wrote:I = 500 mA or 0.5 A
500mA is way to high in my opinion.

You can take into account that the input resistance for ADC is very high indeed.
For that reason you can use 500uA (500 microamps) = 500 E-06

So if you used 500uA instead of 500mA you should be in the right track, as your calculations method looks ok.
Personally I would also use 8 in my calculations instead of 7.2 to allow for more healthy battery.






.
Martin

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

Ah all right, thus it is necessary to convert microamps in ampere?
Or it is necessary to make calculates it directly, I set 8v also :

R2 =5/500 = 1000
R2= 5/0.005 =0.01(With convertion in ampere)
----------------------------------------------------------
R1= 3/500=0.006
R1= 3/0.005 =600(With convertion in ampere)
---------------------------------------------------------
I think for the part which concerns calculates them one finished, favor has you, I think that I has to change the paramétrè of my programe in flowcode ,this is the hardest part for me.

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: level of battery

Post by medelec35 »

homayon50 wrote:Ah all right, thus it is necessary to convert microamps in ampere?
No,
What the two resistors do is work as a potential divider.
A portion of i/p voltage appears across R1 & R2 (Vtot = VR1 + VR2)
We are just measuring the portion across R2.
The voltage across R2 will be the same if using
R1 = 6K8
R2 = 10K
or
R1 = 680R
R2 = 1K
or
R1 = 68R
R2 = 100R
It just the total current drawn is larger the lower the resistance value.
So why waste power and draw 42.8mA
when you can get the same reading drawing just 428uA (428 microamps)

We maybe talking about two different things?
I thought you was talking about the battery condition i.e the voltage level and the word power was due to translation since power is Voltage x current and is measured in watts.
In my opinion, level of the battery is usually how good condition it's in ie its voltage.
From your last post it seems your talking about measuring the current being drawn by what ever is connected to your battery?

So all the posts I have posted about is referring to measuring the voltage of the battery only,

Are you wanting to measure battery voltage(Volts), current (Amps/mA) or power (Watts)?

Also I noticed that your using a registered version of Flowocde since it has:

Code: Select all

This copy of Flowcode belongs to LYCEE-ESSOURIAU91
So for this to carry on we need to be posting in the correct Flowcode V5 section for registered users.
To do that you will need to take a look here:
http://www.matrixmultimedia.com/mmforum ... =46&t=9958

If for any reason you can't do that can you let us know please, as I will be moving this topic there tomorrow.
Martin

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

Yes I think also , I have just need shown on the bar-graph the state of the battery, for example when the battery is full 10 LED of bar-graph are to light and when we consome the car the energy of the battery are going to fall and the bar graph has to indicate this with the LED, it is little as on mobile phone (energie indicator ) .

Please no delete my post ,I am going to try to see what I can make, I am student and I have not means to buy the software, I have that the copy of version of my high school.

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: level of battery

Post by medelec35 »

homayon50 wrote:Please no delete my post
Don't worry, did not say I was going to delete your post, as I would not do that.
Was just going to move it to the correct section.
Moving this thread can be postponed for a few days.
homayon50 wrote: I have just need shown on the bar-graph the state of the battery, for example when the battery is full 10 LED of bar-graph are to light
If that's the case all what I stated still should stand.
What I can suggest is work out a table of Battery voltage V LED's Lit.

E.g

Code: Select all

Battery        LED's
Voltage        Lit
>=7.5          10 
7.0 to 7.4      9
6.9 to 7.3      8
Of course this should be your own values and not mine.
you need a bit of hysteresis to avid to much flickering
hence difference between 7.4 and 7.5 is 100mV
Once you have done that it can be taken a step further.

Also I worked out using a current of 500uA
R2 = 5/500E-6 = 10K
R1 = (8 - 5)/500E-6 = 6K. nearest preferred value = 6K2

So with a battery voltage of 7.2V, the votage across R2 =
10/(10+6.2)*7.2 = 4.4V

Using an integer:
DAC = 1023/5 * 4.4
Rounding down:
= 204 * 4.4
= 897
So now you know that when value if integer variable is 897 or greater then battery voltage is 7.2V or greater so 10 LED's should be lit.


Martin
Martin

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

Thank you very much martin for calculates them.
I have measure the tension of the battery in 2 times :
(I know that ,the autonomy of the battery is 10 min)
when the battery is full :7.2v
and after 10 minutes of use : 6.40 v

Battery LED's
Voltage Lit
>=7.5 10
7.0 to 7.4 9
6.9 to 7.3 8
6.8 to 7.2 7
6.7 to 7.1 6
6.6 to 7.0 5
6.5 to 6.9 4
6.4 to 6.8 3
6.3 to 6.7 2
6.2 to 6.6 1
6.1 to 6.5 ?
6.0 to 6.4 ?

what do you think of tha ?
Thank you for calculates them

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: level of battery

Post by DavidA »

Hi,

These Flowcharts are v5, so please post in the v5 forums. Instructions on how to do this are available in the v5 forums.

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

Hello
Here are the new flowchart :?
https://www.mediafire.com/?dy2fz4fmi6n6f2v

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: level of battery

Post by medelec35 »

Hi homayon50,
There are several issues with your flowchart.
1) if you use ReadAsVoltage then you should use a floatvaraible with it.
Floats are not recomented with 8bit pics.

2)It's a waste of sorceress to use two ADC components for reading from the same ADC channel.
Use either:
ReadAsByte = resolution of 5/256 = 19.53mV
Or
ReadAsInt = resolution of 5/1024 = 4.88mV

3) It looks like your expecting over 7Volts in the ADC input.
This is not the case since the maximum ADC input on these microcontroller is 5V
the voltage on the pin will be divided down by the potential divider.

Here is what you will need to do:
Workout the ratio of potential divider so you can determine the voltage present on the ADC pin.
Workout if your using bytes or integer.
Use a formula to calculate what the value of byte or int will be for the the voltage that will be on the pin.
Use decision branches to light appropriate LED
Or
The best but more complex way:
You can use a calculation box to derive a value of integer that is 10 or 100 times the voltage that will be present on the battery.
So if the battery voltage is 7.3V the value of integer should be either 73 or 730
But as i stated before there will be a maximum voltage on the ADC pin of 5V, so the calculation must include the ratio of potential divider.

Hopefully this will give you something to think about.

Martin
Martin

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

Hi Martin
To sadden for the delay, I think that you go not to re-hang me, in brief I almost finished my project, I just have to try it on an assembly to see its work or not.
I use a tension 7.2 V
The current crosses 7.2 in 5v by means of a regulator of tension ( http://www.selectronic.fr/media/catalog ... 220_46.png) and then the current spends on my chip 16F77A

Here is my assembly (I took the photo 1 week ago I test the new programe this week and 2 week after i spend my oral examination : Image

Link removed. Triggering malware warnings. Martin

Cordially.
Homayoun

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

withe a regulator of tension:
7.2v ----> 5 v
7.1v ----> 4.9v
7v ----> 4.8v
6.9v ----> 4.7v
6.8v ----> 4.6v
6.7v ----> 4.5v
6.6v ----> 4.4v
6.5v ----> 4.3v
6.4v ----> 4.2v
6.3v ----> 4.1v
6.2v ----> 4 v
------------------------------------------------
5v everything led to switch on
4.9 Led number 9 switch of.
4.8 Led number 8 switch of .
[....]
4 v Led number 1 switch of .

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: level of battery

Post by medelec35 »

Hi Homayoun,
if posting a flowchart,
can you please post the flowchart on the forums as the links posted triggers malware warning while blocking a popup:
Malware.png
(86.11 KiB) Downloaded 8956 times
Martin
Martin

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

I have to present my project on April 2
and I use now the pic 18F4620
in attached file you can find the Shema on isis and new flowchart withe pic 18F4620 .
when I try the program on installation, the program on work on the pic,all the LEDs are lit even at 3V , I do not know why, but it works on isis.
Attachments
isis + Sti2d final.fcf + hex .rar
(21.72 KiB) Downloaded 269 times

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: level of battery

Post by medelec35 »

The problem is there are no configuration fuses set within your hex code.
When Flowcode compiles to hex, the configuration settings (Fuses) are embedded with in the hex file.
Then the programmer will program the chip with the fuses embedded within the hex file,
Since this is not happening there seems like an issue with the version of Flowcode your using since the configurations are set within the flowchart you posted.
Not sure exactly the reason for this since it worked for your 16F77a (do you mean 16F877a)?

What is the full version of Flowcode are you using (including the dates within brackets)?
Information can be found in help, about Flowcode.
Martin

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

is that the problem comes from my program ? What should I do?
I use Flowcode v5.1.0.0 5
10.02.2012

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: level of battery

Post by medelec35 »

homayon50 wrote:I use Flowcode v5.1.0.0 5
10.02.2012
That does appear to be the issue,
You will need to use the latest version which is V5.5.2.1 (30.1.2013)

The other alternative is to download a trial version of V6, I believe you can use all the features for 30days?
You can download V6 trial from Here
Details of trial from Here
Martin

homayon50
Flowcode v5 User
Posts: 14
Joined: Sat Feb 22, 2014 12:54 pm
Has thanked: 9 times
Contact:

Re: level of battery

Post by homayon50 »

Hi Martin
I finished my project and everything works well , I need to find a deffintion for ''Float'' and ''String'' variable?
can you help me ?

Cordially.
Homayoun

Post Reply