Simulator

Kiwi Bruv

Member
The simulator is using the generic value setting for my ADC input. I have other analogue inputs to and changing these values on the simulator doesn't do anything.

Have I missed a configuration setup or something?
 

BCJKiwi

Senior Member
Which Chip are you using?
Do you have the #PICAXE 28X1 (or whatever chip you are using) at the beginning of your code to tell the programmer/simulator which chip you are using?
Which pins are you trying to use for ADC - only certain pins can do ADC.

or,

Do you mean when running the simulator standard values appear in the simulator - if so then you need to put in the values you want as you step through the program. This is the way the simulator works for things like inputs. Since the program is not running in the chip the inputs have to be supplied by you. This enables you to test different values to check your program is doing what it should.

e.g.
'
#PicAXE 14M
'
' Input 0 ( chip leg 7 ) - Input0 / ADC 0 / hpwmCSymbol LDR = 0 'Input 0
Symbol LDR = 0 'Input 0
'
ReadADC LDR,b0
let w1=b0*4
If b0=>b1 then let b0=b0-b1 ' test to see if READADC value changed.
elseif b1=>b0 then let b0=b1-b0
EndIf

Here you would step until the line "let w1=b0*4 is highlighted (i.e. the value of b0 has been 'read') then double click on the '0' for the value of b0 in the simultor and input the value you want to test and click OK. Then you step once more and that value of b0 is then used in calculating w1.

Trust I have understood your question correctly and that this helps.
 
Last edited:

Kiwi Bruv

Member
simulator problem

See code below. Sim is set up for 28x picaxe.

Status:
pause 500 'init LCD
serout 7,N2400,(254,1) 'clear LCD
pause 30 'allow LCD to clear
serout 7,N2400,(254,128) 'move cursor to start of first line
serout 7,N2400, ("Checking Status ")
readadc10 0,battery_value 'read battery voltage
serout 7,N2400,(254,192) 'move cursor to start of second line
serout 7,N2400, (#battery_value," Volts"

I stepped to the readadc line and then put a value in the AO box, stepped on and the LCD sim showed 0 volts. I then put "50" in the generic value box and the LCD sim showed 50 volts.

battery_value is assigned to w3 and appears as whatever is in the generic value box.
 

Kiwi Bruv

Member
Simulator issue

Re-checked your post and tried a couple of things:

First stepped to the readadc line and then changed the value in the w3 box. Value is reset to 0 after executing the readadc line.

Then after my line - symbol battery_value = w3, I put let w3 = 76. This set the value of w3 which was then reset to 0 after the readadc line was executed.

Then thinking the 0 in the readadc command was a problem I tried changing the readadc line to readadc 1, battery_value, but no difference.

Something wrong with my code, with the value of w3 being set to 0, but what?

'Things to do
'move messages to pre-defined in LCD to save memory
'tune turning to mow next strip ie one motor only to turn or turn onto compass bearing
'brake cutter motor





'Mower program for 28x

'Inputs

'Input 0 is ADC for battery voltage
symbol perimeter_collision_sensor =pin1
symbol tilt_sensor =pin2
symbol bump_sensor =pin3
symbol wet_sensor = pin6
symbol docked_sensor = pin7


'Outputs

symbol cutter_motor = 0
symbol right_motor_drive =1
symbol left_motor_drive = 2
symbol run_LED =5
symbol piezo_sounder = 6
'output 7 is serial comms with LCD




'Variables and constants

symbol full_charge = w1
Let full_charge =100 ' set battery threshold voltage for fully charged
symbol battery_value = w3
symbol running_flag =b12

'random number for turning =w4

'Check machine status and if Ok goto start sequence

Status:
pause 500 'init LCD
serout 7,N2400,(254,1) 'clear LCD
pause 30 'allow LCD to clear
serout 7,N2400,(254,128) 'move cursor to start of first line
serout 7,N2400, ("Checking Status ")
readadc10 0,battery_value 'read battery voltage
serout 7,N2400,(254,192) 'move cursor to start of second line
serout 7,N2400, (#battery_value," Volts")
if docked_sensor =1 then feed
If perimeter_collision_sensor = 1 and battery_value <300 then home
if perimeter_collision_sensor = 1 then reverse_direction
if tilt_sensor =1 then alarm
if wet_sensor =1 then home
if running_flag =0 then start 'if not already running goto start
random w4 'generate randon number
debug
sound piezo_sounder,(100,50) 'setup intermittent beep
goto status 'continue to monitor status

'Shutdown machine, wait and check status

Shutdown:

Low cutter_motor 'shutdown cutter
' would be better to brake cutter motor!
serout 7,N2400,(254,1) 'clear LCD
pause 30 'allow LCD to clear
serout 7,N2400,(254,128) 'move cursor to start of first line
serout 7,N2400, ("Stopping ")
Pulsout Right_Motor_drive,150 'stop (low outputs doesn't stop!) speed change on MD22 operates on next pulse
Pulsout Left_Motor_Drive,150
readadc10 0,battery_value 'read battery voltage
Pause 5000 'wait for complete shutdown
low run_LED 'turn off running lamp
Let running_flag=0 'flag start is required
sound piezo_sounder, (120,500)'signal stopped
serout 7,N2400,(254,1) 'clear LCD
pause 30 'allow LCD to clear
serout 7,N2400,(254,128) 'move cursor to start of first line
serout 7,N2400, ("Waiting for 10 mins")
'put countdown here
sleep 260 'wait 10 mins then check if reason for shutdown has gone
Goto status
 

BCJKiwi

Senior Member
I think you are one step away from where you need to be. Post #2 indicates;

"Here you would step until the line "let w1=B*4 is highlighted (i.e. the value of b0 has been 'read')"

in your case this needs to be until the line
"serout 7,N2400,(254,192) 'move cursor to start of second line"
is highlighted - i.e. the non-existent value has been read (as 0).
The command on the highlighted line does not get processed until you step OFF the highlighted line.
In this case there is no input for ADC so the simulator just sets it to 0 and moves on so you need to change the value after it has processed that line but before it processes the next line.

Checked this in your code and it seems OK (had to rem out the IF tests - variables not defined, and I put in the following line above the rem'd out IFs;
If Battery_value < 100 then goto shutdown
to test it.

If you add the if statement as I did for testing purposes and then step to the line
serout 7,N2400,(254,192) 'move cursor to start of second line
THEN change the value of w3 (Battery_Value) to 110 or 190, the code branches accordingly.
 
Last edited:

jonphenry

New Member
PicAxe Manual 1, Page 44, Basic Simulation

Analogue input values are shown in a grid and can be altered by the scroll
up/down buttons or by typing over the value directly (0-255). These are the
values used by the ‘readadc’ command.

The ‘generic’ value operates in a similar manner (0-65535) and is used by
the following commands as the input value: count, pulsin, readadc10,
readtemp, readtemp12


When using readadc10, the generic controls your input values in simulation.
 
Top