PIC24/dsPIC33 Timer1 PR1 period value

Timer Calculator is a free software development tool used for easier calculation of timer interrupts.
Post Reply
Author
Message
tima
Posts: 1
Joined: 21 Feb 2024 16:28

PIC24/dsPIC33 Timer1 PR1 period value

#1 Post by tima » 21 Feb 2024 16:50

Hi, I'm using Timer Calculator v4.0.0 to check the Timer1 PR1 period value in some inherited code.
For PIC24/dsPIC33 with 140MHz MCU clock frequency the Timer1 calculated C code is:

Code: Select all

//Timer1
//Prescaler 1:8; PR1 Preload = 8750; Actual Interrupt Time = 1 ms
 
//Place/Copy this part in declaration section
void InitTimer1(){
  T1CON	 = 0x8010;
  T1IE_bit	 = 1;
  T1IF_bit	 = 0;
  IPC0		 = IPC0 | 0x1000;
  PR1		 = 8750;
}
 
void Timer1Interrupt() iv IVT_ADDR_T1INTERRUPT{
  T1IF_bit	 = 0;
  //Enter your code here 
}
I believe the calculation for PR1 should be 8750 - 1 because the Timer1 Module Family Reference Manual for PIC23/dsPIC33 (https://ww1.microchip.com/downloads/en/ ... 05279B.pdf) says:
Timers using a timer input clock prescale = N (other than 1:1) operate at a timer clock rate
(PBCLK / N), and the TMR1 Count register increments on every Nth timer clock rising edge. For
example, if the timer input clock prescale is 1:8, the timer increments on every eighth timer clock
cycle. The timer continues to increment until the TMR1 Count register matches the PR1 Period
register value. The TMR1 Count register then resets to 0x0000 after ‘N’ more timer clock cycles,
and then continues to increment and repeats the period match until the timer is disabled.
That is, it starts from 0 and doesn't reset until one TMR1 increment after the match/interrupt.

Can you confirm this?
Thanks

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: PIC24/dsPIC33 Timer1 PR1 period value

#2 Post by IvanJeremic » 17 Mar 2024 18:58

Hi,

Sorry for the delay.

There are timer interrupt examples in Mikro PRO compilers, all of them are made with the timer calculator so it should work ok.

Can you tell me for what MCU were you trying to use the calculator exactly?

Regards,

Ivan.

Post Reply

Return to “Timer Calculator”