Discussion forum for the BasicX family of microcontroller chips.
|
Hi, I am posting this for my 14year old son who is wanting to multitask a servo movement while reading a TSL230 current to frequency photodiode. He had progressed from having the read and print.debug working well on Com1 as a non-multitasking process but once he added in the first part of the multitasking he cannot get the conversion to string function working. In the code below the program appears to work until it gets to the Cstr function. The "checkpoint 1" prints out but then continues to print out "Checkpoint 1". If Cstr(res) is commented out it does continue through to "checkpoint 2" etc. Maybe there is a problem with the variable res. If he replaces res with a number (e.g 5.2) it does print out. But the Call InputCapture and calculation of res did work before he added in multitasking. I haven't been able to help him. Can any body help us. Thanks in anticipation. Peter & Michael Option Explicit dim tasktag as byte dim read_tslstack(1 to 60) as byte dim move_servostack(1 to 60) as byte Public Sub Main() const SenS0 as byte = 5 const SenS1 as byte = 6 const ScaleS2 as byte = 7 const ScaleS3 as byte = 8 const OutEnable as byte = 9 Call PutPin(SenS0, bxOutputHigh) Call PutPin(SenS1, bxOutputLow) Call PutPin(ScaleS2, bxoutputHigh) Call PutPin(ScaleS3, bxoutputHigh) Call PutPin(OutEnable, bxoutputlow) Call PutPin(12, bxInputTristate) calltask "read_tsl", read_tslstack End Sub public sub read_tsl() dim tasktag as byte dim localtag as byte localtag = tasktag dim reps as integer dim x as integer dim convstr as string dim res as single dim PulseTrain(1 To 10) As Integer res = 0! reps = 10 do call InputCapture(PulseTrain, reps, 1) x=2 do until x = reps res = res + Csng(PulseTrain(x)) x = x+2 loop res = 1!/((res/5!)/7372800!) debug.print "Checkpoint 1" convstr = CStr(res) debug.print "Checkpoint 2" debug.print convstr debug.print "Checkpoint 3" loop call sleep(0.1) End sub |
|
|
|
From: "medude56au" <> > [...] > In the code below the program appears to work until it > gets to the Cstr function. The "checkpoint 1" prints > out but then continues to print out "Checkpoint 1". > [...] > Option Explicit > [...] > dim read_tslstack(1 to 60) as byte > [...] > calltask "read_tsl", read_tslstack > [...] > public sub read_tsl() > [...] > dim convstr as string What setting are you using for lengths of variable length strings? If you're using 64, this will blow the stack right away, since the task stack is only 60 bytes long. Unless there is a compelling reason to keep the string around, I'd just use this: Debug.Print CStr(res) which minimizes the memory use, since you don't need to declare a separate variable. Also, CStr is expensive in RAM when you're converting floating point. This might be another reason the stack may be overflowing. If you could output an integer instead of floating point, that would save RAM. Or you could use code posted to the Yahoo files section, which converts float to string types, and uses less RAM than CStr, although it's also more restrictive than CStr. -- Frank Manning -- NetMedia, Inc. |