Simulator - 18X readadc turns on output?

BCJKiwi

Senior Member
PE 5.12.0 / 262144
Working on this problem for mshorter and found strange behaviour in the simulator;

Code:
#picaxe 18X
 
main:
'Sound
readadc 2,b1
'sertxd ("Sound (b1) - ",#b1,cr,lf)
 
'LEDs
readoutputs b0
If bit0 = 1 then            'Check if pump 1 is on
    b2 = b1 - 100 * 2
EndIf
 
'Pumps
select case b1
case <110                   'OFF
    pins = %00000000
case 110 to 130             'Pump 1
    pins = %00000001
    pwmout 3,255,b2
 
case 131 to 160             'Pump 2
    pins = %00000011
    pwmout 3,255,b2
 
case 161 to 190             'Pump 3
    pins = %00000111
    pwmout 3,255,b2
 
Else                        'Pump 4 b1 >189
    pins = %00010111        'Leds pwm on pin3
    pwmout 3,255,b2
 
EndSelect 
 
goto main
When stepping through the code with the simulator, the first time the editor is run on the first pass all seems OK but on the second pass, immediately the readadc command is stpped through, output 2 goes high. This is the same regarless of which adc is set for read i.e. readadc 0, 1, or 2!

The same thing seems to happen if the read adc line is remmed out and b1 is is set manually within the simulator.

Also readadc does not produce a value - my memory says that in earlier versions of the editor, a readadc line in the simulator returned a mid range value or am I dreaming?
 
Last edited:

maitchy

Member
I suspect it isn't the readadc that is turning on output 2 - seems to be some other simulator fault as far as I can see (even 1 after pins = 0 for me).
 

BCJKiwi

Senior Member
I suspect the simulator is actually processing the result of the readadc and acting on it elswhere in the program before that part has been stepped to.
 
Top