cog problem... but code seems right
sov
Posts: 17
hello, I have been doing a contest with my school for some time. But since it has been a couple months since I have really worked on propeller I am having trouble with the cognew command or any other cog command. With the code I put within this post seems right to me, but every time I try it out the cog command would fail. Is it because I have a 6.25 mhz crystal instead of a 5mhz crystal (6.25 mhz makes propeller run at 100mhz) or is it a silly mistake that I can not figure out, thank you in advance!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
iPhone expert
con _clkmode = xtal1 + pll16x _xinfreq = 6_250_000 obj debug : "FullDuplexSerial" var long microseconds, stack[noparse][[/noparse]10],success pub start debug.start(31,30,0,57600) dira~~ repeat success := (cognew(ticks(0),@stack[noparse][[/noparse]10])) if success > 0 outa~ if success == -1 outa~~ debug.dec(success) PUB Ticks(Pin) | cnt1, cnt2 ''Return Ping)))'s one-way ultrasonic travel time in microseconds repeat outa[noparse][[/noparse]Pin]~ ' Clear I/O Pin dira[noparse][[/noparse]Pin]~~ ' Make Pin Output outa[noparse][[/noparse]Pin]~~ ' Set I/O Pin outa[noparse][[/noparse]Pin]~ ' Clear I/O Pin (> 2 µs pulse) dira[noparse][[/noparse]Pin]~ ' Make I/O Pin Input waitpne(0, |< Pin, 0) ' Wait For Pin To Go HIGH cnt1 := cnt ' Store Current Counter Value waitpeq(0, |< Pin, 0) ' Wait For Pin To Go LOW cnt2 := cnt ' Store New Counter Value Microseconds := (||(cnt1 - cnt2) / (clkfreq / 1_000_000)) >> 1
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
iPhone expert
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
iPhone expert
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Some of my objects:
MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
@stack[noparse][[/noparse]10]? - That seems wrong.
Also, your code seems to just launch a bunch of cogs using the same I/O pin until it runs out of them.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
COGNEW is only the instruction to trigger the start of a new COG. It takes 512 HUB-cycles until the COG is completely loaded (with another SPIN-interpreter in your case). BUT ... the COGNEW immediately returns to your main-loop. So, the variable success will be 0 when you read it first.
The second parameter of the COGNEW is the start of the stackspace that the additional SPIN-interpreter shall use. @stack[noparse][[/noparse]10] is pointing to the first long AFTER the array stack. But in SPIN the stack grows bottom-up whereas in other systems the stack grows top-down - maybe that's why you thought it's right this way.
Whether SPIN is fast enough to measure the travel-time of a ultrasonic signal I don't know. But is this code right at all? You are not interested in the high-time of the signal. You are interested in the time it took between sending and receiving. But I have to admit that I don't know the PING and might be wrong here.