PDA

View Full Version : ADCIN query



muddy0409
- 24th June 2009, 10:15
Hi all.
Got a little problem with a project:

I am reading a single Anaolgue pin, and then sterring a particular LED on depending on the reading

start:

adcin 1, instate

select case instate

case is>220 'actual is 248
portb = %00010000
goto finish

case is>190 'actual is 201
portb = %00001000
goto finish

case is>162 '178
portb = %00000100
goto finish

case is> 139 '154
portb = %00000010
goto finish

case is<133 '108
portb = %00000001
goto finish
case is >132 and is <140 '136
portb = %00000000
goto finish

finish: end select
pause 20
goto start


The first 5 cases are OK, however when I disconnect the input pin so that it is open circuit, rather than setting all LEDs off, for some reason PB1 turns on. The open circuit reading is not in the range for that, as it is 136 which falls into the 6th case.
Each reading sith within a particular window, but for some reason there is a hiccup.

There is a resistor divider and Cap on the input line, and have looked at it on my CRO and can't see any noise on the pin. (anyway, any noise would (should) cause a couple of LEDs to blink?))

Have tried 'F88, 'F819 and 'C715 in the target PCB and in my development board with the same result.
Have also sent the reading to an LCD and each shows up as what it should be.

Any ideas (again?)

Regards,
Peter Moritz.

Dave
- 24th June 2009, 11:31
muddy0409, Try this...

case is >133
portb = %00000000
goto finish
case is<134 '108
portb = %00000001
goto finish

I have to ask though, Why are you using all of the "goto finish" statements? The case statement takes care of that for you.. The code would run faster with out them...

Dave Purola,
N8NTA

Acetronics2
- 24th June 2009, 12:48
Hi, Peter

isn't that a Typo ???



case is<133 '108


Cause the written code matches to what you describe ...

so, Try this one :



start:

adcin 1, instate

select case instate

case is>220 'actual is 248
portb = %00010000

case is>190 'actual is 201
portb = %00001000


case is>162 '178
portb = %00000100


case is> 139 '154
portb = %00000010


case is >132 '136
portb = %00000001


case ELSE '108
portb = %00000000

end select

pause 20
goto start



Here, leds will be off for Open input ... if divider present on input !

Alain

PS ... I suppose you mix "break" C statement with PbP " go to Finish " ... lol : PbP do not [no]need[no] have it !!!