Voltmeter Pic

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
jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times

Voltmeter Pic

Post by jgu1 »

Hi!


Is there anyone here who will help me create a program to a voltmeter. I have been trying but without success. I know that the analog entrance of the Pic is max. 5 volt, but how can I scale to from 0 - 5V to be 0 to 15V with two decimal places.

Hope someone would be kind to make a small program. For a display.

Please

Thanks in advance. :P

Jgu1

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times

Re: Voltmeter Pic

Post by JohnCrow »

Hi
This is a program I've been playing with along the lines of what you are looking at.
Hope it might give you a pointer.
May not be the best way,but you are welcome to use it.
Attachments
pic-voltage.fcf
(14.5 KiB) Downloaded 1181 times
1 in 10 people understand binary, the other one doesn't !

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

Re: Voltmeter Pic

Post by jgu1 »

Hi John!

Thanks for your program and inconvenience. It looks interesting. But this I need is, 0-5 volts in the analog input and the display will show 0-15 volts with 2 decimal, (eks 12.57 Volt). I can not really figure out how to do it.

Regard

JGU1

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

Re: Voltmeter Pic

Post by medelec35 »

Hello jgu1
Here is a voltmeter that scales 0-5V to 0 - 15V. to 2 decimal places. Hope it works the way you would like it to. As a quick test I set a pot and measured 192mV on meter. This gave a reading on LCD display of 0.57 Volts. Since there is a factor of 3: 0.192 * 3 = 0.576
I have also added a bar graph function ( simulation wrongly displays a y with two dots above it, whereas EB005 LCD correct displays squares)
Tested on a 18F4455 target, so you will need to change the necessary settings for your target device and speed of osc.
This is easily adpaded to read 0 - 5 V by removing the *3 in the calculation box. If keeping the bargraph function, just replace 93 with 25.
I have not used any float variables, so should also work on target devices with less memory available.
Attachments
pic-voltage Mod1 (0-15V).fcf
(10 KiB) Downloaded 1368 times
Martin

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

Re: Voltmeter Pic

Post by jgu1 »

Hi Medelec! :P 8) :lol:

Just what I need. It work´s fine. And the "formel". Thank you wery much. :P

Jgu1

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

Re: Voltmeter Pic

Post by jgu1 »

Once again. Hi Medelec!

I have now tested your voltmeter in a 16f876 Super, it works perfectly and I can see it is easy to change ranges in the program. I will analyze your bar chart function (Very smart) and try to find out exactly how it works.
Once again many thanks.

Best regard

Jgu1 :P

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

Re: Voltmeter Pic

Post by medelec35 »

Thanks jgu.
Glad it works for your application.
The bar graph was something I thought of late last night for a novelty effect to replicate a bar graph multimeter.
Thanks for letting me know, it’s appreciated.
Martin

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

Re: Voltmeter Pic

Post by medelec35 »

I have been sent this PM.
Hello
I saw your post about the voltmeter. I'm trying to understand the Math. I see that it works in the sim and in a chip but I don't understand how.
In the Math statement {IntAnswer=IntValue_read*5/(1023/10)} isn't the value of (1023/100) a real number and not a Int (10.23)?
I have been struggling with similar scaling and working really hard to keep all the math as only integers. I thought (apparently incorrectly)the answer to 1023/100 as a int would return an answer of 10 not 10.23 and so the math would not work out correctly.
If you can please explan why it work correctly that would be great
You are correct! (1023/100) is treated as a real number = 10
So here is how it's done:

Value of sampled Voltage = INT = 100 times sampleADC (0 -5V) or 300 times sampleADC (0 to 15V)

E.g on 0-15V range with 4.5V on i/p. Value of adc_level variable = 1023/5*4.5= 920
Converting to 3 times i/p voltage:

920 *5/(1023/100)*3 = 1380 Note: with pic maths, since using integers: 1023/100 = 10 and not 10.23. so I could of used voltage *5/10 * 3 = 1380 so get the same answer!
(Reason I used 1023/100 instead of just 10 was to show that max int read was 1023, so it is used in the calculation. If I just used 10, then people could be puzzled why I used it.)
Convert to a string = “1380”

Now use Left$ and Right$ to display Voltage.

I.e For Voltage whole part:
Voltage_Unit = Left$(Volts, 2) = 13

For the hundredths part:
Votlage_Hundreths = Right$(Volts, 2) = 80

Then send to display Voltage_Unit = 13
A decimal point
Then hundredths = 80
= 13.80 Volts

If you follow the flowchart, it can be seen that a lower voltage e.g less than 1V requires a different format of left$ and right$.

E.g again on 0 - 15V range:
with 0.12V on i/p. Value of adc_level variable = 1023/5*0.12= 24
Converting to 3 times i/p voltage:

24 *5/10*3 = 36
Convert to a string = “36”

Now use Left$ and Right$ to display Voltage.

I.e For Voltage whole part:
Voltage_Unit = "0"

For the hundredths part:
Votlage_Hundreths = Right$(Volts, 2) = 36

Then send to display Voltage_Unit = “0”
A decimal point
Then hundredths = “36”
= 0.36 Volts

Remember these are 3 times measured voltage since on 0 – 15V
So for last example approximate voltage on pin = 0.36/3= 0.12 There will be an error factor since not using floating point.
Martin

Post Reply