battery meter

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

battery meter

Post by siliconchip »

hi all i have been trying to design a battery meter going from 1 -6v during simulation with flowcode it works as expected but when i try to compile to a hex code i get the following message

C:\Documents and Settings\bob\My Documents\battery meter.c(449): error: can't convert 'float' to 'unsigned char'
C:\Documents and Settings\bob\My Documents\battery meter.c(449:9): error: failed to generate expression
battery meter.c success

failure

..
Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:

i have the ADC to read as voltage but from the errors above it seems i need to do some thing to the "float" in the variables can anyone shed any light on where i have gone wrong please cheers
Attachments
battery meter.fcf
battery meter
(16.5 KiB) Downloaded 321 times

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: battery meter

Post by jgu1 »

Hi !

I think it's because you use the return value "in" which has to be a floating value but is a byte.

I have tryed to do it on another way. I have no problem by compiling to hex but not testet in "real world". try it. :?:

Regard

jgu1
Attachments
battery meter_Modyfied.fcf
(12.5 KiB) Downloaded 308 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: battery meter

Post by medelec35 »

Hi, siliconchip.
You will need to bear in mind that if you Want to read 6V then the supply to chip (VDD) must also be 6V.
If you are using 5Vto supply the chip then you must use a potential divider to tap off from the voltage to be measured.
E.g how I would do it (prob not the best way!) is 1st determine a resistance that is connected to ADC pin to gnd for a max voltage of 5V at say a current of 1/2 mA (value I just made up) then R = V/I = 5/0.0005 = 10K,
Value for resistor that connects between ADC pin and voltage to be measured (Vin - Vsupply )/I = 6 - 5 = 1 / 0.0005 = 2K.
I have simplified your flowchart so 0 - 6V will be indicated by LEDs, but at the same time greatly reduced the program size.
Hope its of some use to you.

You will need to change the configuration of flowchart to suit your target device, or your code will not run on hardware.
See:
http://www.www.matrixmultimedia.com/mmf ... =26&t=6936

Edit: I have just noticed jgu1 beat me to it so i have edited out the same answer(I'm a slow typer and was editing your flowchart :P ), but we both agree about the float issue and jgu1 deserves the credit for his answer.
Attachments
battery meter Modified.fcf
Removed float var and all macros
(8 KiB) Downloaded 367 times
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: battery meter

Post by jgu1 »

Hi medelec! :D

Finally, there was just a situation where I could help a little, hope it´s ok, so therefore the answer. The expert I am not. It is evident by your eksembel where the program is very simple. Fortunately, we can program in many ways. Now we are going, you can tell me how to give rating :?:

Regard

Jgu1

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: battery meter

Post by medelec35 »

Hi Jgu1,
In my opinion Your answer was more than OK, it's spot on!
That's why I edited my post, It looked like I was just copying you :lol:
It's great when there is more than one answer from people on this forum.
If I was stuck, I would rather see more than one reply, even if they were similar, than none at all.
Your right, there are many different ways you can program to achieve the same results. So it's good to have more than one version.
It teaches you different programming techniques.
jgu1 wrote:The expert I am not.
Don't worry about that all!
I'm not an expert either!
But that does not stop me from replying :P
Nor should it stop anyone else from replying
Not all my answers help or are helpful like yours!

If you think someone has helped you , just click on the thumbs up icon situated next to the "QUOTE
on the post that is helpful.

Regards
Martin
Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: battery meter

Post by siliconchip »

hi jgu1 and medelec35 both your answers were great my next step now is to test this in the real world, (hardware) thanks to you both for replying it also gives me a chance to study your revisions of my idea hopefully to better understand flowcode many thanks :D

Post Reply