Time "?" running 100Khz on a waitcnt
I am hitting my head against the wall trying to calculate the speed of this loop.
I want to run it around 100Khz for an IC. My prop is running at 80Mhz
My thinking is that I am running at [noparse][[/noparse] 80Mhz / 1000 = 80khz] = seconds at 12.5uS. Is this right?
So running at 100Khz I thought that I would change to this
Please inform me if I am making a mistake.
Thanks
I want to run it around 100Khz for an IC. My prop is running at 80Mhz
PUB ShiftIn (Dpin, Cpin, Mode, Bits) : Value | InBit
dira[noparse][[/noparse] Dpin ]~
outa[noparse][[/noparse] Cpin ]:=0
dira[noparse][[/noparse] Cpin ]~~
InBit~
Value:=0
REPEAT Bits
!outa[noparse][[/noparse] Cpin ]
!outa[noparse][[/noparse] Cpin ]
InBit:= ina[noparse][[/noparse] Dpin ]
Value := (Value << 1) + InBit
[b]waitcnt(1000 + cnt)[/b]
My thinking is that I am running at [noparse][[/noparse] 80Mhz / 1000 = 80khz] = seconds at 12.5uS. Is this right?
So running at 100Khz I thought that I would change to this
[b]waitcnt(800 + cnt)[/b]
Please inform me if I am making a mistake.
Thanks

Comments
You could time the critical section with something like this...
CON ''General Constants for Propeller Setup _CLKMODE = XTAL1 + PLL16X _XINFREQ = 5_000_000 OBJ ''Setup Object references that make this demo work Ser : "FullDuplexSerial" VAR long ClockStart long ClockStop long ClockDelta long maxtime long interval PUB Serial_DEMO Ser.start(31, 30, 0, 2400) ' Initialize serial communication to the PC repeat ClockStart := cnt ***YOUR CODE HERE*** ClockStop := cnt ClockDelta := ClockStop - ClockStart ClockDelta *= 125 ' Convert clock ticks to micro seconds ClockDelta /= 1000 ser.tx(1) ' Tell me what the value is through the serial port ser.dec(ClockDelta)Post Edited (Brian Fairchild) : 4/27/2009 4:36:24 PM GMT
you forget that both assignments need some time as well.
Before starting the loop you should do a measurement without any code in between and subtract that from the measurements later on.
ClockStart:=cnt
ClockEnd:=cnt
MeasurementRuntime:=ClockEnd-ClockStart
@Zap-o:
Just remove the waitcnt and see how fast it is then.That's closest you can get to 100kHz using SPIN.
You should remove the InBit. It's an additional assignment which only consumes time.