Help-> 32-bit Timer dsPIC

Post your requests and ideas on the future development of mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
b4rzan
Posts: 60
Joined: 12 Nov 2011 21:39

Help-> 32-bit Timer dsPIC

#1 Post by b4rzan » 15 Feb 2013 21:59

hi all,

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
}

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Help-> 32-bit Timer dsPIC

#2 Post by dejan.odabasic » 18 Feb 2013 16:10

Hello,

I suggest that you take a look at our free timer interrupt, service routine generator tool:
Timer Calculator - http://www.libstock.com/projects/view/3 ... calculator

Timer calculator have support for 32bit mode calculations.
Just make sure you have selected double timer - 32bit mode in timer drop-down list.

Best regards.

b4rzan
Posts: 60
Joined: 12 Nov 2011 21:39

Re: Help-> 32-bit Timer dsPIC

#3 Post by b4rzan » 18 Feb 2013 19:01

my problem is not calculating interrupt delay time. My problem is that the combination of Timer2 and 3 isn't working as 32bit!
I am combining Timer2 and Timer3 so I can measure a longer pulse width in gated mode.

Please any1 has any suggestion?

Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Re: Help-> 32-bit Timer dsPIC

#4 Post by Toley » 18 Feb 2013 19:14

The 32-bit timer operates similarly to a 16-bit timer in Gated Time Accumulation mode.
Quote from the dsPIC30F Reference manual. Please donwload it on microchip website and check there is an example code for what you want to do.
Serge T.
Learning is an endeless process but it must start somewhere!

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 Wish List”