ab. PIC18F2550 asynchronous counter 1 (timer 3) workaround

NOTE: SVLIB_PIC18F24J50 v4.0.NET4(x64).dll is available from Downloads section. It will solves minor PIC18F2550 microcontroller compatibility issues, except for PIC18F2550 hardware deficiencies.

Example: PIC18F2550 only has 4 timers: 0 through 3, while PIC18F2xJ50 microcontrollers have 5 timers: 0 through 4. This means that high level tasks may have to be performed differently on PIC18F2550. However the application program interface (API) will reamin the same.

The original firmwares v2.5 and v2.6 are written for PIC18F24J50 and PIC18F26J50, which use I2 and I3 inputs as hardware timer 0 and hardware timer 3 asynchronous inputs. This means that timer 1 counter and timer 3 counter work on inputs I2 and I3 on Velleman K8055-1 board. The firmwares are also ported to PIC18F2550, which has no PPS unit. Therefore pin remapping is not possible.

Hardware timer 0 input is connected to I1 on PIC18F2550, but Timer3 is not configured correctly by calling pic.timermode(0), because it’s counter registers reside on different addresses in data memory space:

TMR3L is on &hFB2

TMR3H is on &hFB3

T3CON is on &hFB1

The following workaround enables you to use timer 3 as asynchronous counter 1 (second counter):

Dim cnt as UInt16

Dim tmr3Lval as Byte

PIC.DataMemWrite(&hFB1,&h83) ‘ This properly initializes timer 3 on I3 input

Tmr3Lval=PIC.DataMemRead(&hFB2)

cnt= PIC.DataMemRead(&hFB3)

cnt<<=8

cnt = cnt or Tmr3Lval ‘ Now, cnt holds the 16-bit value of timer 3 counter.

To reset timer 3 counter, write:

PIC.DataMemWrite(&hFB3,0)

PIC.DataMemWrite(&hFB2,0)

To set timer 3 counter to a specific value, write:

PIC.DataMemWrite(&hFB3,high_byte)

PIC.DataMemWrite(&hFB2,low_byte)

NOTE: A new value for Timer 3 counter must be written to high byte first. The existing value of Timer 3 counter must be read low byte first