Shop OBEX P1 Docs P2 Docs Learn Events
__PARAMCNT or __PARAMn value corrupted on user defined function — Parallax Forums

__PARAMCNT or __PARAMn value corrupted on user defined function

slcottslcott Posts: 27
edited 2010-01-02 16:55 in General Discussion
I am trying to use my micromega fpu. My hardware is setup and I have established communication with the fpu. Unfortunately, I have a problem using either a subroutine or a function to write to the fpu inside of my main loop. It seems that either my __PARAMn values or __PARAMCNT gets corrupted somehow because my sx fpu function leaves out the ARG and only passes an OPCODE to the FPU. Has anyone had experience with user defined functions going haywire like this.

Post Edited (slcott) : 12/30/2009 1:44:59 AM GMT
692 x 926 - 31K
692 x 926 - 30K

Comments

  • BeanBean Posts: 8,129
    edited 2009-12-30 12:13
    SX/B code will re-use the _PARAMx variables.
    It looks like you ARE copying them to other variables, so it should work.
    If you could post the whole program we could help more.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    PropBASIC home page www.propbasic.com
    ·
  • slcottslcott Posts: 27
    edited 2010-01-02 02:24
    i tried converting all the subroutines to functions instead with no effect. i also tried calling Fpu_SPI_Write only which works on a single argument at a time which serves as a workaround, but I would like full use of my fpu.SXB functions for ease of further development. When I call Fpu_Write with 2 or more arguments, the 2nd and following arguments are reported by my fpu as 0. I think the prob is in the microcontroller.
  • ZootZoot Posts: 2,227
    edited 2010-01-02 16:55
    It's not the microcontroller, trust us. There may be a number of problems with your code that are clobbering your param registers. I also found several logic errors that would certainly lead to weird results, for example:

    FUNC Fpu_Write
      tmp1 = __PARAM1
      if __PARAMCNT = 1 then
        Fpu_SPI_Write tmp1
      else
        tmpCnt = __PARAMCNT
        tmp2 = __PARAM2
        tmp3 = __PARAM3
        tmp4 = __PARAM4
        Fpu_SPI_Write tmp1
        Fpu_SPI_Write tmp2
        if tmpcnt < 3 then Fpu_Write2
        Fpu_SPI_Write tmp3
        if tmpcnt < 4 then Fpu_Write2
        Fpu_SPI_Write tmp4
      endif
      Fpu_Write2
      return
    ENDFUNC
    
    FUNC Fpu_Write2
      return
    ENDFUNC
    
    



    In the above, the line "if tmpcnt < 3 then FPU_Write2" will NOT call the function, it will GOTO the function, then return, without executing following code. You may want to break some of your code into very small testable piece and make sure each piece is OK before working the pieces into a larger program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.