Debug.print and interrupts

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
pjc30943
Posts: 220
Joined: 01 December 2005, 18:45 PM

Debug.print and interrupts

Post by pjc30943 »

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.
Paul
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Debug.print and interrupts

Post by dkinzer »

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: Select all

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 &#40;GetQueueSpace&#40;outQueue&#41; <= 0&#41;
      ' Call Sleep&#40;0.1&#41;
    Loop

    ' output the next character
    Dim c as Byte
    c = Asc&#40;s, idx&#41;
    Call PutQueue&#40;outQueue, c, 1&#41;
  Next idx
End Sub

Sub Main&#40;&#41;
  OutStr&#40;"Hello, world!" & Chr&#40;&H0d&#41; & Chr&#40;&H0a&#41;&#41;
End Sub
- Don Kinzer
Post Reply