Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 22:30 13 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : HELP! Need MicroMite to measure voltage

     Page 1 of 2    
Author Message
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2933
Posted: 11:06pm 09 Apr 2015
Copy link to clipboard 
Print this post

All,

I am getting strange & unexpected results when measuring a voltage on an analogue pin so thought I would run it pass members here to see if anyone can help me.

Details: Using a 28-pinner MX170 and MMBasic v4.6b. Pin 7 is the pin used for measuring the voltage. PIC has a stable 3v supply (from a 5v USB charger - mains powered). I have an 'external' voltage that varies between 2.5v and 4.5v (the voltage I wish to measure). There is a common ground between 'external' voltage and the PIC (i.e. 0v).

Currently using a simple resistor divider across the 'external' voltage - two 4M7 resistors. So I am expecting to see a voltage reading in MMBasic of approximately half the actual value of the 'external' voltage i.e. between approx 1.25v and 2.25v.

However, I am getting 'inconsistent' results - so for example, fixing the external voltage at approx. 4v I will get a reading of anything between 1.1v and 2.2v. I would expect to consistently see approx 2v.

So the questions I have:

1> Are two 4M7 resistors too high for a divider? If so, what maximum value can I use to minimise 'loading' of the 'external' voltage?

2> Pin 7 is set to AIN at the start of the program. Is it better to do something else?

3> Print Pin(0) causes an error (I remember reading about this before in another thread but yet to find the outcome). Can I use Pin(0) somehow to test things?

Note, I have tried other analogue pins to eliminate the issue of a faulty pin. Also tried another PIC just in case!

Any views and/or help on the above would be extremely welcomed as I am obviously doing something wrong (or there is a firmware bug which I doubt!)

Thanks . . . .

WW

Edited by WhiteWizzard 2015-04-11
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 11:14pm 09 Apr 2015
Copy link to clipboard 
Print this post

My inexpert opinions:
1: yes. I would use 10k to 20k
2: don't know
3: I seem to recall there is a hardware bug in the PIC which affects pin(0)

Bob
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 11:20pm 09 Apr 2015
Copy link to clipboard 
Print this post

4M7 resistors are definite too high. From memory, the input bias on an analogue pin in PIC32 was about 2uA so I would not go above 1M. If you are targeting better noise immunity, even much lower - 100-200k.
http://rittle.org

--------------
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2933
Posted: 11:21pm 09 Apr 2015
Copy link to clipboard 
Print this post

Thanks Bob

I am about to drop the resistor value now to see what happens . . .
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2933
Posted: 11:24pm 09 Apr 2015
Copy link to clipboard 
Print this post

Hi Kon,

You're reply came in as I was typing a response to Bob.
Will try two 470Ks to give just over 2uA current . . .
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2933
Posted: 11:48pm 09 Apr 2015
Copy link to clipboard 
Print this post

OK - success (kind of).

Two 470Ks now give the expected consistency - thanks, Kon/Bob for pointing to a lower value

However, I have noticed that the first read always returns a value of 3.3?? Not too much of an issue as I can do an initial 'dummy' read.

I do vaguely remember a comment about this too - can anyone remember (or indeed know) whether there is a 'bug' with the first read whenever the program is first run??

WW
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3285
Posted: 02:45am 10 Apr 2015
Copy link to clipboard 
Print this post

The Microchip documentation states that the source resistance should be 10K or less for an "accurate" reading. This is because the sample-and-hold is a capacitor and it needs a low source resistance to charge up to the full value during the sample period.

This sounds like something that should be documented in the user manual...

Geoff
Geoff Graham - http://geoffg.net
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1576
Posted: 07:54am 10 Apr 2015
Copy link to clipboard 
Print this post

Hi Geoff

  Quote  The Microchip documentation states that the source resistance should be 10K or less

Where can I find that?

I only found (p 275 on PIC32MX1XX/2XX Datasheet)
  Quote  Recommended Impedance of Analog Voltage Source=5k

??

Does an analog input have a impedance of 1MR?

