memory full error

regpye

New Member
I am building a simple circuit that consists of just a 08M2 chip and a momentary button on pinC.2
The idea is to press the button to go to the next label for doing a test.
The test is to find out the real value of a resistor in a ladder on C.1 and have that value read back on the computer screen.
I have written the code as I think it should be, but when I run it in simulation I get this error message that it is out of memory.
This is quite beyond me, I am not familiar enough to know why.

Code:
;    Function:  test ladder value  
;    Last Revision:
;    Target PICAXE:
; *******************************
Symbol Res_Ladder1= C.1
Symbol Ladder_Value = b0

Main:
button1:
if pinC.2 = 1 then button2
readadc Res_Ladder1,Ladder_Value ; read ADC Pin into Ladder Value  (variable b0)
sertxd("Value of button1 ADC is ",#Ladder_Value,13,10)  ; transmit to computer
pause 1800 ; short delay
goto button1

button2:
if pinC.2 = 1 then button3
readadc Res_Ladder1,Ladder_Value ; read ADC Pin into Ladder Value  (variable b0)
sertxd("Value of button2 ADC is ",#Ladder_Value,13,10)  ; transmit to computer
pause 1800 ; short delay
goto button2

button3:
if pinC.2 = 1 then button4
readadc Res_Ladder1,Ladder_Value ; read ADC Pin into Ladder Value  (variable b0)
sertxd("Value of button3 ADC is ",#Ladder_Value,13,10)  ; transmit to computer
pause 1800 ; short delay
goto button3

button4:
if pinC.2 = 1 then button5
readadc Res_Ladder1,Ladder_Value ; read ADC Pin into Ladder Value  (variable b0)
sertxd("Value of button4 ADC is ",#Ladder_Value,13,10)  ; transmit to computer
pause 1800 ; short delay
goto button4

button5:
if pinC.2 = 1 then button6
readadc Res_Ladder1,Ladder_Value ; read ADC Pin into Ladder Value  (variable b0)
sertxd("Value of button5 ADC is ",#Ladder_Value,13,10)  ; transmit to computer
pause 1800 ; short delay
goto button5

button6:
if pinC.2 = 1 then button7
readadc Res_Ladder1,Ladder_Value ; read ADC Pin into Ladder Value  (variable b0)
sertxd("Value of button6 ADC is ",#Ladder_Value,13,10)  ; transmit to computer
pause 1800 ; short delay
goto button6

button7:
if pinC.2 = 1 then button8
readadc Res_Ladder1,Ladder_Value ; read ADC Pin into Ladder Value  (variable b0)
sertxd("Value of button7 ADC is ",#Ladder_Value,13,10)  ; transmit to computer
pause 1800 ; short delay

button8:
readadc Res_Ladder1,Ladder_Value ; read ADC Pin into Ladder Value  (variable b0)
sertxd("Value of button8 ADC is ",#Ladder_Value,13,10)  ; transmit to computer
 
Last edited:

papaof2

Senior Member
Check the settings in the PICAXE Editor.

Your code will work on the 08M2 chip. It gives the "Out of memory" error message on the 08M chip. Which chip is selected?

If you shorten the quoted text, it would also work on an 08M: sertxd("bt1 ADC = ",#Ladder_Value,13,10)
 

regpye

New Member
Check the settings in the PICAXE Editor.
I changed the chip type and the memory error has gone, thanks.
Next problem, the code doesn't work correctly in simulation mode due to not having a momentary button press, unless it can be done with coding.
 

micrometal

New Member
The code DOES work correctly in simulation mode; the problem is that your logic is incorrect. Imagine that you are at the first loop, and the execution reaches this statement ...
Code:
button1:     if pinC.2 = 1 then goto button2
If C2 is high then the code execution will jump to this statement ...
Code:
button2:     if pinC.2 = 1 then goto button3
Unless you are very, very quick with your finger on the button then pinC.2 will still be high and the code will progress to 'button3' as directed. It is not just the way that the simulator works; real code works this way too.

After you have checked that pinC.2 is high then you need to wait until it is low again before going on to the next loop. Here is a suggestion ...
Code:
button1:     if pinC.2 = 1 then goto button1a
            ' Do your thing ...
            pause 1800
            goto button1
button1a:    if pinC.2 = 0 then goto button2    ' Wait until the button is released ...
            goto button1a
          
button2:    if pinC.2 = 1 then goto button2a
            ' Do your thing ...
            pause 1800
            goto button2
button2a:    if pinC.2 = 0 then goto button3
            goto button2a
          
button3:    ' and so on ..
 

hippy

Technical Support
Staff member
To ensure PE6 is set to the chip you are targetting when Syntax Checking, Compiling or Simulating you can add this to the top of your code, adjusted for whatever PICAXE you have -
Code:
#Picaxe 08M2
Handling stepping through execution of different things is more challenging and can be approached from a number of ways. I favour having a top-down approach with a nice clean and simple main loop so my starting code for stepping though four separate things would be ...
Code:
MainLoop:
  Do
    Do :  Gosub Option1  : Gosub CheckButton : Loop Until time_to_move_on = 1
    Do :  Gosub Option2  : Gosub CheckButton : Loop Until time_to_move_on = 1
    Do :  Gosub Option3  : Gosub CheckButton : Loop Until time_to_move_on = 1
    Do :  Gosub Option4  : Gosub CheckButton : Loop Until time_to_move_on = 1
  Loop
That's still too much clutter for me. I'd go for -
Code:
#Macro Execute( subroutineName )
  Do : Gosub subroutineName : Gosub CheckButton : Loop Until time_to_move_on = 1
#EndMacro

MainLoop:
  Do
    Execute( Option1 )
    Execute( Option2 )
    Execute( Option3 )
    Execute( Option4 )
  Loop
You can add as many 'Execute( OptionN )' as you want or need.

Then all you need to do is implement the 'CheckButton' routine and of course all the 'OptionN' routines - Episode 2 arriving shortly.
 

hippy

Technical Support
Staff member
Checking when it's time to move on is achieved by a 'CheckButton' routine which will set 'time_to_move_on' to 1 when it literally is time to move on to executing the next option, will set it to 0 if not.

First we need to define how your hardware is configured, which pin the button is on and what value it has when pushed. I have chosen a push makes it high here which suits simulation; the leg in the chip image is lit when pushed -
Code:
Symbol PUSH_BUTTON     = pinC.2
Symbol PUSHED          = 1
And we will also need to use some variables. One for 'time_to_move_on' and another which tracks the button state so we can tell when it has been pushed or released -
Code:
Symbol button_state    = b2
Symbol time_to_move_on = b3
Our 'CheckButton' routine simply sets 'time_to_move_on' to 1 when it is.

We set 'time_to_move_on' to 0 so we don't move on when we shouldn't and then check to see if we have had a new push which should set it.

If the button reading isn't the same as 'button_state' we know it has been pushed or released. We toggle 'button_state' between 0 and 1 to match what it now is, and then check if 'button_state matches the pushed level. If it does we set 'time_to_move_on' to 1. We add a short pause in there to debounce the button and job done.

Code:
CheckButton:
  time_to_move_on = 0
  If PUSH_BUTTON <> button_state Then
    button_state = button_state ^ 1
    If button_state = PUSHED Then
      time_to_move_on = 1
    End If
  End If
  Pause 10
  Return
Our code so far will be -
Code:
#Picaxe 08M2

Symbol PUSH_BUTTON     = pinC.2
Symbol PUSHED          = 1

Symbol button_state    = b2
Symbol time_to_move_on = b3

#Macro Execute( subroutineName )
  Do : Gosub subroutineName : Gosub CheckButton : Loop Until time_to_move_on = 1
#EndMacro

MainLoop:
  Do
    Execute( Option1 )
    Execute( Option2 )
    Execute( Option3 )
    Execute( Option4 )
  Loop

CheckButton:
  time_to_move_on = 0
  If PUSH_BUTTON <> button_state Then
    button_state = button_state ^ 1
    If button_state = PUSHED Then
      time_to_move_on = 1
    End If
  End If
  Pause 10
  Return

Option1:
  Return

Option2:
  Return

Option3:
  Return

Option4:
  Return
If you simulate that you will see it running through 'Execute( Option1 )' and 'Option1:' until C.2 is set high. It will then move on to the next option. On to the next when C.2 is set low and then set high again.
 

regpye

New Member
Thanks Hippy, when I get back home I will try that out. Nothing is ever as simple as it first seems
 
Top