Question about code snippet for standard hex

Hello,

I’m curious why there is a need to set two constants to define one pin. Could you not just assign a servo to a particular pin such as FRHH con “8”, instead of FRHH con “0” then FRHH con “8”. The code example is below for the hexapod:

[code]RRHH con “0” ;Rear Right leg : Hip Horizontal : pin 0
RRHH2 con “0”
RRHV con “0” ;Rear Right leg : Hip Vertical : pin 1
RRHV2 con “1”
RRK con “0” ;Rear Right leg : Knee : pin 2
RRK2 con “2”

MRHH con “0” ;Middle Right leg : Hip Horizontal : pin 4
MRHH2 con “4”
MRHV con “0” ;Middle Right leg : Hip Vertical : pin 5
MRHV2 con “5”
MRK con “0” ;Middle Right leg : Knee : pin 6
MRK2 con “6”

FRHH con “0” ;Front Right leg : Hip Horizontal : pin 8
FRHH2 con “8”
FRHV con “0” ;Front Right leg : Hip Vertical : pin 9
FRHV2 con “9”
FRK con “1” ;Front Right leg : Knee : pin 10
FRK2 con “0”

RLHH con “1” ;Rear Left leg : Hip Horizontal : pin 16
RLHH2 con “6”
RLHV con “1” ;Rear Left leg : Hip Vertical : pin 17
RLHV2 con “7”
RLK con “1” ;Rear Left leg : Knee : pin 18
RLK2 con “8”

MLHH con “2” ;Middle Left leg : Hip Horizontal : pin 20
MLHH2 con “0”
MLHV con “2” ;Middle Left leg : Hip Vertical : pin 21
MLHV2 con “1”
MLK con “2” ;Middle Left leg : Knee : pin 22
MLK2 con “2”

FLHH con “2” ;Front Left leg : Hip Horizontal : pin 24
FLHH2 con “4”
FLHV con “2” ;Front Left leg : Hip Vertical : pin 25
FLHV2 con “5”
FLK con “2” ;Front Left leg : Knee : pin 26
FLK2 con "6[/code]

supposedly it saved space.

Alan KM6VV

You obviously could do this several different ways. Obviously you could simply do it with one if your pin number is less than 10. Personally I doubt it saves space, but it might be a hair faster than doing the conversion.
To verify the space, I had a simple program:

bar var long
dpin con 10
DP1	con	"1"
DP2 con "2"
serout s_out, i9600, [DP1, DP2, dec dpin]

If yo ulook at the generated assembly language you will find:

... .stabs "0 7 0",32,0,0,_DEBUGLABEL0 .word _CONPCMD .long 0x21 ;S_OUT .word _CLRWPCMD .word _CONPCMD .long 0x40d0 ;I9600 .word _CLRWP3CMD .word _CONSTROUTCMD .word _SEROUTFUNCCMD .long 0x2 ;COUNT .long 0x31 ;DP1 .long 0x32 ;DP2 .word _CONCMD .long 0xa ;DPIN .word _DECOUTCMD .long 0xa ;FLAG .word _SEROUTFUNCCMD ...
So you will see that for each character you output, it is actually passed as a LONG (4 bytes). As for doing a decimal it looks like it passed a WORD, a Long and a word, so again 8 bytes. But: the code did not have to take the time to do the Decimal to Ascii conversion…

Kurt

Anytime I ever find something that looks more complicated than it needs to be, there is always an underlying reason. :wink: