Bert - 2020-03-21

This example (http://gcbasic.sourceforge.net/help/_generate_accurate_pulses.html) messed me up for a while. The subroutine at the bottom adds 4 to TMR1L to account for processing delays, which is fine, except it is done after stripping the lower 8 bits. If the lower 8 bits overflow, the pulse is wrong.
The example code should be:

  SUB PULSE_OUT_US (IN Variable as WORD)
    Variable = 65535 - Variable + 4
    TMR1H = Variable_H      'Timer 1 Preset High
    TMR1L = Variable  'Timer 1 Preset Low

Linked example repeated here:
SUB PULSE_OUT_US (IN Variable as WORD)
TMR1H = 65535 - Variable_H 'Timer 1 Preset High
TMR1L = (65535 - Variable) + 4 'Timer 1 Preset Low

GCBasic rocks!