32bit timer problem in pic24ep512gu814

Status
Not open for further replies.

anboli

Full Member level 2
Joined
Mar 9, 2012
Messages
144
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Visit site
Activity points
2,513
Hi friends,

I had configured the 32bit timer. I dont know how to calculate the timing value to load in the period registers. Could anybody help me?
 

Attachments

  • timer.rar
    3.3 KB · Views: 90

What timer interrupts do you need and for which timer(s)?What is your Fosc?

A sample code.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//Timer2/3
//Prescaler 1:1; PR3 Preload = 12; PR2 Preload = 13580; Actual Interrupt Time = 100 ms
 
//Place/Copy this part in declaration section
void InitTimer2_3(){
  T2CON      = 0x0;
  T3CON      = 0x0;
  TMR2           = 0;
  TMR3           = 0;
  T3IE_bit       = 1;
  T3IF_bit       = 0;
  T3IP0_bit      = 1;
  T3IP1_bit      = 1;
  T3IP2_bit      = 1;
  PR3            = 12;
  PR2            = 13580;
  T2CONbits.TON  = 1;
  T2CONbits.T32  = 1;
}
 
void Timer2_3Interrupt() iv IVT_TIMER_3 ilevel 7 ics ICS_SRS{
  T3IF_bit       = 0;
  //Enter your code here 
}

 

ITS SHOWING AN ERROR,

*** Error 29 "timer_32bit.c" Line 41(29,31): Function definition different from previous definition Timer2_3Interrupt Param#1

- - - Updated - - -

SHOWIN AN ERROR IN INTERRUPT ROUTINE FUNCTION,

Code:
	#include <24ep512gu814.h>
	#include "REGISTERS.h"
	#include "PORT_BIT.h"
	
	#use delay(clock=25M)

	#pragma config ICS = PGD3           // ICD Communication Channel Select bits (Communicate on PGEC3 and PGED3)
	#pragma config JTAGEN = OFF         // JTAG Enable bit (JTAG is disabled)

	// FPOR
	#pragma config ALTI2C1 = OFF        // Alternate I2C1 pins (I2C1 mapped to SDA1/SCL1 pins)
	#pragma config ALTI2C2 = OFF        // Alternate I2C2 pins (I2C2 mapped to SDA2/SCL2 pins)
	#pragma config WDTWIN = WIN25       // Watchdog Window Select bits (WDT Window is 25% of WDT period)

	// FWDT
	#pragma config WDTPOST = PS32768    // Watchdog Timer Postscaler bits (1:32,768)
	#pragma config WDTPRE = PR128       // Watchdog Timer Prescaler bit (1:128)
	#pragma config PLLKEN = ON          // PLL Lock Enable bit (Clock switch to PLL source will wait until the PLL lock signal is valid.)
	#pragma config WINDIS = OFF         // Watchdog Timer Window Enable bit (Watchdog Timer in Non-Window mode)
	#pragma config FWDTEN = OFF         // Watchdog Timer Enable bit (Watchdog timer enabled/disabled by user software)
	
	// FOSC
	#pragma config POSCMD = HS          // Primary Oscillator Mode Select bits (HS Crystal Oscillator Mode)
	#pragma config OSCIOFNC = OFF       // OSC2 Pin Function bit (OSC2 is clock output)
	#pragma config IOL1WAY = ON         // Peripheral pin select configuration (Allow only one reconfiguration)
	#pragma config FCKSM = CSECME       // Clock Switching Mode bits (Both Clock switching and Fail-safe Clock Monitor are enabled)
	
	// FOSCSEL
	#pragma config FNOSC = PRIPLL       // Oscillator Source Selection (Primary Oscillator with PLL module (XT + PLL, HS + PLL, EC + PLL))
	#pragma config IESO = ON            // Two-speed Oscillator Start-up Enable bit (Start up device with FRC, then switch to user-selected oscillator source)
	
	// FGS
	#pragma config GWRP = OFF           // General Segment Write-Protect bit (General Segment may be written)
	#pragma config GCP = OFF            // General Segment Code-Protect bit (General Segment Code protect is Disabled)
	
