Comparator and Project Boards

Gypsy

New Member
I am using a comparator (eg LM339) to convert analoge inputs (Thermistor etc) to digital so the Picaxe (18X) can report an alarm condition when the temperature reaches a preset threshold. The Project Boards (CHI030, AXE020) all seem to have a pull-down resistor on th inputs, but, as I understand, the Comparator output needs a pull-up resistor.

Do I have to break the pull-down resistor on the board and add a pull-up one, or is there a cunning way to interface the Comparator without damaging the Board? And do I need a resistor between the Comparator outpu pin and the Picaxe input? Why do the Boards use pull-down instead of pull-up resistors?

NB I am using the ADC inputs already.
 

moxhamj

New Member
Yes from memory the 339 needs a pull up resistor - eg 2.7k

It is a bit of a strange chip in that respect. I've tended to use 324s instead - you can use them as comparators and then don't need pullup resistors.

I suppose if you have run out of adc inputs, maybe look at a bigger picaxe chip?
 

westaust55

Moderator
Boriz,

That would work, but you may experience a small amount of error as there will be a few microamps reverse current back through the (non ideal) diodes.

Poking the relevant TRISx register (x = A, B, C,D depending upon which PICAXE) of the PIC chip to set the unused output as an input which gives a tri-state (very high impedance) output would improve the situation.

Depends on the accuracy you want and if timing is critical poking the respective TRISx register (in terms of spending time poking operatings) to switch the optputs.

Have a look at the PICAXE memory map I created a while back
http://www.picaxeforum.co.uk/showthread.php?t=9525

pokes to locations 133 to 137 cover the various TRIS registers.

To make a pin an input the coresponding TRISx bit must be set high (=1).

On the 40X1 for example, the standard Outputs are on port B so TRISB applies. The 40X1 Port C obviously uses the TRISC.

For other PICAXE models people will need to check wich port is used for the outputs.
 
Last edited:

boriz

Senior Member
@westaust55
A pA is one billionth of a mA. If your thermistor divider is drawing (say) 1mA, and you are using 5v, and you are using READADC10 (1024 steps), then in order for the reading to change by just one bit, the ‘error load’ caused by the diode would need to be at least 1/1024 mA or about 1uA (one million pA). If your diode has that much leakage at 5v, I’d throw it away. Anyway, the ADC itself probably draws more than that!

Or am I missing something?
 

Dippy

Moderator
I'm sure you are perfectly right Boriz, but remember WA has only been wrong twice in his life!! (And was obviously bursting to say something;) )

Maybe you'd be running the diodes at max Vr @ 100oC?? That could deffo affect things.

I would have thought that with I/O control then, in some cases, the diodes wouldn't be needed at all.
But I'm just guessing out loud, you lot know more than I.
 

Michael 2727

Senior Member
For a few Bob extra you could use a DS18B20 rather than the Thermistor.
Prolly work out cheaper in the long run, by the time you far, um fiddle around
with OP Amps etc.
 

Gypsy

New Member
Thanks for the tips.
All I'm using the Comparator for is to create a digital signal from an anologue one and use in conjunction with a Project Board - from your replies there seems to be no way to interface the two without removing the pull-down resistors from the project board. Shame - trying to KISS!
Tried to keep my description of the problem simple - I am also using a Gas detector which uses a temperature-compensated voltage divider as its trigger reference, and and LED/LDR pair as a Tacho to create a pulse that PULSIN/COUNT can read.
I already have lots of comparators (LM339 etc) from other projects. Need to get my head round the LM324 Op Amp... and look up a 4051...

Boriz - did not really understand what your drawing does - are you using the OpAmp to select between one or other of the Thermistors?

Westaust55 - have followed your link on switching outputs to inputs - looks promising. On an 18X would POKE 135, %00000001 set output 1 to be an ADC input? (ie decimal 135 = TRISC on the 18X) And does this stay after a reset? So do I have to be careful to undo it before reusing the chip?
 

boriz

Senior Member
Sorry G. I did not make it clear, but OP1 means PICAXE digital OutPut 1. (Could be any output). So it’s either 0v or 5v.

The Idea being that when OP1 is high and OP2 is low, the LDR divider is being supplied with +5V by OP1 and the ADC is reading from the junction of the LDR/ resistor divider. Because OP2 is low, it’s diode is reverse biased and does not contribute to the ADC reading.

On the other hand, with OP1 low and OP2 high, the reverse is true. The ADC gets it’s level from the thermistor/resistor divider and the LDR does not effect the reading.

By swapping which divider gets the power before making an ADC reading, you can sort of multiplex a single ADC to read several divider-type sensor arrangements (you may need a short delay between powering the divider and reading it). This method could probably be expanded using transistors to include other analogue signal sources.

Just remember to only have one divider powered at a time, or you’ll get ‘difficult to interpret’ results.
 
Top