Simulator bug?

jcmaco

New Member
If I simulate the following:

main:
readadc 0,b0 ' Read Clutching Paddle Position Value
goto main

With a PICAXE-18X (4 Mhz)

The output2 will be high. Why is that? I am using 5.1.6 of the PICAXE Programming Editor
 

Pfrogs

Member
I also get this problem. Output 2 turns high without any command ordering to do that. I am using Programming Editor 5.2.1. Anyone know I this happen? Is this a simulator bug?
 

Technical

Technical Support
Staff member
We can't make it do that either.

What does the 'pins (out)' value on the variables section of the simulation panel say when this occurs?
 

kevrus

New Member
I tried it with 5.2.0 and everything works as it should. I tried changing the gosubs from 256 to 16 and it was still ok.
 

Pfrogs

Member
Hi,

I'm sorry I didn't explained myself right. I ment to say that I get the same error when I'm using the readadc command (I have actually just tried jcmaco's code and it runs ok - doesn't turn output 2 high). Nonetheless, when i use this code:

init:
pwmout 3,64,255
b1 = 255

main:
readadc 0,b0
if b0 >= 36 and b0 < 72 then red_led
pause 500
if b0 >= 72 and b0 < 108 then green_led
pause 500
if b0 >= 108 and b0 < 144 then blue_led
pause 500
if b0 >= 144 and b0 < 180 then white_led
pause 500
if b0 >= 180 and b0 < 216 then dec_bright
pause 500
if b0 >= 216 and b0 < 255 then inc_bright
pause 500
goto main

red_led:
toggle 0
goto main

green_led:
toggle 1
goto main

blue_led:
toggle 2
goto main

white_led:
high 0,1,2
goto main

dec_bright:
if b1 = 0 then main
b1 = b1 - 5
pwmout 3,64,b1
goto main

inc_bright:
if b1 = 255 then main
b1 = b1 + 5
pwmout 3,64,b1
goto main
---
when it gets to the "Main: readadc 0, b0" it turns output 2 high. Should this happen? Is it something to do with my code?
Note that I haven't tried this code in a real Picaxe, since I'm expecting to get it this week, so I don't know if it is a bug in the simulator or it real happens with the real chip.
Please let me know if this is a bug or is a problem with my code.
Thank you!
Pfrogs

Ps: I'm running Picaxe Programming editor 5.2.1 on Windows XP Pro SP2
Ps to Technical: with my program the Pins (out) on the variables section reads "12 | %00001100"
 

kevrus

New Member
Okay, now ive done couple of checks, the line b1 = 255 sends output 2 high in the simulator, this happens for any of the variables from b0 to b12, and for differing values as well, but only for the 18x, all other '18' chips seem ok in the simulator.

When downloading the line b0 = 255 into an 18x, everything seems ok although downloading the whole of JCMACOs program into an 18x actual, pin 2 does go high . Removing the subroutine 'white_led' stops this.
Havn't studied the code in detail but there may be more than one issue here.
 

Pfrogs

Member
Hi kevrus,

first of all thank you for looking into this issue.
I've actually used Picaxe 18X to simulate my program, and as you very well stated, this "output 2 set to high" problem only happens with 18X (Unfortunately, the Picaxe I've ordered is the 18X..so I'm hopping this is a simulator bug indeed ;)).

I did some testing of my own and found that this two commands set output 2 high (in Picaxe 18X emulator):
---
main:
b1=255

'either value from 0 to 255 set output 2 high
---
main:
readadc 0, b0

'either combination of ADC0,1 or 2 and b0 to b12 sets output 2 high
---
Another thing that I've tried and also sets output2 high is if you set "pin0 = 1" or "pin1 = 1", and more interestingly if you set "pin2 = 0"


I don't really know much about Picaxe, since I'm only starting to use it. But hope that this information might help you in any way to find out if this is a bug in the simulator or just a Picaxe18X behaviour exception thing.
 

hippy

Ex-Staff (retired)
This does appear to be a bug in the simulator which affects the 18X only, and should only affect simulation not physical chips. The single line program "b0=0" run on 18X simulation demonstrates the problem.

@ jcmaco, Pfrogs : The best workround would be to simulate as if you were using a different PICAXE until you have your code design proven, then convert it to run on a physical 18X.
 

Pfrogs

Member
Thank you Hippy! That is what I wanted to hear. I will do what you suggested and hope that in a future release this bug is corrected.
Thank you all again for looking into this issue!
 

kevrus

New Member
Use the 20m for the simulation as the 18 and 18a doesnt support pwmout in the sim.

You could try putting a 'low pin 2' after the offending commands but this will interfere with the sim when b0 is greater than 108 (and you will see pin 2 flash when cycling through the 'main' routine)
 

eclectic

Moderator
@pfrogs.

Your program works on a real 18X.

LED's 0,1 and 2 toggle.
LED 3 varies in brightness.

You might like to add
Code:
main:
readadc 0,b0
sertxd (#b0,"  ",#b1,cr,lf) '***** Add this line
I think you may also need to adjust the Pwmout values, but,
I'll leave the fun experimenting to you. :)

e
 

Pfrogs

Member
@eclectic

thank you for experimenting my code on a real 18X and for suggesting the "debuging" line. I realize that I will have to play with pwmout values and b0 once I have the circuit in place.
Nevertheless, my idea is to have an array of RGB leds (total of 50 leds with common anode) all light up in either R, G or B combinations or all at same time (white) at the press of a switch (one to toogle Red, one to toogle Blue, one to toogle Green, and one to turn RGB=white on).
To control the brightness of all this combinations of light colours (6 in total) I wanted to use Pwmout output.
The thing is that I don't understand much about electronics (I only look at it as a hobby). So far I am still trying to figure out if it is possible to use one output to connect to the cathode (of Red, for example) and the pwmout output to connect the common anode?!? Since I will be drawing 1A max for each colour (3A for white - 20mA each color/led), I know that connecting directly to Picaxe outputs is out of the question. I also realize the answer should be using NPN or PNP transistors to drive the array of leds, but I really can't understand which should I use in which output (have to read more about it).
Anyways, if you could help me out just by letting me know that this idea is feasible, I would appreciated. I am currently designing the circuit (and trying to simulate it in Yenka, with no luck so far)..so once I think I have the final solution I might post it here to get some feedback from you guys and see if I have sorted everything right.
Once again thank you all for your help. It shows true community spirit!
 

Technical

Technical Support
Staff member
We have identified the 18X simulation bug, it is actually with the 'pwmout' command. Once this command has been simulated, it can leave an unwanted 'marker' for output 2 that can later affect other programs that are simulated.

The workaround is to simply restart the Programming Editor after simulating with pwmout. Naturally this will be fixed for the next release, and real life chips will work as expected.
 
Top