ADC reads varies a lot, direct out chip 1 -> ADC chip 2

amewsaj

Member
Hi,

I have a project where I use both 28x1 and 18x which communicates with each other using pulses. It works great from 28x1 to 18x, but the other way I am having some trouble.

18x OUT6 (pin 12) -> 28x1 ADC0 (pin 2)

(I have to use ADC since I use all other input pins as output)

On the 18x I set "high 6"
On 28x1 I use readadc 0,b0 (But it varies about 0-200)

I have measured the output from 18x, and I get 0V on low, but only 2,7V on high.

The cable is not connected to the PC at this time.

- So the question, why so unstable readings on adc0 with a stable output 2,7V. (Average seems ok)
- Why only 2,7V out on that port (had a problem with another 18x with that pin as well)?


I have tried adc readings from trimpots and LDRs, no problems at all.
I have read that a BAT85 can be required for proper adc readings, but isn't that mostly while pc cable is connected?


Thank you...
 

Jeremy Leach

Senior Member
Hmm, what power supply voltage are you using for both picaxes? Have you made a direct connection from output to ADC input? How long does the pulse last?

P.S Welcome to the forum ;)
 

amewsaj

Member
Thank you,

The power supply is a 9V adapter, regulated with a 7805 voltage regulator with parallel 100 nF and 100 uF elect. capacitor from ground to output on the 7805.

Measuring supply voltage on microcontrollers shows 5V.

Yes I made a direct connection from output (18x) to ADC input (28x1).

Well, the purpose is to communicate using pulse, but since I had those issues, I tried setting the output always high, but still readings are as mentioned in first post.

I tried putting a 10k resistor from ADC to ground, but as I expected it seems to have no influence.
 

Jeremy Leach

Senior Member
So you're getting 2.7V as a 'high' output level on a 5V powered picaxe. Hmm. Checked your wiring? What do you get with no connection to that output pin?
 

hippy

Ex-Staff (retired)
It does sound like a circuit wiring problem and 2V7 is suspiciously close to half 5V to suggest that two pins are shorted together, one high, one low.

Maybe strip the circuit down to the bare minimum. Check continuity and voltage with no chips inserted, add the 18X, check again. With the 18X having executed the HIGH command, you should be able to read that back on the same 18X with READADC.
 

amewsaj

Member
Wiring problem was my first guess to, but before plugging in anything, I measured each and every pin in the socket, and everything seems fine.

And ehm, btw, I think I've just found the issue.
It is probably time to say: "DOH!" :rolleyes:

I have not tried to force it high (thought I had)
The real code is:
Code:
readadc 2,b2            (READING LDR)
if b2 > 100 then high 6
else low 6 endif
And further down:
Code:
if b2 < 100 then
	let pins = hrs
else
	let pins = %00010000
endif
It seems to be the issue. I switch output 6 high, and then I let pins = hrs (which means that 6 go low again)

So it keeps going high and low.

Thank you for your suggestions though...

--
Maybe you can quickly answer this? (or should I create a new thread?)
I tried using the count command to count pulses, but it keeps giving me an incorrect result (some times correct, often +1)
I created my own loop instead to check for changes (high/low) and by that count. It works just fine.
What is wrong with the count command?
 
Last edited:

Jeremy Leach

Senior Member
Glad you found the problem - so you were measuring an average ;)

I expect there's nothing wrong with the count command at all. Manual states:
"Count checks the state of the input pin and counts the number of low to high transitions within the time &#8216;period&#8217;."

My guess is that you aren't counting low to high transitions when you do it manually, so you aren't comparing like for like?
 
Last edited:

amewsaj

Member
Seems I do not get email notifications...

Yes I am counting low to high transistions manually:

Code:
b1 = 0
...
countit:   'sub routine
	b12 = 0
	for b11 = 0 to 200
	if pin7 = 1 then
		if b12 = 0 then
			b1 = b1 + 1
			b12 = 1
		endif
	else
		b12 = 0
	endif
	pause 1
	next b11
return
 

Jeremy Leach

Senior Member
Hi, I find that code a bit confusing. How about something like this, just as a suggestion? ...
Code:
Symbol OldState = bit0
Symbol NewState = bit1
Symbol LowHighCount = b1

'Initialise
OldState = Pin7
LowHighCount = 0

'Count low to high transitions
Do
    NewState = Pin7
    If NewState = 1 And OldState = 0 Then
        Inc LowHighCount
    EndIf

    OldState = NewState
Loop Until Pinx = 1
And exit the loop by setting another pin high.
 

amewsaj

Member
Sure, but it still does the same thing...
And the point is that count does not give me the same number.

Nice, I did not know you could also use bit0 ... and the Inc command.
 

Jeremy Leach

Senior Member
Ok, so we need to check all possibilities:

The manual says "Take care with mechanical switches, which may cause multiple ‘hits’ for each switch push as the metal contacts ‘bounce’ upon closure"

So, how are you switching? If the count command reports greater counts than this code then I'd suspect contact bounce.
 

manie

Senior Member
If you start the "other" chip pin from a low state it will count as 1 pulse won't it ? Try starting from a high state maybe ?
 

hippy

Ex-Staff (retired)
COUNT counts the number of pulses which are seen in a time window, and only starts counting when the level is at the opposite of the level you will be counting. Under some circumstances, depending on how the pulses are synchronised to when you start counting, you may sometimes count one more or less.

If you are counting complete cars going past, assuming cars go past one per second, you open your eyes for four seconds you will normally see four cars. If you open your eyes just as a car is going past you will discard that and sometimes then only count three.

Theoretically you would still count four cars under all circumstances but small discrepancies in the measurement period or pulse arrival time means that doesn't happen.
 

amewsaj

Member
I know, but I have made the code so that I make sure the counts are synchronized. I send a signal to the 18x to make it aware that now I am giving it a pulse. Not until the 18x has "replied" I start sending the pulse.

See?
 

hippy

Ex-Staff (retired)
Okay, but earlier you said, "The hits are generated only by code. Simply pulseout on a specific out pin. (From another chip)". The more detail you can give the better people can understand what you have and it will help them to help you resolve your problems.
 
Top