READADC appears to "Break" READTEMP (20M2)

AllyCat

Senior Member
Hi,

I've been "playing" wih a DS18B20 and noted that it seems to work fine using only the PICaxe's internal Weak Pullup resistor (~30k) instead of the normal external pullup. It's a "Waterproof Probe" type (so I can't actually check if it's "genuine Dallas") with about 1m of cable, but for the following observation I am using a normal external pullup resistor:

As a follow-up to the above experiment I thought it could be useful to measure the normal voltage level on the data line (I believe the minimum should be 2.2 volts) using READADC. However, after the first READADC, READTEMP appears to always return 0 (zero). Of course READADC turns the Data pin into an input, but it should be this anyway and making it an output doesn't appear to help.

So I tried replacing the READADC{10} by my "equivalent" POKE/PEEK SFR commands and they DO NOT break the READTEMP. Here is my test code (using PE5), any ideas?

Code:
#picaxe 20m2
#no_data
#define showbug

symbol Vcc = b.1			; 18B20 supply
symbol Dat = b.0			; 18B20 data

	pullup 1			; May permit omission of the external pullup resistor
do
	high Vcc					; Supply rail to 18B20
	readtemp dat,w1				; Works fine on first pass
#ifdef showbug
	readadc10 dat,w3				; ** BREAKS Readtemp **
#else
	call readadc1				; Read ADC value of b.1 into w3 using SFRs
#endif
	sertxd(#w1," C  ",#w3,cr,lf)
	pause 3000
loop

	symbol ADRESL 	= $3B		      ; ADC Low byte
	symbol ADRESH 	= $3C		      ; ADC High byte
	symbol ADCON0 	= $3D		      ; ADC control register 0
	symbol ADCON1  = $3E		      ; ADC control register 1
readadc1:	
	pokesfr ADCON1,%10000000		      ; Right Justify result
	pokesfr ADCON0,%00000111		      ; Select b.0 (AN1) input and ADC on
	pokesfr ADCON0,%00000111 	      ; Start conversion
	peeksfr ADRESL,b6,b7 		      ; Read w3
	return
	
#rem    Terminal Typical Result:

16 C  1020
0 C  1021
0 C  1021
Cheers, Alan.
 

hippy

Technical Support
Staff member
On the PICAXE-M2's READADC and READADC10 switch the pin to being Analogue input, and this consequently disables the Digital input, forces it to always be zero when read digitally. You can use "ADCSETUP =" to return pins to digital inputs as required.
 

AllyCat

Senior Member
Hi,

Ah yes, of course, thanks hippy. An ADCSETUP = 0 fixes it.

But it's strange that my READADC1 routine appears to give correct analogue values but doesn't break the READTEMP (presumably the digital input remains connected). I'll have to check my ADC values more accurately.

Cheers, Alan.
 

hippy

Technical Support
Staff member
It is possible to read an ADC on a digital input, but the Microchip datasheets recommend against that.

The digital port interface should be detached from the input when supplied with an analogue signal and the M2's do that automatically in the PICAXE firmware when READADC is executed. Going direct via SFR simply avoids that automatic disconnect.

In most cases it isn't a problem because an input signal will either always be read as digital or analogue. It is only in the case when both are needed that the digital interface has to be reconnected to the pin after a READADC
 
Top