//	int32 Period_value	= 70000000; // Instruction clock
	int8	count	=	0;
	
	void Timer2_3Interrupt() iv IVT_TIMER_3 ilevel 7 ics ICS_SRS        // SHOWING AN ERROR
	{
  	T3IF    = 0;
  	RJ12	= ~RJ12;
	}

	void Init_timer3_32()
	{
		T2CON	=	0;
		T3CON	=	0;
		TMR3	=	0;
		TMR2	=	0;
		T2T32	=	1;
		T2CS	=	0;
		T2GATE	=	0;
		T2CKPS_4=	0;
		T2CKPS_5=	0;
		PR3		=	12;
		PR2		=	13580;
		IPC2	= 	0X0007;
		T3IF	=	0;
		T3IE	=	1;
		GIE		=	1;
		
		T2ON	=	1;
	}

	void cpu_initiallisation()
	{
		PMD1	=	0X07FF;				// TIMER3 IS ENABLED T3MD = 0;
		PMD2	=	0XFFFF;
		PMD3	=	0X0FFF;
		PMD4	=	0XFFFF;
		PMD5	=	0XFFFF;
		PMD6	=	0XFFFF;
		PMD7	=	0XFFFF;
		
		ANSELA	=	0X0000;
		ANSELB	=	0X0000;
		ANSELC	=	0X0000;
		ANSELD	=	0X0000;
		ANSELE	=	0X0000;
		ANSELF	=	0X0000;
		ANSELG	=	0X0000;
		ANSELH	=	0X0000;
		ANSELJ	=	0X0000;
		ANSELK	=	0X0000;
	
		TRISA	=	0X0000;
		TRISB	=	0X0000;
		TRISC	=	0X0000;
		TRISD	=	0X0000;
		TRISE	=	0X0000;
		TRISF	=	0X0000;
		TRISG	=	0X0000;
		TRISH	=	0X0000;
		TRISJ	=	0X0000;
		TRISK	=	0X0000;

		INTCON1	=	0x8000;
		INTCON2	=	0X8000;
		INTCON3	=	0X0000;
		INTCON4	=	0X0000;

		INTTREG	=	0X0000;
		
	}
	void main()
	{
		
		cpu_initiallisation();
		Init_timer3_32();
		while(1)
		{
			RD1 = ~RD1;
			delay_ms(1000);
		}
	}
 

Ofcourse it will show error because the code I gave is for mikroC PRO PIC32 Compiler. Place my ISR routine code inside your isr routine.

This is code for PIC24. Earlier I posted code for PIC32.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//Timer1
//Prescaler 1:8; PR1 Preload = 25000; Actual Interrupt Time = 50 ms
 
//Place/Copy this part in declaration section
void InitTimer1(){
  T1CON  = 0x8010;
  T1IE_bit   = 1;
  T1IF_bit   = 0;
  IPC0       = IPC0 | 0x1000;
  PR1        = 25000;
}
 
void Timer1Interrupt() iv IVT_ADDR_T1INTERRUPT{
  T1IF_bit   = 0;
  //Enter your code here 
}

 

Is this also a mikro c code?

- - - Updated - - -


and your updated CODE is for TIMER1, I THINK SO.

for CCS the interrupt routine will be like this..

#INT_TIMER2
void Timer2_3Interrupt()
{
T3IF = 0;
RJ12 = ~RJ12;
}

- - - Updated - - -

Sorry to update my oscillator frequencies.

Im using 25MHz, Timer3 - 32bit timer.

and i saw your code, in that you gave the value of the period register. how did you calculate the value for the registers.
PR3 = 12;
PR2 = 13580; of your code. you said it as its for 100ms and i dono whats your frequency. Can you tell me hopw to calculate the value?
 

Yes. It is mikroC code. I haven't used PIC24 or PIC32 but as you say it is a 32 bit timer then max it can count will be 0xFFFFFFFF. I might be wrong. Read datasheet. See how the timer has to be reloaded. I have used Timer Calculator app from mikroe website. The below code is for Fosc = 25 MHz, PIC24, 50 ms interrupt, timer 2 or 3 in 32 bit mode, Prescalar = 1:1.

I think PR2, PR3 are used to load timer values and they are 16 bit registers. I will see the datasheet and reply. Mention what will be the clock for Timer2_3 in 32 bit mode if Fosc is 25 MHz.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//Timer2/3
//Prescaler 1:1; PR3 Preload = 9; PR2 Preload = 35185; Actual Interrupt Time = 50 ms
 
//Place/Copy this part in declaration section
void InitTimer2_3(){
  T2CON      = 0x0;
  T3CON      = 0x0;
  TMR2           = 0;
  TMR3           = 0;
  T3IE_bit       = 1;
  T3IF_bit       = 0;
  T3IP_0_bit         = 1;
  T3IP_1_bit         = 1;
  T3IP_2_bit         = 1;
  PR3            = 9;
  PR2            = 35185;
  T2CONbits.TON  = 1;
  T2CONbits.T32  = 1;
}
 
void Timer2_3Interrupt() iv IVT_ADDR_T3INTERRUPT{
  T3IF_bit       = 0;
  //Enter your code here 
}




Edit: This might help you. https://www.mikroe.com/chapters/view/52/chapter-4-timers/#ch4.4.1
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…