Adding character pacing to the hardware USART

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Adding character pacing to the hardware USART

Post by Jerry Messina » Sun Mar 18, 2012 12:48 pm

Here's an example of how you could modify the USART module to add a delay between transmitting characters similar to the Pacing used in the software UART module.

Copy USART.bas to your user library and add the following (replacing the two existing subs)

Code: Select all

Dim 
   FPacing As Word                    // write byte pacing (us)

// public variables...
Public Dim
   Pacing As FPacing                  // write pacing (us) 


{
****************************************************************************
* Name    : WriteByte                                                      *
* Purpose : Write a Byte value To the hardware USART                       *
*         : Wait Until ready To send Is enabled, Then send WREG Byte       *
****************************************************************************
}
Public Sub WriteByte(pValue As WREG)
   Repeat
      ClrWDT
   Until (ReadyToSend)          // wait for transmitter to be available

   TXRegister = WREG            // load the byte into the txreg

   If (FPacing > 0) Then        // add any char pacing
      while (TRMT = 0)          // first, wait for the TSR to be empty
          ClrWDT
      end while
      DelayUS(FPacing)          // now, wait the specified delay time
   EndIf 

End Sub


{
****************************************************************************
* Name    : WriteItem (OVERLOAD)                                           *
* Purpose : Write a String value To the hardware USART                     *
****************************************************************************
}
Sub WriteItem(pText As String)
   FSR0 = AddressOf(pText)
   while (INDF0 <> 0)
      WriteByte(POSTINC0)
   end while
End Sub



// Module initialisation...
FPacing = 0

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Post by Aresby » Mon Mar 19, 2012 9:01 am

This is interesting.

I had already carried out the first change (at least, I just added in a DelayuS) but as we already establish the method of writing complete strings - as opposed to single bytes - still did not work because it used a different method.

So I shall take both your examples and experiment at the next available opportunity and post back here whether it works as expected (I have high hopes).
Aresby
Swordfish & PIC Newbie

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Pacing in the hardware USART does the trick

Post by Aresby » Thu Mar 22, 2012 7:09 am

I've just implemented Jerry's new routines that support PACING (the delay between sending characters out via the hardware USART to my LED screen) and it has cured the problem previously described (ie garbage output).

So, I can now use my PICAXE 133 OLED 2 x 16 chars screen (with built in 'intelligent' PIC driver).

The problem would appear to be that the PICAXE LED driver/code just isn't fast enough to keep up with 'standard' USART output and needs a small delay (350 microseconds in my case) to prevent garbage being displayed.

Thanks, Jerry.
Aresby
Swordfish & PIC Newbie

Post Reply