Usual digital voltmeter using ADC
-
- 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
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?
-
- 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
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
What are you trying to do? Which MCU are you using? Can you post your code?
Merton
Re: Usual digital voltmeter using ADC
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?
What code do you ask about?
-
- 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
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
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
-
- 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
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
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
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Re: Usual digital voltmeter using ADC
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
-
- 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
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
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
Re: Usual digital voltmeter using ADC
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.chipfryer27 wrote: ↑Sun Aug 21, 2022 7:16 pmI 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?
Regards.
-
- 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
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
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