I am trying to combine timer2 and timer3 to form a 32-bit timer so that I can measure a longer pulse width via the T2CK pin. I am using these timers in Gated mode (TGATE). My problem is that I am not getting the 32-bit value, I am able to measure 5ms max with Timer2 only, however when timer2 and timer3 are used in 32bit mode; I should be able read much longer pulse but this is not the case with my code. please look at my code and comment if you have anything. thanks
I am using dsPIC30F4013, 12MHZ crystal. As you can see below is the Timer3Int() I am displaying the pulse width in milliseconds, hence my period is 83.33ns therefore this value multiplied by the value in the 32-bit REGISTER and then divided by 1mil so that we get millisec.
Code: Select all
#include"dsLCD.h"
#include"dsLCD.c"
void Timer3Int( ) org 0x000022 // Timer2 interrupt vector
{
Cursor(0,0);
PrintNumber(((TMR3HLD<<16)+TMR2)*83.33 /1000000); //show in milliseconds
LATD = (TMR3HLD<<16)+TMR2; // Display Pulse duration on port D
IFS0 = IFS0 & 0x0030; // Clear interrupt flag
}
void main()
{
TRISD = 0; // Make PORTD output
TRISC = 0x2000; // Make RC13> T2CK pin input
LATD = 0; // Clear PORTD
IPC1 = IPC1 | 0x1000; // Set priority level at 1
IEC0 = IEC0 | 0x0080; // Enable Timer3 interrupt
PR2 = 0xFFFF; // Set period to its maximum
PR3 = 0xFFFF; // Set period to its maximum
T2CON = 0x8048; // T2ON=1 and TGATE=1 (gating mode), 1:1 prescaler
Clear(); //LCD
Start(); //LCD_init
while (1) ; // Endless loop
}