Forum Index
Debug.print and interrupts

 
Author Message
pjc30943



Joined: 02 Dec 2005

Posted: 23 July 2008, 21:32 PM    Post subject: Debug.print and interrupts

With external ISRs enabled, debug.print of course locks up the system until characters are placed onto the queue.
A consequence is that interrupts are serviced at arbitrary times, whenever debug.print gives control back.

Is there a better way to output debug info to the screen that doesn't conflict with infrequent (~500Hz) ISR calls? Such as manually copying single characters into the queue, etc., when the system is free.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 23 July 2008, 23:56 PM    Post subject: Re: Debug.print and interrupts

pjc30943 wrote:
debug.print [...] locks up the system until characters are placed onto the queue.
I just checked the code to confirm that interrupts are not disabled for Debug.Print. It is true, however, that calling Debug.Print will cause an interrupt for each character sent. It is possible that those interrupts will cause the servicing of an external interrupt to be deferred.

pjc30943 wrote:
Is there a better way to output debug info to the screen that doesn't conflict with infrequent (~500Hz) ISR calls? Such as manually copying single characters into the queue, etc., when the system is free.
The code below can be used in place of Debug.Print to print a single string. Note that you have to manually add the CRLF. The commented-out call to Sleep() in the loop can be used to throttle back the speed of outputting the characters. This may be helpful in reducing the deferral of servicing of the external interrupt.
Code:
Sub OutStr(ByVal s as String)
  Dim outQueue() as Byte Based Register.TxQueue
  Dim strLen as Integer, idx as Integer
  strLen = Len(s)
  For idx = 1 to strLen
    ' wait for space to be available
    Do While (GetQueueSpace(outQueue) <= 0)
      ' Call Sleep(0.1)
    Loop

    ' output the next character
    Dim c as Byte
    c = Asc(s, idx)
    Call PutQueue(outQueue, c, 1)
  Next idx
End Sub

Sub Main()
  OutStr("Hello, world!" & Chr(&H0d) & Chr(&H0a))
End Sub
Back to top
Display posts from previous:   
Page 1 of 1

 



ZBasic Microcontrollers Home
All content Copyright © 2005, 2006, 2007, 2008 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group