Dennis B. Page
05-12-2008, 04:43 AM
Servo32v3 move some servos unexpectedly with when used with my code. My code is very complex so I created a simple demo of the problem (see Figure 1). I modified Servo32v3 to return pointers to variables used by Servo32v3 so the demo can output the pointers and contents to the PC (see Figure 2 for the output, and the attachment for the modified Servo32v3 code).
Figure 2 shows that one pointer, ZoneClocks, shares one of the ServoData array memory location. Some ServoData array memory locations are filled with unexpected data. ServoData memory locations 0 through 18 should be filled with "$1D4C0" except for servo 12, which should be "$13880." You'll also notice that PanServo 12 is at memory location ServoData[18]. What's up with this?
When I use Servo32v3 with my code, I find that variables in other procedures, which should be completely separate, share Servo32v3 memory locations, causing servos to move unexpectedly.
I can't figure out what is wrong. Is the bug in my demo, Servo32v3 or the compiler? Your feedback will be appreciated.
Figure 1:
{{
Servo32v3 Conflict Demo based on Servo32_v3 Demo v1.3
Written 11 May 2008 by Dennis B. Page
- May connect a servo to PanServo pin (optional)
- Open a terminal to see results
*****************************************
* Servo32_v3 Demo v1.3 *
* Author: Beau Schwabe *
* Copyright (c) 2007 Parallax *
* See end of file for terms of use. *
*****************************************
}}
CON
_clkmode = xtal1 + pll8x 'Set for SS1 Spin Stamp 1
_xinfreq = 10_000_000 'Note Clock Speed for your setup!!
PanServo = 12 'Select DEMO servo to pan
VAR
long ServoDataPtr
long ZoneClocksPtr
long I
OBJ
SERVO : "Servo32v3 Modified" 'Modified to return pointers
debug : "Simple_Serial"
num : "Numbers"
PUB Main
debug.start(31, 30, 9600)
num.init
debug.str(string(13,10,13,10,"Servo32v3 Conflict",13,10))
debug.str(string("Variable Pointer Data",13,10))
repeat I from 0 to 19 'preset ALL servos to center position
SERVO.Set(I,1500)
SERVO.Start(ServoDataPtr,ZoneClocksPtr) 'start servo handler
debug.str(string("ZoneClocks ")) 'send pointers and contents to PC
debug.str(num.ToStr(@ZoneClocksPtr,%11_000_000_0_0 _001010_10000)) '8 hex digits zero padded
debug.tx(" ")
debug.str(num.ToStr(ZoneClocksPtr,%11_000_000_0_0_ 001010_10000)) '8 hex digits zero padded
debug.tx(13)
debug.tx(10)
debug.str(string("ServoData "))
debug.str(num.ToStr(@ServoDataPtr,%11_000_000_0_0_ 001010_10000)) '8 hex digits zero padded
debug.tx(" ")
debug.str(num.ToStr(ServoDataPtr,%11_000_000_0_0_0 01010_10000)) '8 hex digits zero padded
debug.tx(13)
debug.tx(10)
repeat I from 1000 to 2000 'sweep PanServo back and forth once
waitcnt(cnt+40_000) 'control ramp rate
SERVO.Set(PanServo,I)
repeat I from 2000 to 1000
waitcnt(cnt+40_000)
SERVO.Set(PanServo,I)
repeat I from 0 to 19 'send pointers and contents to PC
waitcnt(clkfreq/10000 + cnt) 'wait a few moments
debug.str(string("Servo Data "))
debug.str(num.ToStr(I,%11_00000+%1010)) '2 decimal digits zero padded
debug.str(num.ToStr(@ServoDataPtr+I,%11_000_000_0_ 0_001010_10000)) '8 hex digits zero padded
debug.tx(" ")
debug.str(num.ToStr(ServoDataPtr,%11_000_000_0_0_0 01010_10000)) '8 hex digits zero padded
debug.tx(13)
debug.tx(10)
waitcnt(clkfreq/4 + cnt) 'allow time for PC to display everything before shutdown
{{
┌───────────────────────────────────────────────── ────────────────────────────────────────────────── ───────────────────────────┐
│ TERMS OF USE: MIT License │
├───────────────────────────────────────────────── ────────────────────────────────────────────────── ───────────────────────────┤
│Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │
│files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │
│modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
│is furnished to do so, subject to the following conditions: │
│ │
│The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
│ │
│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │
│WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │
│COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
│ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
└───────────────────────────────────────────────── ────────────────────────────────────────────────── ───────────────────────────┘
}}
Figure 2 Output:
Servo32v3 Conflict
Variable Pointer Data
ZoneClocks $000006DC $00000000
ServoData $000006D8 $00000000
ServoData 00 $000006D8 $00000000
ServoData 01 $000006D9 $00000000
ServoData 02 $000006DA $00000002
ServoData 03 $000006DB $00061A80
ServoData 04 $000006DC -$00030D41 <- ZoneClocks
ServoData 05 $000006DD $400FFFFF
ServoData 06 $000006DE $0001D4C0
ServoData 07 $000006DF $0001D4C0
ServoData 08 $000006E0 $0001D4C0
ServoData 09 $000006E1 $0001D4C0
ServoData 10 $000006E2 $0001D4C0
ServoData 11 $000006E3 $0001D4C0
ServoData 12 $000006E4 $0001D4C0
ServoData 13 $000006E5 $0001D4C0
ServoData 14 $000006E6 $0001D4C0
ServoData 15 $000006E7 $0001D4C0
ServoData 16 $000006E8 $0001D4C0
ServoData 17 $000006E9 $0001D4C0
ServoData 18 $000006EA $00013880 <- Servo 12
ServoData 19 $000006EB $0001D4C0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dennis B. Page, Page Radio Company
Post Edited (Dennis B. Page, Page Radio Company) : 5/12/2008 12:46:16 AM GMT
Figure 2 shows that one pointer, ZoneClocks, shares one of the ServoData array memory location. Some ServoData array memory locations are filled with unexpected data. ServoData memory locations 0 through 18 should be filled with "$1D4C0" except for servo 12, which should be "$13880." You'll also notice that PanServo 12 is at memory location ServoData[18]. What's up with this?
When I use Servo32v3 with my code, I find that variables in other procedures, which should be completely separate, share Servo32v3 memory locations, causing servos to move unexpectedly.
I can't figure out what is wrong. Is the bug in my demo, Servo32v3 or the compiler? Your feedback will be appreciated.
Figure 1:
{{
Servo32v3 Conflict Demo based on Servo32_v3 Demo v1.3
Written 11 May 2008 by Dennis B. Page
- May connect a servo to PanServo pin (optional)
- Open a terminal to see results
*****************************************
* Servo32_v3 Demo v1.3 *
* Author: Beau Schwabe *
* Copyright (c) 2007 Parallax *
* See end of file for terms of use. *
*****************************************
}}
CON
_clkmode = xtal1 + pll8x 'Set for SS1 Spin Stamp 1
_xinfreq = 10_000_000 'Note Clock Speed for your setup!!
PanServo = 12 'Select DEMO servo to pan
VAR
long ServoDataPtr
long ZoneClocksPtr
long I
OBJ
SERVO : "Servo32v3 Modified" 'Modified to return pointers
debug : "Simple_Serial"
num : "Numbers"
PUB Main
debug.start(31, 30, 9600)
num.init
debug.str(string(13,10,13,10,"Servo32v3 Conflict",13,10))
debug.str(string("Variable Pointer Data",13,10))
repeat I from 0 to 19 'preset ALL servos to center position
SERVO.Set(I,1500)
SERVO.Start(ServoDataPtr,ZoneClocksPtr) 'start servo handler
debug.str(string("ZoneClocks ")) 'send pointers and contents to PC
debug.str(num.ToStr(@ZoneClocksPtr,%11_000_000_0_0 _001010_10000)) '8 hex digits zero padded
debug.tx(" ")
debug.str(num.ToStr(ZoneClocksPtr,%11_000_000_0_0_ 001010_10000)) '8 hex digits zero padded
debug.tx(13)
debug.tx(10)
debug.str(string("ServoData "))
debug.str(num.ToStr(@ServoDataPtr,%11_000_000_0_0_ 001010_10000)) '8 hex digits zero padded
debug.tx(" ")
debug.str(num.ToStr(ServoDataPtr,%11_000_000_0_0_0 01010_10000)) '8 hex digits zero padded
debug.tx(13)
debug.tx(10)
repeat I from 1000 to 2000 'sweep PanServo back and forth once
waitcnt(cnt+40_000) 'control ramp rate
SERVO.Set(PanServo,I)
repeat I from 2000 to 1000
waitcnt(cnt+40_000)
SERVO.Set(PanServo,I)
repeat I from 0 to 19 'send pointers and contents to PC
waitcnt(clkfreq/10000 + cnt) 'wait a few moments
debug.str(string("Servo Data "))
debug.str(num.ToStr(I,%11_00000+%1010)) '2 decimal digits zero padded
debug.str(num.ToStr(@ServoDataPtr+I,%11_000_000_0_ 0_001010_10000)) '8 hex digits zero padded
debug.tx(" ")
debug.str(num.ToStr(ServoDataPtr,%11_000_000_0_0_0 01010_10000)) '8 hex digits zero padded
debug.tx(13)
debug.tx(10)
waitcnt(clkfreq/4 + cnt) 'allow time for PC to display everything before shutdown
{{
┌───────────────────────────────────────────────── ────────────────────────────────────────────────── ───────────────────────────┐
│ TERMS OF USE: MIT License │
├───────────────────────────────────────────────── ────────────────────────────────────────────────── ───────────────────────────┤
│Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │
│files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │
│modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
│is furnished to do so, subject to the following conditions: │
│ │
│The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
│ │
│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │
│WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │
│COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
│ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
└───────────────────────────────────────────────── ────────────────────────────────────────────────── ───────────────────────────┘
}}
Figure 2 Output:
Servo32v3 Conflict
Variable Pointer Data
ZoneClocks $000006DC $00000000
ServoData $000006D8 $00000000
ServoData 00 $000006D8 $00000000
ServoData 01 $000006D9 $00000000
ServoData 02 $000006DA $00000002
ServoData 03 $000006DB $00061A80
ServoData 04 $000006DC -$00030D41 <- ZoneClocks
ServoData 05 $000006DD $400FFFFF
ServoData 06 $000006DE $0001D4C0
ServoData 07 $000006DF $0001D4C0
ServoData 08 $000006E0 $0001D4C0
ServoData 09 $000006E1 $0001D4C0
ServoData 10 $000006E2 $0001D4C0
ServoData 11 $000006E3 $0001D4C0
ServoData 12 $000006E4 $0001D4C0
ServoData 13 $000006E5 $0001D4C0
ServoData 14 $000006E6 $0001D4C0
ServoData 15 $000006E7 $0001D4C0
ServoData 16 $000006E8 $0001D4C0
ServoData 17 $000006E9 $0001D4C0
ServoData 18 $000006EA $00013880 <- Servo 12
ServoData 19 $000006EB $0001D4C0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dennis B. Page, Page Radio Company
Post Edited (Dennis B. Page, Page Radio Company) : 5/12/2008 12:46:16 AM GMT