Regards
Michael
causality ≠ correlation ≠ coincidence
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3285
Posted: 11:57am 10 Apr 2015
Copy link to clipboard 
Print this post

You are right, the data sheet does specify 5K. I must have been thinking of another chip.

Also, the Micromite Manual does mention this factor - on page 38 (although it says 10K which I will correct).

The input impedance is quite high, the reason why a low source impedance is required is to allow the voltage across the sample-and-hold capacitor to settle.

Geoff


Edited by Geoffg 2015-04-11
Geoff Graham - http://geoffg.net
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2949
Posted: 02:48pm 10 Apr 2015
Copy link to clipboard 
Print this post

Phil,

If 2 x 2.5k resistors is too much load you may have to design some sort of voltage comparator into the circuit..

I know `of' these type of chips but I am really more of a digital man rather than an analogue one.

I did a search on Element14/farnell and this is the only one I can find

Comparitor but I am sure there are other high impedance optios for you there.

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
VK2MCT
Senior Member

Joined: 30/03/2012
Location: Australia
Posts: 120
Posted: 03:11pm 10 Apr 2015
Copy link to clipboard 
Print this post

Mr Wizzard,
What is the voltage range you are wanting to measure ?
John B
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 07:21pm 10 Apr 2015
Copy link to clipboard 
Print this post

  bigmik said  
I know `of' these type of chips but I am really more of a digital man rather than an analogue one.


For this type of circuit, I use the old faithful LM324.
4 op amps in the one package and it runs on a single supply rail. It can run on 3V and if you run it on 5V the outputs can swing from zero to about 3.5V making it a good input protector for the 'mites.

But I expect that a pair of ~4.7k resistors will be the right choice here.

Jim
VK7JH
MMedit
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2933
Posted: 09:47pm 10 Apr 2015
Copy link to clipboard 
Print this post

Just woke up to all this feedback - thanks guys.

I was Googling last night and came across a relevant document (albeit for the Atmega). In it they specify 10k source resistance which is probably the document Geoff was referring to when he mentioned 10k.

Anyway, the two 470Ks are working 'consistently' and also within accuracy - however, I may drop them to 100k to be doubly sure of reliability.

Another method I may employ is to use two 4K7 and add a series MOSFET to 'connect' them when doing a periodic measurement. Ultimately I am after an ultra low power circuit (since it is a battery voltage being measured) so leaving 5Ks connected all the time just won't be suitable.

As previously mentioned - the voltage range is 2.5v to 4.5v. The PIC voltage is 3v (not 3v3).

Time to switch on the soldering iron . . . .

WW

 
srnet
Senior Member

Joined: 08/08/2014
Location: United Kingdom
Posts: 164
Posted: 04:54am 11 Apr 2015
Copy link to clipboard 
Print this post

  WhiteWizzard said  Anyway, the two 470Ks are working 'consistently' and also within accuracy - however, I may drop them to 100k to be doubly sure of reliability.


The results may well be consistent, under good supply and low noise conditions, but 100K is still way outside the PIC spec.

I dont know if the 170s etc are better, but most PICs need to be kept to the 5K region.
$50SAT is Silent but probably still working.
For information on LoRa visit http://www.loratracker.uk/

 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2933
Posted: 05:31am 11 Apr 2015
Copy link to clipboard 
Print this post

After taking onboard all comments, I have decided to be cautious (even though the two 470Ks are performing really well currently) and will be switching to using two 4K7s.

