Shop OBEX P1 Docs P2 Docs Learn Events
Need help with "Clunky Code" — Parallax Forums

Need help with "Clunky Code"

gc3076gc3076 Posts: 44
edited 2006-05-03 19:46 in BASIC Stamp
I have been working (on and off) on a project that used a serial out electronic inclinometer to calculate elevation. Stage two was to use a Grayhill 2-bit optical encoder to count the rotations of a large jack screw . The results of both routines are displayed real-time on a 2x16 serial LCD display. Each result having its own line on the display.

Each routine works fine on its own my problem exists during the merge. I seem to be missing optical encoder counts b/c the inclinometer takes too long to execute thus causing rotation count errors.

Could someone give me an option on this, it would be much appreciated.



GC3076

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-05-02 20:41
    It looks like your "EL:" routine 'falls through' into your "GetSpecTilt" code -- so you're calling it twice before the return.
  • gc3076gc3076 Posts: 44
    edited 2006-05-03 13:02
    hmmmm............· I don't see that ?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-05-03 13:30
    I think allanlane5 has it.
    gc3076, your DO...LOOP GOSUBs to "EL"; "EL" GOSUBs to "Get_Spec_Tilt", at the start, but "EL" does not have a RETURN following its SEROUT instruction, so it is proceeding to "Get_Spec_Tilt", as allanlane5 noted.
    
    
    DO
     [color=green]GOSUB EL
    [/color]  GOSUB AZ
     LOOP [color=green]EL:
    [/color] GOSUB Get_Spec_Tilt
     angle = angle * 10 ** 22446
     angle = angle - 7014
     SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]Line0, "EL  "]
     IF angle.BIT15 = 1 THEN
      SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]"-"]
     ELSE
      SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]" "]
     ENDIF
     SEROUT LcdPin, LcdBaudMode, [noparse][[/noparse]DEC2 ABS(angle) / 100,
                                 ".",
                                   DEC2 ABS(angle) // 100, 0]
    
     [color=red]RETURN   ' It seems you need THIS or it'll do another Get_Spec_Tilt (which immediately follows)[/color]
    
  • Shawn LoweShawn Lowe Posts: 635
    edited 2006-05-03 19:46
    Yep, PJ is right. If you don't want to do Get_spec_tilt twice you have to insert that return. Then your code sends the program to "AZ" then repeats

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    My last words shall be - "NOT YET!!!"
Sign In or Register to comment.