Phil Pilgrim (PhiPi)
01-11-2009, 02:49 PM
A question came up in a different thread about why Spin programs draw more current than assembly programs (according to the graphs in the datasheet). One hypothesis had it that it was because the interpreter was always busy with hub interactions. I hypothesized that because of the hub interactions (and consequent idles waiting for the hub) that Spin programs should consume less current, not more, than non-hub-interacting assembly programs. So I decided to see for myself.
The Propeller Demo Board has a handy jumper that can be removed that breaks the Vdd connection for hooking up an ammeter (or low-ohmic resistor and voltmeter). Here are the programs I tried, along with their Vdd current draw, as measured on the Demo Board:
A. Spin loop only (14.2mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
repeat
B. Assembly loop only (10.1mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
DAT
loop jmp #loop
C. Assembly loop with RDLONG from RAM (10.1mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
DAT
loop rdlong x,addr
jmp #loop
addr long $1000
x res 1
D. Assembly loop with RDLONG from ROM (10.7mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
DAT
loop rdlong x,addr
jmp #loop
addr long $8000
x res 1
E. Assembly loop with RDLONG from ROM + NOP (13.4mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
DAT
loop rdlong x,addr
nop
jmp #loop
addr long $8000
x res 1
Observations so far:
····1. Assembly programs require less current than Spin programs, confirming the datasheet.
····2. It takes more current to read from RAM than from ROM.
····3. Programs that hit the hub "sweet spot" (E) require more current than programs that wait for hub access (D).
····4. Programs that hit the hub "sweet spot" (E) require more current than programs that don't access the hub (B).
Now I know Chip writes some amazingly tight code. But how can his interpreter draw more current than an assembly loop that hits the hub sweet spot every time (reading from ROM, no less)?
This required more testing. Maybe some instructions require more current than others. After all, NOPs and JMPs are pretty much "free" instructions, effortwise. So I added an ADD to the loop in B. Aha!
F. Assembly loop + ADD (15.1mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
'cognew(@loop, 0)
DAT
loop add x,#0
jmp #loop
addr long $8000
x res 1
G. Assembly loop with RDLONG from ROM + ADD (14.3mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
'cognew(@loop, 0)
DAT
loop rdlong x,addr
add x,#0
jmp #loop
addr long $8000
x res 1
Conclusions:
Okay, now we're comparing apples with apples and can revise a couple observations:
····1. Assembly programs require less current than Spin programs, confirming the datasheet. See #5.
····2. It takes more current to read from RAM than from ROM.
····3. Programs that hit the hub "sweet spot" (E) require more current than programs that wait for hub access (D).
····4. Programs that hit the hub "sweet spot" (E) require more current than programs that don't access the hub (B). See #6.
····5. Realistic assembly programs require just as much current as Spin programs, if not more.
····6. Hub accesses decrease the average current requirements due to the waiting time (even the single-cycle wait when hitting the "sweet spot").
So there you have it. It all makes sense now, at least to me. I think the datasheet is a little misleading in this regard, since it gives the impression that Spin programs are more current-consumptive than assembly programs. But this is only because the example program (JMP only) cited is not doing any real work, whereas the Spin interpreter is. So the difference, it turns out, has little to do with hub accesses.
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 1/11/2009 9:10:05 AM GMT
The Propeller Demo Board has a handy jumper that can be removed that breaks the Vdd connection for hooking up an ammeter (or low-ohmic resistor and voltmeter). Here are the programs I tried, along with their Vdd current draw, as measured on the Demo Board:
A. Spin loop only (14.2mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
repeat
B. Assembly loop only (10.1mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
DAT
loop jmp #loop
C. Assembly loop with RDLONG from RAM (10.1mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
DAT
loop rdlong x,addr
jmp #loop
addr long $1000
x res 1
D. Assembly loop with RDLONG from ROM (10.7mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
DAT
loop rdlong x,addr
jmp #loop
addr long $8000
x res 1
E. Assembly loop with RDLONG from ROM + NOP (13.4mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
DAT
loop rdlong x,addr
nop
jmp #loop
addr long $8000
x res 1
Observations so far:
····1. Assembly programs require less current than Spin programs, confirming the datasheet.
····2. It takes more current to read from RAM than from ROM.
····3. Programs that hit the hub "sweet spot" (E) require more current than programs that wait for hub access (D).
····4. Programs that hit the hub "sweet spot" (E) require more current than programs that don't access the hub (B).
Now I know Chip writes some amazingly tight code. But how can his interpreter draw more current than an assembly loop that hits the hub sweet spot every time (reading from ROM, no less)?
This required more testing. Maybe some instructions require more current than others. After all, NOPs and JMPs are pretty much "free" instructions, effortwise. So I added an ADD to the loop in B. Aha!
F. Assembly loop + ADD (15.1mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
'cognew(@loop, 0)
DAT
loop add x,#0
jmp #loop
addr long $8000
x res 1
G. Assembly loop with RDLONG from ROM + ADD (14.3mA)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main
cognew(@loop, 0)
'cognew(@loop, 0)
DAT
loop rdlong x,addr
add x,#0
jmp #loop
addr long $8000
x res 1
Conclusions:
Okay, now we're comparing apples with apples and can revise a couple observations:
····1. Assembly programs require less current than Spin programs, confirming the datasheet. See #5.
····2. It takes more current to read from RAM than from ROM.
····3. Programs that hit the hub "sweet spot" (E) require more current than programs that wait for hub access (D).
····4. Programs that hit the hub "sweet spot" (E) require more current than programs that don't access the hub (B). See #6.
····5. Realistic assembly programs require just as much current as Spin programs, if not more.
····6. Hub accesses decrease the average current requirements due to the waiting time (even the single-cycle wait when hitting the "sweet spot").
So there you have it. It all makes sense now, at least to me. I think the datasheet is a little misleading in this regard, since it gives the impression that Spin programs are more current-consumptive than assembly programs. But this is only because the example program (JMP only) cited is not doing any real work, whereas the Spin interpreter is. So the difference, it turns out, has little to do with hub accesses.
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 1/11/2009 9:10:05 AM GMT