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
battery meter
Moderator: Benj
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 24 times
- Contact:
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
- Contact:
Re: battery meter
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
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
-
- 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
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 ), but we both agree about the float issue and jgu1 deserves the credit for his answer.
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 ), 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
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
- Contact:
Re: battery meter
Hi medelec!
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
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
-
- 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
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
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.
I'm not an expert either!
But that does not stop me from replying
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
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
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.
Don't worry about that all!jgu1 wrote:The expert I am not.
I'm not an expert either!
But that does not stop me from replying
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
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 24 times
- Contact:
Re: battery meter
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