Proton BASIC Compiler - HRSOut by interrupt

  • PicŪ Basic

  • HRSOut by interrupt

    This code has been requested by "Maxi" (PDS user in the forum) for saving time in the execution of the main program. See the thread HERE.

    The idea is #disable the HRSout command and rewrite the low level routine to send bytes to a circular buffer (very fast). In the interrupt routine the bytes of the array will be sent one by one to the UART in the background. The HRSOut command continues to function normally as indicated in the manual.

    The parameters that must be handled are the baud rate and the array size. The end there is not speed gains if too many bytes are sent. The code is prepared for several baude rates: 9600, 19200, 38400 & 57600. The timer used is Timer2 because it is very easy to manage with PR2 and needs small lines of codes to run.

    Some formula could be applied, if the number of Bytes to send is repetitive.
    YourProgramTimeLoop > numberBytesToSend x 10 / BaudRate
    For example: 100 bytes x 10 / 9600 = 0,104 the "YourProgramTimeLoop" must to be > 104 mS

    To be as efficient as possible, you can regularly distribute the number of interruptions in time the main program loop. Pulling out all the bytes at maximum speed in the beginning of his program could delay your main code. Carefully choose the baudrate, the dimension of the array depending on the number of bytes to send and runtime of the main program. Of course some testing is needed.

    Download the code HERE