Can edit variable value in simulator

mackingu

New Member
Can't edit variable value in simulator

Actually, the title is misleading - I can in fact edit the variable value - however, it keeps resetting itself back to zero.

I have a program using the readadc command, and I tried to set the value to some random number. Everytime the program would get to the end of the program, it will reset the variable value back to zero. I got it to work the first time I tried it, but now it won't work.

Any help is greatly appreciated.
 
Last edited:

mackingu

New Member
Code:
'08M program

symbol pbutton = pin3				
symbol pressed = 0
symbol trimpot_pin = 1				
symbol trimpot_value = b1			'put the trimpot value into memory address b1
symbol LDR_pin = 4					
symbol LDR_value = b2				'put the LDR value into memory address b2
symbol dispensed = b5				'count the number of times pballs fall into memory address b3
symbol supposed_to_dispense = b4



read_trimpot:
	readadc trimpot_pin, trimpot_value	'read the value from the trimpot and put it into variable "trimpot_value"
	goto button_press				'check if user has pressed button to start dispensing pballs



button_press:
	if pbutton = pressed then main	'checks to see if the switched has been pressed
	goto read_trimpot				'if button isn't pressed, checks value of pot to see if it's changed then checks if button has been pressed


main:
	if trimpot_value < 2 then dispense_zero'if knob is turned to off, no pballs are dispensed and program goes back to check the trimpot
	pwmout 2,150,150					
	goto check_pballs_to_be_dispensed


check_pballs_to_be_dispensed:
	if trimpot_value < 26 then 
	let supposed_to_dispense = 20
	goto read_LDR
	endif
	
	if trimpot_value < 51 then 
	let supposed_to_dispense = 40
	goto read_LDR
	endif
	
	if trimpot_value < 77 then 
	let supposed_to_dispense = 60
	goto read_LDR
	endif
	
	if trimpot_value < 102 then 
	let supposed_to_dispense = 80
	goto read_LDR
	endif
	
	if trimpot_value < 128 then 
	let supposed_to_dispense = 100
	goto read_LDR
	endif
	
	if trimpot_value < 153 then 
	let supposed_to_dispense = 120
	goto read_LDR
	endif
	
	if trimpot_value < 179 then 
	let supposed_to_dispense = 140
	goto read_LDR
	endif
	
	if trimpot_value < 204 then 
	let supposed_to_dispense = 160
	goto read_LDR
	endif
	
	if trimpot_value < 230 then 
	let supposed_to_dispense = 180
	goto read_LDR
	endif
	
	if trimpot_value < 255 then 
	let supposed_to_dispense = 200
	goto read_LDR
	endif
	
read_LDR:
	readadc LDR_pin, LDR_value		'reads value into LDR_value
	if LDR_value>50 then count_pballs	
	

count_pballs:
	let dispensed = dispensed + 1
	if dispensed < supposed_to_dispense then goto read_LDR
	pwmout 2,0,0				
	

dispense_zero:
	pwmout 2,0,0					
	goto read_trimpot
I just realized that a little explaination of the program might help. Using a trimpot to select the desired number, the program should spit out a specific number of gumballs as well as count them to make sure the desired number of gumballs have been dispensed. If the number of gumballs dispensed is less than desired, it'll keep spitting gumballs out until the number is reached then shut off the motor.

I used to do R&D at a confectionary plant, and i came up with the idea of this device for my old boss to use when he's running small samples as a time saver of sorts. It's really just a thank-you gift for him as well as he's the one who helped get me into the industry many years ago.

Thanks in advance.
 
Last edited:

eclectic

Moderator
Only had a very quick check.

Two points.
This section ...
Code:
read_LDR:
	readadc LDR_pin, LDR_value		'reads value into LDR_value
	if LDR_value>50 then count_pballs	
	

count_pballs:
	let dispensed = dispensed + 1
	if dispensed < supposed_to_dispense then goto read_LDR
	pwmout 2,0,0
What happens if LDR_value is < than 50?
The program still continues to count_pballs.

Also, pwmout is best stopped with

pwmout 2 OFF

e
 

mackingu

New Member
Only had a very quick check.

Two points.
This section ...
Code:
read_LDR:
	readadc LDR_pin, LDR_value		'reads value into LDR_value
	if LDR_value>50 then count_pballs	
	

count_pballs:
	let dispensed = dispensed + 1
	if dispensed < supposed_to_dispense then goto read_LDR
	pwmout 2,0,0
What happens if LDR_value is < than 50?
The program still continues to count_pballs.

Also, pwmout is best stopped with

pwmout 2 OFF

e
Ah, thanks for the tips. I focused all of my attention on thinking of ways to fix the simulation problem and not on possible snags in the program. I actually knew about the "OFF" command for PWM but figured it wouldn't make much difference setting the duty/period to 0. Good to know that OFF is the better solution.

In regards to the LDR variable - I never caught it. I have to figure out a solution for that as well. I arbitrarily chose ">50" as I don't know the appropriate value as I haven't prototyped it yet. Depending on the desired value, if the variable returns a value that's either below or above (depending on what's needed) it should not be counted.

Any solutions offered would be appreciated.

-mack
 
Last edited:

Technical

Technical Support
Staff member
1) run the program
2) hit the break button (second button down on simulation panel)
3) double click over LDR_Value to bring up the edit dialog, change value, click ok
4) click the break button again to continue

seems to work ok for us with your program.

Are you hitting the run/stop button instead (third button down). This completely stops, not pauses, the simulation. Therefore the chip 'resets' upon the next start - and as on a real device, all variable values are reset to 0.
 

mackingu

New Member
1) run the program
2) hit the break button (second button down on simulation panel)
3) double click over LDR_Value to bring up the edit dialog, change value, click ok
4) click the break button again to continue

seems to work ok for us with your program.

Are you hitting the run/stop button instead (third button down). This completely stops, not pauses, the simulation. Therefore the chip 'resets' upon the next start - and as on a real device, all variable values are reset to 0.
Bingo. That seems to have corrected the biggest of my problems. Thanks!
 
Top