Sign in

username:

password:



Not a member?

Search basicx



Search tips

Subscribe to basicx



basicx by Keywords

Accelerometer | ADC | ADXL | Adxl20 | AVR | BasicStamp | BX-35 | BX28 | BX35 | COM3 | Compiler | Downloader | EEPROM | Electromagnet | GetADC | GP2D1 | GPS | I2C | IDE | Keypad | LCD | LCD+ | MIDI | Motors | Multitasking | Netmedia | Networking | PCB | PID | PlaySound | PWM | Relays | RTC | Servo | ShiftOut | SitePlayer | SPI | Stack | Timer | USB


Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | BasicX | Serial Port and Tasks

Discussion forum for the BasicX family of microcontroller chips.

Serial Port and Tasks - Joseph Obernberger - Aug 3 20:49:00 2003

Hi - just wanted to thank everyone for the help so far!
I'm having a problem using the serial port (Com1) inside a task with the
Debug.Print command. I start two tasks, one to get data from the analog
to digital ports, and one to display that data on the serial line. The
main task displays the data on a VSDM (http://www.simmetry.com) display.
If I do not call the SerialTask, everything works OK, but with the
SerialTask started (see below), the stamp resets or hangs. Any ideas?

On a side note, if anyone has a better way of polling the serial port
(see PrintLCD below), I'd appreciate it.
Thanks!!
joeo

------------------------------------------
Dim OutBuffer(1 To 48) As Byte
Dim InBuffer(1 To 48) As Byte
Dim ADCData(1 To 9) As Integer

Private Const StackSize As Integer = 25
Private DisplayTaskStack(1 to StackSize) As Byte
Private GetDataTaskStack(1 to StackSize) As Byte
Private SerialTaskStack(1 to StackSize) As Byte

Sub Main()

Dim PVal as Byte
Dim Sing as Single

' Open Com3 and corresponding queue.

Call OpenQueue(OutBuffer, 48)
Call OpenQueue(InBuffer, 48)
Call DefineCom3(5, 6, bx0000_1000)
Call OpenCom(3,9600,InBuffer, OutBuffer)
Call Delay(0.5)

' Reset and init the display
Call PutQueueStr(OutBuffer, "R")
Call PutQueueStr(OutBuffer, Chr(13))
Call Delay(0.5)
Call PutQueueStr(OutBuffer, "C")
Call PutQueueStr(OutBuffer, Chr(13))
Call Delay(0.5)
Call PutQueueStr(OutBuffer, "W0")
Call PutQueueStr(OutBuffer, Chr(13))
Call Delay(0.5)

' Put Display into graph mode
Call Delay(1.0)
Call PrintLCD("GRchOXY Ln")
Call PrintLCD("Ts81, 1 Seconds 10")

CallTask "GetDataTask", GetDataTaskStack
CallTask "SerialTask", SerialTaskStack

Do
Sing = CSng(ADCData(1))
'Sing = Sing * 0.248780 'Scale A2D - value for O2
Sing = Sing * 0.0498046875
Pval = CByte(Sing)
Call GraphPoint(Pval)
Sleep(10)
Loop

End Sub

Private Sub PrintLCD( ByVal LCDString As String)

Dim Length As Integer
Dim Out as Byte
Dim QStatus as Boolean

QStatus = False
Out = 0
' Do not allow entries that are too long - causes crashes.
Length = Len(LCDString)
If(Length>26) Then
Debug.Print "Invalid Length " & Cstr(Length) & " to PrintLCD
with value: " & LCDString
Else
Call PutQueueStr(OutBuffer, LCDString)
Call PutQueueStr(OutBuffer, Chr(13))
Do
Call GetQueue(InBuffer, Out, 1)
If (Cstr(Out)=62) Then
QStatus = True
End If
Loop Until (QStatus)
End If
Call Delay(0.02)
End Sub

Private Sub GraphPoint( ByVal DataPoint as Byte)

Call PutQueueStr(OutBuffer, "P")
Call PutQueue(OutBuffer, DataPoint, 1)
Call PutQueueStr(OutBuffer, Chr(13))
Call Delay(0.02)

End Sub

' Task Definitions Follow

' Get Data from all the Analog Ports.
Private Sub GetDataTask()

Do
ADCData(1) = GetADC(13)
ADCData(2) = GetADC(14)
ADCData(3) = GetADC(15)
ADCData(4) = GetADC(16)
ADCData(5) = GetADC(17)
ADCData(6) = GetADC(18)
ADCData(7) = GetADC(19)
ADCData(8) = GetADC(20)
Sleep(2)
Loop

End Sub

' Write analog data to serial port Com1.
Private Sub SerialTask()

Do
Debug.Print "Hello"
Sleep(1.0)
Loop

End Sub

joeo





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )


