Shop OBEX P1 Docs P2 Docs Learn Events
how to get around the 15 parameter error — Parallax Forums

how to get around the 15 parameter error

KeyBoardKeyBoard Posts: 22
edited 2013-05-25 10:09 in Propeller 1
Hello, I have been trying to update my 3dof quad program recently so that it can easier to calibrate the servos when I get better ones and I ran into a problem, that is I need to pass the pin values and servo offsets for all the servos (a parameter count of 24) to another object and there is a limet of 15 that I can pass is there any way that I can get around this or am I doomed. kind regards.

Comments

  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-05-25 09:44
    When I have more than 5 parameters I pass the address of a block of values in a DAT section:
    object.start(@ParameterList)
    


    With the list built like this:
    dat
    
      ParameterList         byte    1, 2, 3, 4, 5, 6
    


    Of course, the code in the .start method needs to know how to deal with the list, but that's easy:
    pub start(p_params)
    
      pinX := byte[p_params][0]
      pinY := byte[p_params][1]
    
  • KeyBoardKeyBoard Posts: 22
    edited 2013-05-25 09:45
    thanks I will try that
  • Mike GreenMike Green Posts: 23,101
    edited 2013-05-25 10:09
    Since parameters are always long values and I/O pin numbers are a byte or less, I've sometimes passed them packed together in a long. This works particularly well when the pin numbers are defined as constants in the main object. You can get six pin numbers in one long value this way like this:
    CON pinA = 5
        pinB = 8
        pinC = 10
        pinD = 15
        pinE = 21
        pinF = 25
        allPins = pinA<<25 | pinB<<20 | pinC<<15 | pinD<<10 | pinE<<5 | pinF
    
    You'd pass allPins to your start method and unpack it in a loop like this:
    pub start( myPins) | i, pins[6]
       repeat i from 0 to 5
          pins[ i ] := (myPins >> (25 - i*5)) & 31
    
    This is not a particularly efficient way to do this, but it will work and illustrates the technique.
Sign In or Register to comment.