ReadInternalTemp, RAW, 8 or 10 bit?

jadney

New Member
How many bits does the ReadInternalTemp IT_RAW_H command return? 8 or 10? The PIC instructions in AN1333 seem to imply that either is possible, but the PICAXE manual entry for this command does not make any mention of this, so I can't tell what the PICAXE firmware has implemented.

I understand that this command is crude, but crude is all I need for my present task, which needs to give some indication of temperature from -20 F to maybe +120 F. I'd just like to get some sort of output that I can do a single point calibration on at room temp and be approximate both higher and lower than that.

Yes, I understand that the number returned is the voltage above ground of 4 PN junctions that hang from Vcc. My Vcc will be zener regulated, so that should be fairly stable.

thanks,
 

Goeytex

Senior Member
Welcome to the Picaxe Forum,

The Online Manual Command Reference states:

When IT_RAW_H or IT_RAW_L are used, the raw reading is returned in a word variable.
Returning a WORD implies that the 10 bit value is returned where the upper 8 bits are the contents of Register ADRESH and the lower 2 bits are Bits bit 7-6 of register ADRESL.
 

AllyCat

Senior Member
Hi,

Welcome to the forum. I don't know if you actually intend to use a zener (shunt) stabiliser, but I'd suggest a proper integrated series regulator, if only a 78L05 or similar.

Also, beware that the tempco of the "PN junctions" seems rather lower than normally expected for a forward-biassed silicon diode, and that there is (still) a bug in PE5. If you haven't already found it, take a look at my thread here.

Cheers, Alan.
 

jadney

New Member
Thanks for the replies. Yes, I noticed the use of "word" in the manual. That certainly implied more than 8 bits, but I was hoping for something explicit. The one programming example they give, which is not for RAW, puts the output in a byte. Ones first assumption on this manual page would be that all results would be the same resolution. This should be explicit in the manual, especially since it's now clear that they are different.

Since I needed to cover temps that go both negative and positive in C, I needed to work with the RAW output. Given the info in AN1333, it's clear that the RAW outputs are probably either 8 or 10 bit. It finally became clear to me that the RAW outputs were 10 bit when I looked at the formulas PICAXE uses to calculate its direct temp outputs. The first thing they do, assuming the default zero offset, is subtract some number. Since those numbers are all larger than 255 and smaller than 1023, the RAW number must be 10 bit. (Assuming 10 bit is the only option larger than 8.)

I have to look into the temp coeffs of a 5.1 V zener vs that of the 78L05. It may work to my advantage, or I may need to go with the 78L05. Yes, that's a very viable option.

I had already tried to follow the arguments about the inverted HI and LOW RAW outputs, but I'll have to admit that I really wasn't able to get all of it. As far as I could see, the outcome seemed to go back and forth, so I wasn't sure about the conclusion. The last I could see was that this was a problem in PE5 which got fixed in PE6. I'm using PE6.0.8.0 (beta) so I assume this means that this is not a problem for me. If so, I'm surprised. I assumed that an error like this would have been in the firmware built into the PICAXE chip, rather than in the editor. Fixing it in the editor is MUCH easier. Glad to be wrong here.

thanks again,
 

AllyCat

Senior Member
Hi,

IMHO it's not just the tempco of a zener but the relatively poor "knee" (V/I) of the lower voltage devices (below 6v2). Maybe not an issue if it's operating from a higher voltage regulated supply (e.g. +12 v) but I'd still prefer the 78L05 for peace of mind.

I'm fairly satisfied that the RAWs in PE5 are wrong (swapped), but corrected in PE6. For me, the main issue (now) is what tempco to use for the internal "diodes", since AFAIK it's not specified in the data sheet. AN1333 suggests 1.32 mV/degC, but contains a few "questionable" aspects (e.g. in Fig 8, what does the "error" changing by 5 degrees between 20 and 25 degrees C imply ? ). The PICaxe formulae use a slightly lower value and my measurements suggested something below 1 mV/deg C. What value do you plan to use? :confused:

Yes, it's fortunate that READINTERNALTEMP is implemented in the Program Editor. Personally, when using a "new" command (to me), I put it in an empty file and do a "sytax" check. That gives the number of bytes used by the command, which gives a fair indication if it's a "real" token or a string of pseudo commands. You may get quite a surprise (even a fright) with BINTOASCII, PWMDUTY and even a humble SWAP . ;)

Cheers, Alan.
 

jadney

New Member
Hi again, and sorry to be absent for so long. This is part of a project that's been rolling around in my mind for over 20 years, so it should come as no surprise that this is not a rush job. Nevertheless, I need to get it right once I implement it. The project is the control of both voltage and current in a power supply that needs a bit of temp dependence on the output voltage. Since the amount of dependence isn't critical, I really haven't worried about my mV/C. I'll look into that eventually, and probably choose a number that's somewhere in the middle. I, too, was confused/amused by the large jump in temp error in that one temp range. That graph implies that the V vs T curve backs over itself in that region. Seems highly unlikely.