Re: Serial Port and Tasks - Frank Manning - Aug 3 22:43:00 2003

From: Joseph Obernberger <>

> If I do not call the SerialTask, everything works OK,
> but with the SerialTask started (see below), the stamp

The what?

> resets or hangs. Any ideas?
> [...]
> Private Const StackSize As Integer = 25
> Private DisplayTaskStack(1 to StackSize) As Byte
> Private GetDataTaskStack(1 to StackSize) As Byte
> Private SerialTaskStack(1 to StackSize) As Byte
> [...]
> Private Sub SerialTask()
>
> Do
> Debug.Print "Hello"
> Sleep(1.0)
> Loop
>
> End Sub

The stack size is way too small for SerialTask. With a 25 byte
stack, 15 bytes are taken up by the task frame, which leaves only
10 bytes for everything else. Debug.Print takes at least 9 bytes
of that for its own stack frame. Probably you have a stack
overflow.

You might try measuring the actual stack usage.

-- Frank Manning
-- NetMedia, Inc.





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Serial Port and Tasks - Joseph Obernberger - Aug 4 0:19:00 2003

Thanks - that was the problem.
I'm not sure how to go about measuring the stack usage - is there
documentation about that somewhere?
Thanks!
joeo

Frank Manning wrote:

>From: Joseph Obernberger < >
>>If I do not call the SerialTask, everything works OK,
>>but with the SerialTask started (see below), the stamp
>>
>>
>
>The what? >
>>resets or hangs. Any ideas?
>> [...]
>>Private Const StackSize As Integer = 25
>>Private DisplayTaskStack(1 to StackSize) As Byte
>>Private GetDataTaskStack(1 to StackSize) As Byte
>>Private SerialTaskStack(1 to StackSize) As Byte
>> [...]
>>Private Sub SerialTask()
>>
>> Do
>> Debug.Print "Hello"
>> Sleep(1.0)
>> Loop
>>
>>End Sub
>>
>>
>
>The stack size is way too small for SerialTask. With a 25 byte
>stack, 15 bytes are taken up by the task frame, which leaves only
>10 bytes for everything else. Debug.Print takes at least 9 bytes
>of that for its own stack frame. Probably you have a stack
>overflow.
>
>You might try measuring the actual stack usage.
>
>-- Frank Manning
>-- NetMedia, Inc.




______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Serial Port and Tasks - airmaledfw - Aug 4 11:11:00 2003

Joseph,

The following past post shows an example (with code) of measuring
stack useage http://groups.yahoo.com/group/basicx/message/13718 --- In , Joseph Obernberger <joelori@e...>
wrote:
> Thanks - that was the problem.
> I'm not sure how to go about measuring the stack usage - is there
> documentation about that somewhere?
> Thanks!
> joeo
>
> Frank Manning wrote:
>
> >From: Joseph Obernberger <joelori@e...>
> >
> >
> >
> >>If I do not call the SerialTask, everything works OK,
> >>but with the SerialTask started (see below), the stamp
> >>
> >>
> >
> >The what?
> >
> >
> >
> >>resets or hangs. Any ideas?
> >> [...]
> >>Private Const StackSize As Integer = 25
> >>Private DisplayTaskStack(1 to StackSize) As Byte
> >>Private GetDataTaskStack(1 to StackSize) As Byte
> >>Private SerialTaskStack(1 to StackSize) As Byte
> >> [...]
> >>Private Sub SerialTask()
> >>
> >> Do
> >> Debug.Print "Hello"
> >> Sleep(1.0)
> >> Loop
> >>
> >>End Sub
> >>
> >>
> >
> >The stack size is way too small for SerialTask. With a 25 byte
> >stack, 15 bytes are taken up by the task frame, which leaves only
> >10 bytes for everything else. Debug.Print takes at least 9 bytes
> >of that for its own stack frame. Probably you have a stack
> >overflow.
> >
> >You might try measuring the actual stack usage.
> >
> >-- Frank Manning
> >-- NetMedia, Inc.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>


______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )