|
|
View previous topic :: View next topic |
Author |
Message |
harlequin2
Joined: 11 Jun 2011 Posts: 21
|
|
Posted: Fri Mar 08, 2013 1:02 am |
|
|
Should be an edit, but here goes:
I use ref-lo as Vss and ref-hi as Vdd and the input as FVR, then ADC = ( FVR*1023)/Vdd
Is that it?
So the Vdd = ADC/FVR*1023
For a 4.5 V Vdd and a 2.048 FVR, ADC = 465
For Vdd = 3, ADC = 714
So my working voltage range of 4.5 down to 3.0 gives an ADC count of 465 to 714 and hence I can calculate Vdd to insert in the temp formula. Sigh! Its not easy, is it?
Now I have to work out how to calibrate the thing........
Last edited by harlequin2 on Fri Mar 08, 2013 2:30 pm; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri Mar 08, 2013 3:09 am |
|
|
Unfortunately, it is worse than that.....
Historically, an 'ideal' 10bit ADC, has a transfer function, with 1024 steps, and 1023 'risers', with the first riser at 1/2046 of the difference between Vref- and Vref+, and the last riser the same distance below Vref+. This is the 'theoretical' transfer function.
Now Microchip show this as the ADC curve on a few of the PIC data sheets. However in application notes for the same chips they then refer instead to the chips having a 1/2 LSB offset, and on quite a few PIC's now show this as the transfer function. However to screw things up further, in (for example), the PIC24 reference manual, they refer to this transfer function (which would then give a high point transition at 1.5/2048 below the top Vref), and then on the very next page refer to 0.5/2048 instead.
Fortunately, these crossed references appear to be Typo's....
I've had annoying times actually taking measurements, given the variations in the data sheets...
Older PIC's, do in some cases appear to be close to the original 'ideal' function. The 16F677 behaves like this.
Measurement on half a dozen different 'current' PIC's, ranging from slightly older designs like the PIC18F4520, through modern nanowatt chips, gives the best approximation to the current curve for 10bit ADC's as being:
V = (ADC_reading*((Vref+)-(Vref-))/1024) + ((Vref+)-(Vref-))/1024
Basically the chip behaves as if it has 1025 steps, rather than 1024, and gets to the top reading 1.5 steps below Vref+. A reading of '0', is only given for 0.5 of a step, at the bottom of the range.
So it is giving a 1025 'step', but 1024 'riser' range, but behaving as if this started half a step above the '0' point, and ended half a step 'over' the top rail. It just cannot actually give you this extra bit....
Now the 'neat' thing is that this means you can use /1024 as the divider, but it does also mean you can't quite resolve the Vref rails.
The transition appears to possibly be with the 18 series, but also applies to a lot of the newer PIC16 'nanowatt' chips.
Generally, unless you are working with very good voltage references and resistors (remember you'd need to be using 0.1% or better resistors in any dividers etc.), it doesn't make any difference at all. Much better to calibrate using known references, and then any errors in the expected values are also calibrated out.
I'd say you are much better off calibrating by taking some real values on the PIC, and getting a line of best fit on a spreadsheet, and using this as the calibration, rather than assuming the transfer function.
Best Wishes |
|
|
harlequin2
Joined: 11 Jun 2011 Posts: 21
|
|
Posted: Fri Mar 08, 2013 2:26 pm |
|
|
Thank you for that detailed examination. I see from the data for the 16F1826 that the first transition does indeed occur at 1/2 LSB above Vref(-) and the final one at 1.5 LSB below Vref(+).
Taking your transfer function and putting Vref(-) = 0 with the FVR of 2048 (millivolts) as an input, Vref(+) = Vdd and solving for Vdd gives me:
Vdd = (2048.1024)/(ADC+1)
If ADC = 465, the Vdd = 4500 millivolts. Compare this with my original of Vdd = 2048.1023/ADC which gives 4506 mV.
An error of 6 in 4500 or .13 % which is only slightly worse than the 1-in-1000 one expects from a 10-bit ADC.
I guess it all comes down to what precision/accuracy is desired or required in the final product. My idea is to just make a digital thermometer that I can put outside and it will show me the temperature, so an accuracy >= .1 deg C is certainly more than adequate. Probably 1/2 deg would still be OK.
Calibrating over the range of 0 - 40 deg C will cover my part of the world!
And bear in mind that I'm doing this as a hobby, just to learn a little more about the PIC and use a spare micro board for something I would find useful.
I have to say though, that more I discover about the Microchip products, the more I wish I'd stayed with AVR!! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Mar 08, 2013 5:47 pm |
|
|
Seems to me that you're 'over engineering' this simple 'outdoor thermometer' project to death.
The quick and simple solution is to use a DS18B20-P.In less than 10 minutes you'ld have a stable,precise,accurate sensor up and running.Though if you want a reasonable challenge, grab a 10K thermistor and code away!BTW 8bits of reading at a 1hz rate is far more than needed in the 'real' world.
Though it is commendable that you're really getting 'deep into the silicon',you really should retract your final comment(or have kept it to yourself.Please don't berate the silicon,Microchip does tell you the specs,you have to decide if it's right for your application.
ALL micros have their 'quirks' but after 20+ years of using PICs they've past the test of time for me.Quick, how many used an 1802, or know of it ??I've coded 6800,Z80, 1802,6502,68HC11,8052,etc(even an AVR). and what stood out about the 16C84 was the small easy to learn instruction set and AVAILABILITY ! Anyone in the business knows about the 68HC11 'shortage' 2 decades ago...but Microchip has always been able to fill my orders.
And CCS has always tried they're best to update compilers which has to be a huge challenge considering how fast and furious silicon gets produced!
jay |
|
|
harlequin2
Joined: 11 Jun 2011 Posts: 21
|
|
Posted: Fri Mar 08, 2013 9:16 pm |
|
|
Actually, I'm not "over-engineering" anything. You may note, if you read back a bit, that I am simply adapting a spare pcb with a micro and a lcd on it to a different purpose. It is/was a master controller for a Li battery management system. I noted in the Microchip specs that the device had a "temperature indicator" and that gave me the idea of writing some software to turn it into a thermometer.
Comparing the Harvard architecture with that of the AVR is the main reason I commented about that. A bit like comparing Motorola micros with Intel ones. They both get the job done perfectly well.
I too, have been using and programming microcomputers ever since they were invented, but its only in very recent times that I have had occasion to look at Microchip products and I am grateful to CCS for providing such an excellent C compiler that insulates me almost totally from that strange architecture. Still a pity about the lack of a stack though. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Sat Mar 09, 2013 1:24 am |
|
|
One reason that there are 'apparently' so many problems with the PIC, is that the 'title', covers so many chips and generations of chip. We have chips ranging from the old PIC1650, up to the DSPIC33 family, all called PIC's. Even in just one family like the PIC16's, there are several hundred variants. Amazingly many of the early chips are still in use, and a single 'family' like the PIC16, has about five different actual generations, with chips ranging from a few bytes of memory and almost no peripherals, built using just a few hundred transistors, up to some of the nanowatt chips with re-programmable peripheral usage and KB of memory.
I don't think there is any other family in existence, that even gets to the same order of magnitude of number of models.
Here, the forum is dealing with a single compiler capable of handling almost all of this plethora of chips, and covering a huge range of users from some who are starters, with their own range from ones who are trying hard, to others who want to be 'spoon-fed', up to people working fully professionally in the business. A 'silly' range.....
Best Wishes |
|
|
harlequin2
Joined: 11 Jun 2011 Posts: 21
|
|
Posted: Sat Mar 09, 2013 2:16 am |
|
|
Yes, I think that is really part of the problem: there are just so many variants out there it becomes quite tedious searching for just the "right one".
But hey, variety is the spice of life!
I remember trying to make what is now a gps system using a 6800 and some inertial sensors - doomed to failure. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Sat Mar 09, 2013 3:37 am |
|
|
Hmmm.
Forget about the accuracy of the ADC. What is the quoted accuracy of the FVR?. You are actually just lucky that your example is close to 'nominal'.....
Best Wishes |
|
|
harlequin2
Joined: 11 Jun 2011 Posts: 21
|
|
Posted: Tue Mar 12, 2013 4:48 pm |
|
|
The FVR is quoted as -8 to +6 % in the data sheet - not marvellous.
I measured the temp indicator adc output as 776 at 25 deg C and the calculated value is 855, so the error is 79. Using the uncorrected adc value in the equation gives a temp of -13 deg C.
The only way to make an even slightly useful thermometer out of this is to calibrate it using the techniques described in AN1333.
I'd have to say that anyone wanting to make a thermometer had better not use the temperature indicator! However, I can make it work as a one-off. It is certainly quite complex measuring Vdd and then the temp indicator adc to end up with some numbers that can be put into the complicated equations they give.
By the way, did anyone notice the value .00132 given in the equations in AN1333 mysteriously becomes .0132 a couple of times? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Mar 13, 2013 1:57 am |
|
|
Microchip's abilities at generating "typo's", have become fantastic in the last few years....
I don't think the sensor was ever 'aimed' at being a normal thermometer. More at allowing you to detect potentially dangerous overheat situations. Relatively simple calibrations would allow it to warn you if the chip suddenly gets to double it's normal operating temperature for example.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|