Usual digital voltmeter using ADC

Use this section to discuss your embedded Flowcode projects.
Sergejs
Posts: 143
http://meble-kuchenne.info.pl
Joined: Tue Oct 19, 2021 9:31 am
Has thanked: 73 times
Been thanked: 5 times

Usual digital voltmeter using ADC

Post by Sergejs »

Hi, I have a problem: low memory for Float variables. Is it my mistake and I do something wrong or should I use MCU with memory more than 2K?

mnfisher
Valued Contributor
Posts: 988
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 106 times
Been thanked: 517 times

Re: Usual digital voltmeter using ADC

Post by mnfisher »

2k should allow quite a lot of floats (each is 4 bytes).

What are you trying to do? Which MCU are you using? Can you post your code?

Merton

Sergejs
Posts: 143
Joined: Tue Oct 19, 2021 9:31 am
Has thanked: 73 times
Been thanked: 5 times

Re: Usual digital voltmeter using ADC

Post by Sergejs »

I make voltmeter on PIC12F1822 with LCD 16 x 2. Noone float can not compile. I found old nice PIC16F877A and now all goes good. I hope to finish my idea after some time. I make control of voltage for my electric bicycle.

What code do you ask about?

mnfisher
Valued Contributor
Posts: 988
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 106 times
Been thanked: 517 times

Re: Usual digital voltmeter using ADC

Post by mnfisher »

Glad to hear you got out working..

The code that gives the error message. The PIC12F1822 doesn't have a lot of RAM to store variables (128 bytes) - so with the display using some -you won't have a lot of space to play with.

Martin

BenR
Matrix Staff
Posts: 1756
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 446 times
Been thanked: 606 times

Re: Usual digital voltmeter using ADC

Post by BenR »

Hello,

The code to drive the floating point calculations on an 8bit device can be fairly large. One option on a small device is to try and use integer maths to do the same thing.

If you multiply up your value so each digit is worth say 0.01 of your output value then you can simply do the following when printing your number to the display.

First print your value divided by 100. Then print a decimal point. Then print your value % 100.

So 123 would end up displaying as 1.23

You will need to check if value %100 is less then 10. If it is then you need to print a 0 before the real part of the number.

E.g. 103 might end up appearing as 1.3 and not 1.03

Sergejs
Posts: 143
Joined: Tue Oct 19, 2021 9:31 am
Has thanked: 73 times
Been thanked: 5 times

Re: Usual digital voltmeter using ADC

Post by Sergejs »

Why voltmeter every time show difficult voltage about +/- 5% range? It is not stable than multimeter. What is wrong?
Attachments
16f877a.fcfx
(15.76 KiB) Downloaded 71 times

chipfryer27
Valued Contributor
Posts: 1181
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 287 times
Been thanked: 417 times

Re: Usual digital voltmeter using ADC

Post by chipfryer27 »

Hi

Sorry to be brief.

You are using FRC in your ADC. This isn't recommended for anything other than operation during sleep. Perhaps change to something more suitable (I think chapter 11 in data sheet gives full details).

You are taking a single ADC reading. This in my opinion isn't good practise as unless you are trying to read a very, very stable and smooth reading indeed, then you will be collecting noise and other fluctuations.

If you search the forums for "ADC averaging" or such like I'm sure you will find many posts giving good advice. Averaging your readings will most likely provide you with better stability (assuming you have a reasonable signal to begin with).

I know "medelec35" has posted much on this subject and if I remember correctly even shared a Voltmeter project. Perhaps have a look at his posts?

Hope this helps
Regards

Sergejs
Posts: 143
Joined: Tue Oct 19, 2021 9:31 am
Has thanked: 73 times
Been thanked: 5 times

Re: Usual digital voltmeter using ADC

Post by Sergejs »

chipfryer27 wrote:
Sun Aug 21, 2022 7:16 pm
I know "medelec35" has posted much on this subject and if I remember correctly even shared a Voltmeter project. Perhaps have a look at his posts?
Many thanks for answer! Can you give me a link please? And if you know realy nice working voltmeter can you link to this post or only file with it. I need example how it made by other people and working correctly. Than I will try adapt it for my project.

Regards.

Sergejs
Posts: 143
Joined: Tue Oct 19, 2021 9:31 am
Has thanked: 73 times
Been thanked: 5 times

Re: Usual digital voltmeter using ADC

Post by Sergejs »

Or, I just think, may be I can correct this problem with hardware? Put capacitor on the ADC input or something else?

chipfryer27
Valued Contributor
Posts: 1181
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 287 times
Been thanked: 417 times

Re: Usual digital voltmeter using ADC

Post by chipfryer27 »

Hi

These posts from the v8 forum might be quite helpful showing someone trying to create a digital voltmeter (10 pages worth)

https://www.matrixtsl.com/mmforums/view ... +voltmeter

Regards

Post Reply