Instead of connecting one side of the 'divider' to GND (which would result in an unacceptably high current draw from the 'external voltage', I will try connecting the 'bottom' of the divider to a spare MicroMite pin. When I need to measure the 'external' voltage, I will set a MM Pin to DOUT (set to 0) and then do the read on another pin set to AIN. Once read, I will set the DOUT pin (used for 'GND') to OFF and thereby disconnecting the divider from the 'external' voltage.

If this fails for any reason I will simply use the a MM pin to drive a MOSFET connecting the 'divider' to GND.

WW
 
srnet
Senior Member

Joined: 08/08/2014
Location: United Kingdom
Posts: 164
Posted: 06:59am 11 Apr 2015
Copy link to clipboard 
Print this post

It all hinges on what is meant by ultra low power, and how much resolution is actually needed for reading the battery.

I have used a 200K\21.5K arrangement before, with a 4V battery circuit. There was enough resolution for monitoring the battery, and with the bottom of the resistor divider turned 'off' with a PIC pin, the current through the 200K was the result of the differance between the battery voltage on the PIC voltage, i.e. around 5uA.

You cannot completly disconnect the divider circuit from the external voltage because as soon as the bottom end of the divider goes open circuit the diode that protects the pin reading the AD will be forward biased. Edited by srnet 2015-04-12
$50SAT is Silent but probably still working.
For information on LoRa visit http://www.loratracker.uk/

 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1576
Posted: 07:59am 11 Apr 2015
Copy link to clipboard 
Print this post

Hi WW

  Quote  If this fails for any reason I will simply use the a MM pin to drive a MOSFET connecting the 'divider' to GND.


If the "bottom" of the "divider" is not connected to GND then the voltage on AIN equals (nearly) the 'external' voltage.

I would prefer the MOSFET on the "top" of the 'divider'. Between 'external' voltage and 'divider'.

Regards
Michael
causality ≠ correlation ≠ coincidence
 
srnet
Senior Member

Joined: 08/08/2014
Location: United Kingdom
Posts: 164
Posted: 11:52am 11 Apr 2015
Copy link to clipboard 
Print this post

  twofingers said  If the "bottom" of the "divider" is not connected to GND then the voltage on AIN equals (nearly) the 'external' voltage.


No.

In this circumstance where the 'external' voltage is greater than the PIC supply volts then the the voltage on the AIN pin will be one forward voltage drop above the PIC supply volts.



Edited by srnet 2015-04-12
$50SAT is Silent but probably still working.
For information on LoRa visit http://www.loratracker.uk/

 
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 04:52pm 11 Apr 2015
Copy link to clipboard 
Print this post

Hi WhiteWizzard;

Technically the "DC" input impedance to a CMOS input pin is quite high. See specification "D151" which states +-1uA over the full temperature range which implies an impedance of at least 3.3MOhm. In reality it's most likely much higher.

But why do they say the input resistance should 5K or less?
As twofingers said, it's in the spec in order to make the measurements at max speed and best resolution.

However, if the voltage your measuring only changes slowly, as batteries do, you can use a high valued resister if you also add a capacitor from the input pin to ground.

I don't know what the "correct" value would be but 10nF sounds about right, maybe 100nF.

This capacitor provides a low "AC" impedance on the pin allowing the AtoD to convert at best accuracy yet still have a high DC impedance.

redrok

I should add, even with 5K impedance, capacitors should help improve measurement stability. The resultant RC low pass filter would remove noise spikes, with which your probably aren't interested in anyway.Edited by redrok 2015-04-13
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2933
Posted: 10:34pm 11 Apr 2015
Copy link to clipboard 
Print this post

Thanks redrok for your comments.

Now I'm totally confused (not with what you said - but with yesterday's 'experiments/tests'.

Using two 4k7 resistors (currently 'bottom' half connected directly to GND for now) I am getting a reading about 200mV higher than expected. Makes me think there is an internal diode drop in there somewhere BUT the two 470Ks gave me near accurate readings.

I will try with the cap you suggested later today and see what happens.

In terms of 'maximum speed' - what exactly does this mean? Is it the time between setting the pin to AIN and then reading the pin? Is it better to add a delay to increase accuracy? If so, what kind of delay?
OR are you meaning the 'internal workings' speed of measurement in which case I guess I have no control over it?

These are all things I will be playing with today. Ultimately I just want the MM to show me a 'similar' figure to my multimeter for voltages between 2.5v and 4.5v. The first thing I will do is see if my current setup (two 4K7s) is linear. If so then I may simply subtract 200mV - BUT this will leave 'unanswered' questions.

WW
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025