beginners question
Olli
Posts: 7
Hi everybody... just startet with Spin and Propeller, so iam what u call " dumbest assumable user" or just a DAU....
My first question is about "cnt" register.
every clock cycle 1 is added to "cnt" and cnt is a 32bit register... so maximum counting value should be 2^32 = 4_294_967_296 minus 1
at a clock speed of 80MHz it should be round about 53 seconds before overflow. Is that correct so far ?
So I defined a variable "temp" as long
and used the following: temp:=cnt
when I now want to display that value via Video I used Jeff Martins object "Numbers v1.0" to convert long to string
"Num.ToStr(temp,NUM#DEC11)"
but now I get a value diplayed from 0 to +2_147_483_647 then to -2_147_483_648 and up to 0 again. Its a singned value now.
Is a long variable now from 0 to 4_294_967_295 or from -2_147_483_648 to +2_147_483_647
I hope someone understands where my beginners problem is.
Now to my second question:
Its from the Propeller manual page 324 , 325 using waitcnt
There are two ways described to toggle an output pin. one called "Fixed delay" and one called "synchonized Delays"
page 324
PUB Toggle | Time
Time := cnt
repeat
waitcnt(Time += 50_000)
!outa[noparse][[/noparse]0]
refering to listing on page 324, it compensates the runtime error for executing the code between
Time := cnt and the waitcnt command. thats ok for me,
but now they say: " This method automatically compensates for the overhead time consumed by the loop statements: repeat, !outa[noparse][[/noparse]0] and waitcnt.
see Figure 4-2:
but toggling !outa[noparse][[/noparse]0] is after the waitcnt command. And every action takes some (time) clock cycles. So how I understand it, the first toggling of P0
is 10ms + executing time of !outa[noparse][[/noparse]0]. All following are syncron to the first, but all with that little offset for executing !outa[noparse][[/noparse]0].
Is it correct ?
My first question is about "cnt" register.
every clock cycle 1 is added to "cnt" and cnt is a 32bit register... so maximum counting value should be 2^32 = 4_294_967_296 minus 1
at a clock speed of 80MHz it should be round about 53 seconds before overflow. Is that correct so far ?
So I defined a variable "temp" as long
and used the following: temp:=cnt
when I now want to display that value via Video I used Jeff Martins object "Numbers v1.0" to convert long to string
"Num.ToStr(temp,NUM#DEC11)"
but now I get a value diplayed from 0 to +2_147_483_647 then to -2_147_483_648 and up to 0 again. Its a singned value now.
Is a long variable now from 0 to 4_294_967_295 or from -2_147_483_648 to +2_147_483_647
I hope someone understands where my beginners problem is.
Now to my second question:
Its from the Propeller manual page 324 , 325 using waitcnt
There are two ways described to toggle an output pin. one called "Fixed delay" and one called "synchonized Delays"
page 324
PUB Toggle | Time
Time := cnt
repeat
waitcnt(Time += 50_000)
!outa[noparse][[/noparse]0]
refering to listing on page 324, it compensates the runtime error for executing the code between
Time := cnt and the waitcnt command. thats ok for me,
but now they say: " This method automatically compensates for the overhead time consumed by the loop statements: repeat, !outa[noparse][[/noparse]0] and waitcnt.
see Figure 4-2:
but toggling !outa[noparse][[/noparse]0] is after the waitcnt command. And every action takes some (time) clock cycles. So how I understand it, the first toggling of P0
is 10ms + executing time of !outa[noparse][[/noparse]0]. All following are syncron to the first, but all with that little offset for executing !outa[noparse][[/noparse]0].
Is it correct ?
Comments
"waitcnt(desired wait + cnt), always put cnt at end or you take a chance of having to wait the extra 53 secs for cnt to rollover.
ex: 1 sec wait = waitcnt(clkfreq+cnt)· Use clkfreq since it can change depending on pll and osc freq.
···· 1/2 sec· waitcnt(clkfreq/2+cnt)
··· 3 sec wait= waitcnt(clkfreq*3+cnt)
if you want to wait a small time = waitcnt(50_000+cnt) wait 50,000 clock cyles.
Hope this helps a little.
·As for your first question, I'm not sure what it really is? The cnt does some strange stuff. There are a few ways to use it depending on what you want but what it's actuall value is in unimportant.
··························
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
2) The time delay depends on the system clock frequency. On page 324, the clock frequency is set to 5MHz so 50_000 clock ticks would indeed be 10ms. You're correct that there's a little delay after the WAITCNT for the WAITCNT statement to finish and the !OUTA[noparse][[/noparse] 0 ] to execute. It is a fixed delay and can be measured and compensated for if necessary.
that answers just helped me a lot. Hit the nail on the top. Thanx
I ´ll experiment a bit with singned an unsigned values to see what happens...
ok.... the little delay for toggling port[noparse][[/noparse]0] after the waitcnt is now clear too.
have a nice day
by the way... Propeller chip is an interesting piece of hardware... thanx to Chip and his Crew !
and community is growing... nice
Greetings from Germany
A sequence of bits means what the programmer needs it to mean.· It's all about context and requirements.
32 bits could be an unsigned integer with the range 0 - (2^32)-1, or a signed integer with the range -(2^31) - (2^31)-1, or a string of 4 characters, a set of 4 bytes, or a 32 bit bitfield, or a 16.16 fixed point number, or a 24e8 floating point number, or a 32 bit address, or an opcode, or ....
Higher level languages (like Spin) have conventions on what a certain variable may contain (called typing), and may have ways of implicitly or explicitly converting between the different meanings.· But when you get down & dirty at the assembly level those conventions disappear and you're left with how the opcodes use and affect the data and condition codes.·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: http://forums.parallax.com/showthread.php?p=800114
After some testing with Spin I was wondering ....
is spin really so slow ?
just testet a prog toggling only one port to see maximum performance.
!outa[noparse][[/noparse]0]
!outa[noparse][[/noparse]0]
and the frequency on pin 0 was round about 40Khz, operating at xtal 5MHz and plllx16 so clock is 80MHz.
can that be true ? If so.... isnt then Spin a bottleneck for operating that propeller ?
SPIN has been designed to provide a programming language for all the non-timecritical things in your program. For example, if you deal with user input it's not timecritical - if you poll some sensors that don't change data rapidly - managing all the COGs - doing screen output (I don't mean the video driver itself) .....
SPIN produces compact code compared to PASM, as it is transformed into bytecode.
But that's nothing new with the propeller. High-level languages in general are slower than native machine-code because the goal is different. High-level languages provide instructions/structures that allow programming to be more sophisticated and/or easier than in an assembler language.
If you need highspeed there is no other way than using PASM instead of SPIN. C on the propeller is somewhere in the middle, but needs more memory than SPIN and is still slower than PASM.
Post Edited (MagIO2) : 4/27/2009 9:56:42 AM GMT
So if I need something timecritical PASM is the way to go.
Is there any PASM beginners guide ?
never wrote one line in ASM before.
alredy found in forum: "Assembly, step by step" by Graham Stabler, but is there maybe something easier ?
like the "Propeller Manual" thats with the demo board, but with prefernece on PASM ?
thanx
Post Edited (Olli) : 4/27/2009 4:05:25 PM GMT