I just tried adding a second task to a previously working program. The program does a bunch of stuff, and every so often needs to send a sequence of DTMF digits using a MT8888 chip.
I have a Sub SendDigit(digit) that when called waits in a loop for the chip to be ready to send, then sends the digit. The chip is busy for 100ms after it gets the digit while it sends the digit for 50ms and waits 50ms for the gap between digits. This sub works fine.
My problem is, that sending multiple digits caused the main program to have to wait for up to 100ms (for each digit) while the DTMP chip is busy. I'd like to allow the main program to continue its processing, so I thought I would add a task to send the digits in the background.
The idea is that I would make a Queue to hold the digits to be sent. When the main program needed to send a digit, it would add the digit to the queue instead of calling Sub SendDigit.
The second task would continuously check the queue, and if data were present get the byte and then call SendDigit. When not sending digits, I would like this task to use as few resources as possible to allow the main program to run as fast as possible.
Here is my task:
Code: Select all
Dim DTMFtaskStack(1 to 100) as Byte
Dim DTMFq(40) as byte
Sub DTMFsend () 'Task to send DTMF digits in the background
Dim DTMFbyte as Byte
Do
If StatusQueue(DTMFq) Then 'Any digits available?
Call GetQueue(DTMFq, DTMFbyte, 1) 'Get the digit
Call SendDigit(DTMFbyte) 'Send the digit
End If
Sleep(0.120) 'Give up task time?, best value?
Loop
End Sub
I have read the app notes and the manual pages, but I must be missing something subtle...