I really appreciate all the advice I've gotten here. The time it took to mull that over in my mind is part of the reason it's taken me so long to get back to this thread. The comment on the soft knee of a 5.1 V Zener was a particular concern. I looked into 78L05s, but their dropout voltage is way too large to get this system going. The problem is that the power supply voltage is not much higher than 5.1 V and I need good control of IT's voltage, and IT's voltage is the supply for the PICAXE regulator input.

My PICAXE software is written to run thru a calibration routine only on the very first startup after programming. At that time the circuit would be powered by a regulated supply at the desired output voltage. It then averages and stores the ADC values it gets and uses those for all future comparisons. That will remove all later errors due to PICAXE variations and resistor tolerances. The only remaining error would be due to the accuracy of the initial supply voltage, the current supply voltage and the 10 bit ADC conversion. I can control the first one, and 10 bits is plenty of resolution for this application. That just leave the current supply voltage as an error source.

At first, I was looking at doing a CALIBADC10 and using that to normalize each ADC reading to make those readings accurate, regardless of the current supply voltage. That looked doable, but complicated and bound to introduce additional error into the output V. However, I looked for LDO 5 V regulators and find that it's easy to find ones with dropout V down around 0.3 V or so. Those have very good output regulation and should work just fine.

Okay, so here's the next problem in this design. I need to come up with ~+20 V to turn on an N-Channel MOSFET high side switch. I'd love to use a P-Channel, but they don't come in high enough current and low enough Ron. I've looked at charge pumps, but all the charge pumps I've found just double the input voltage, which is not enough. The solution I'm thinking of is to build a discrete 3 or 4-stage voltage multiplier working off a square wave from another PICAXE output. It does not have to put out much current, so it seems to me that this should be a reasonable, but possibly clumsy, way to do the job. I wonder if anyone makes a VM in an IC?

Any comments?

thanks,
 

premelec

Senior Member
I haven't understood your whole project - recently I got some up-converters which would have about 75% efficiency converting 5 to 20 - reasonably low input idle power - I don't know what your power budget is - anyhow they were cheap from the Orient use XL6009E1 chip... These are higher current than you need and fairly large PCB if you need small - but there are other units and circuits - some drivers that would up convert I think.
 

AllyCat

Senior Member
Hi,

Firstly, on the original topic: Whilst I do still hope to ultimately get "useful" results from READINTERNALTEMP (in particular to monitor the power dissipated in the PICaxe), there's a limit to how much time one should spend "beating one's head against a brick wall" to "make a silk purse out of a sow's ear". Generally an external thermistor, or even a single forward biassed diode (to ground) will give a better result. Apart from the internal temperature sensor circuit, virtually all other "precision" ADC measurements can use the internal Fixed Voltage Reference, even using an unstabilised supply.

----

An issue with Charge Pump circuits is that they are not really voltage "multipliers", but only "adders". So to step up from 5v to 20v requires at least 3 stages and probably 4, taking into acount the diode forward voltage drops (and capacitor droop). So you'll likely need 8 diodes and 8 capacitors, but they could be quite small if using a high frequency square wave drive.

The MAX232 type of (serial comms) integrated circuit includes two charge pump circuits, generating rails of about +10 and -10 volts, and some later versions include the required capacitors internally. To create a +20 volt rail, you could then use a square wave (from the PICaxe) as a "serial data" signal, which would then require only a single "voltage doubler" (peak to peak detector) consisting two diodes and two capacitors.

