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:
SUBPULSE_OUT_US(INVariableasWORD)Variable=65535-Variable+4TMR1H=Variable_H'Timer 1 Preset High TMR1L = Variable 'Timer1PresetLow
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!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
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!