Shop OBEX P1 Docs P2 Docs Learn Events
Help please! Where am I going wrong? — Parallax Forums

Help please! Where am I going wrong?

HughHugh Posts: 362
edited 2010-01-31 20:21 in Propeller 1
Sorry folks, another episode of me being as thick as two short planks...

I have a protoboard to which a Parallax 27977 LCD, three LEDs and three switches are attached. The LEDs and switches work (i.e., I can control whether the LEDs are on or off, and the switch monitoring is OK (I've displayed their state on the LCD))

All I want to do is monitor one of the switches and move between three states that I have named Mode1, Mode2 and (wait for it!) Mode3. The 'mode' switch increments the mode 1, 2, 3, 1, 2, etc., correctly, as shown by debugging to the LCD.

In each state there will be some similar code (setting the LED, adding a title and doing 'stuff' before returning to the main PUB to see if).

What is driving me mad? In the attached code I added a variable 'oldMode', the purpose being that when periodically checked, if the current value of 'Mode' didn't correlate with 'oldMode', the correct 'mode' code would be called and 'oldMode' would be updated.

i) Looking at 'oldMode' as printed to the LCD it toggles 0, 1, 255, 0, 1, 255, etc.,
ii) The code only works with a StackSW of 10 bytes: 10 Longs and it stops working; 20 bytes and it stops working;
iii) The LCD is soooooo s l o w and keeps tripping over itself. Even though I have added a wait period after the 'cls' procedure it only sometimes clears and writes in the top left hand corner of the LCD. Other times it just keeps concatenating the title text sent to it. The baud rate is correct and it is getting 5V; I have double-checked the constatnts in Serial_Lcd against the manual.
iv) Declaring an additional variable (even if it is not referenced in a PUB) changes the behaviour of the code.

I have been through the objects looking for similarly-named variables, there is oodles of variable-space...

Any suggestions would be gratefully received!

Thanks
Hugh

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-31 20:12
    For a start, stacks are long-aligned. You have to declare them as longs. What's probably happening is that MaxMode is being overwritten and, as you change MaxMode, it destroys the first stack location. 10 bytes is way too small for a stack and the Freq and oldMode variables are quickly being overwritten as well as other stuff following those variables in memory.

    I would start with a stack area declared as "long stackSW[noparse][[/noparse] 20 ]"
  • HughHugh Posts: 362
    edited 2010-01-31 20:21
    Thanks Mike, spot-on as usual.

    Starting a project from scratch I seem to forget previous lessons-learned!

    Thanks
    Hugh

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hugh - the thinking woman's Geoffrey Pyke.
Sign In or Register to comment.