Alternatively, a simple "boost" converter basically requires only a small inductor, diode and capacitor, plus a transistor rated for the peak output voltage (so can't be within the PICaxe). In principle, a 3:1 duty cycle (transistor conducting for 75% of the time) should generate a 20v rail from 5v. But in practice, I think a feedback loop is still required to control the input current (e.g. by changing the frequency).

There may be some dedicated and fully integrated chips available for the purpose now, but I don't know of any specific part numbers, and they'll probably be available only in SMD packages. :(

Cheers, Alan.
 

jadney

New Member
I love the silk purse/sow's ear analogy. The good news here is that the sow's ear is plenty good enough for this application, so I'll just be content with it.

I've looked at a few charge pumps, and all the ones I've found are either inverters, or drivers for voltage multipliers, so I still have to supply diodes and caps. I did find some very nice DC-DC converters which had isolated outputs, which seemed perfect until I priced them ($17-20 each.) So that was a non-starter.

Now I've rethought this, which seems to be the continuing story of this project, and I finally realized that what I really needed to drive a high side N-channel MOSFET was a voltage that was 10 V higher than the high side rail. Since the first stage of any voltage multiplier is a capacitor, why not just cap couple from the PICAXE up to a 2-stage voltage multiplier riding on top of the high side rail. Now that won't give me a full 10 V for the MOSFET gate if the PICAXE is running off a 78L05. So how about going back to a slightly higher zener, like 5.5 V. That would give out a slightly higher square wave to make up for diode losses in the voltage multiplier.

Okay, so I go back to zener regulation. What does that do to my ADC conversion? Well, I was stumbling around this forum somewhere and came across someone mentioning running the internal ADC off the internal 1.024 V. So I says to myself, "What's up with that?" You mean there's a way to make the ADC conversion independent of the supply voltage? Okay, a little search reveals that the following commands:

ADCCONFIG
FVRSETUP

Which should allow me to set the ADC to use a fixed internal voltage as the ADC scaling factor, regardless of any variation in the supply voltage. I'm tempted to use a range of 0-4.096 V, but, as usual, these commands raise more questions. Specifically, the manual states that the FVRSETUP status gets automatically turned off after any READADC command, so I have to re-issue the FVRSETUP command before every READADC. Is this correct? If so, does the ADCCONFIG command also have to be re-issued?

Secondly, how stable are the internal references to temp variations? Any graphs or app notes on this?

Thirdly, would these commands apply equally well to the raw internal temperature reading?

And,finally, is it possible to set ADC measurements to take place between TWO fixed internal voltages, say 1.024 - 4.096 V, or 2.048 - 4.096 V? From the manual, I'd say not possible, but there would be a real resolution advantage to suppressed zero scaling for me, so I'm hoping.

thanks,
 

AllyCat

Senior Member
Hi,

You can really only use a zener diode as a "shunt" regulator when it is driven from a reasonably constant current. That's usually done by feeding it through a resistor from a much higher voltage. But you don't appear to have that, so I'd bin the idea of using a zener. However, you could use a "variable" voltage regulator chip (usually set by the ratio of two resistors), or simply put a forward diode in series with the earth pin of a 78L05. The latter will give an output rail around 5.6 volts, but obviously with slighly worse regulation and tempco.

Yes, sitting a "doubler" on top the supply rail will get you reasonably close to 15 volts and using schottky diodes (which have a lower forward voltage drop, nearer to 300 mV) could help somewhat. But don't overlook that the PIC(axe) output devices are not perfect switches, each is likely to drop a voltage similar to a forward diode at higher currents (say ~10 mA), particularly the pull-up transistors. So I think you might struggle to get to 15 volts.

Yes, as I hinted in #8, using the FVR is probably the way to go. It will be specified in the "base" PIC data sheet (linked from here) but the Microchip specifications tend to be notoriously pessimistic. In particular it specifies that the 1.024 volt FVR should NOT be used for the ADCs (which are only rated down to 1.8 volts). Note that most chips have two "FVR"s, but the PICaxe commands control them in tandem.

I'm not sure about READADC "corrupting" the FVR setting, but sometimes the "generic" statements in the PICaxe manuals need to be taken with a pinch of salt (whether positive or negative) and need to be checked with real hardware and code in your particular application. As I discovered in my thread linked in #3, this applies particularly to the internal temperature measurement (which it appears almost nobody has used successfully).

I think that covers most of your questions but I don't believe that you've said which PICaxe you're planning to use, which makes detailed answers more difficult. With some of the chips (not the M2s) it's possible to use an external reference voltage for the ADC Low Voltage Reference, but I don't believe an internal reference can be used (because the FVR is allocated to the Positive Reference).

Cheers, Alan.
 

jadney

New Member
Okay, I'll have to play with the FVR settings and see what really needs to be done to make this work. This application is all about ADC readings, so I really have to get this part right.

Yes, I was certainly planning on using Schottkys for the VM diodes.

Right now I'm trying to get this all to work within the 08M2. That depends on being able to pump enough charge using a square wave of around 500-1000 Hz. If that's not enough, I'll need a second PWM channel to generate a higher frequency square wave, which means moving to the 14M2. The charge requirements are minimal: I just need to pump enough charge to raise the gate of a large MOSFET to 10 V in a few (1-2) seconds. Total gate charge looks like ~300 nC, so that means I only need 0.3 uA from the voltage multiplier to do this in 1 second. It's likely that leakage in the circuitry and on the PC board will dominate the charge budget.

Why are you suggesting sticking to a better regulated voltage source even with the ADC running off a FVR? What am I missing?
 

AllyCat

Senior Member
Hi,

It depends what is your "raw" power supply. A zener can only act as a viable shunt regulator when fed from, or via, a significant source resistance. But it might be that you don't need a zener diode at all, or only as a "protection" component, for example to blow a fuse if the supply rail rises dangerously high for a PICaxe (i.e. 6 volts).

Yes, I find it an amusing challenge to see what can be fitted into an 08M2. C.5 (Leg 2) can be an additional input (using DISCONNECT) and with some devious tricks both C.3 and C.0 can be used for both input and output. But I still always try to retain Legs 2 and 7 (SerIn and SerOut) with their fundamental programming and debugging facilities intact, even in the "final" application.

Cheers, Alan.
 

rossko57

Senior Member
I'd use a bit of caution about turning on a "large" FET slowly - with relative large on-resistance during this time it could cook. You might precharge at leisure and "switch on" quickly using a little P transistor.
 
Top