Timer1 late starting

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
MedBoy
Posts: 137
Joined: 11 Jul 2012 11:45

Timer1 late starting

#1 Post by MedBoy » 27 Apr 2016 15:52

Hello,
I use dsPIC33EP512MU810. I want to make a timer with timer1. I use your timer calculator program and i choosed 1ms interrupt time. i wrote below commands:

Code: Select all

sub procedure InitTimer1()
  T1CON	 = 0x8010
  T1IE_bit	 = 1
  T1IF_bit	 = 0
  IPC0	 = IPC0 or 0x1000
  PR1		 = 8750
end sub

sub procedure Timer1Interrupt() iv IVT_ADDR_T1INTERRUPT
T1IF_bit	 = 0
count=count+1
If count=1000 Then
count=0
Second=Second-1
If Second=255 Then
Second=59
Minute=Minute -1
End If
end if
end sub
timer work well. there is no problem in interrupts. but, first start after the programming, timer start after 50 second(real time). but just first start(switch on). after starts, working normal, without late. why do it that? is it normal?

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: Timer1 late starting

#2 Post by Aleksandar.Mitrovic » 28 Apr 2016 09:38

Hi MedBoy,

I suggest you to take a look at our example from the compiler for dsPIC33EP512MU810 at:
...\Mikroelektronika\mikroC PRO for dsPIC\Examples\Internal MCU modules\dsPIC33EP512MU810\Timer1 Interrupt

Maybe you have overlooked something.

Best regards,
Aleksandar

MedBoy
Posts: 137
Joined: 11 Jul 2012 11:45

Re: Timer1 late starting

#3 Post by MedBoy » 28 Apr 2016 09:58

Aleksandar.Mitrovic wrote:Hi MedBoy,

I suggest you to take a look at our example from the compiler for dsPIC33EP512MU810 at:
...\Mikroelektronika\mikroC PRO for dsPIC\Examples\Internal MCU modules\dsPIC33EP512MU810\Timer1 Interrupt

Maybe you have overlooked something.

Best regards,
Aleksandar
I find problem, i have to set to zero "cnt" variable while starting program. it solved. but i have a question again. i want to pause timer 1 counting. i wrote this command:

Code: Select all

TON_bit= 0   
when i continue to timer1 counting, i make "TON_bit= 1" (timer 1 start bit). is this method correct?

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: Timer1 late starting

#4 Post by Aleksandar.Mitrovic » 28 Apr 2016 10:19

Hi MedBoy,

I suggest you to just try disable timer with:

Code: Select all

T1IE_bit = 0;
Kind regards,
Aleksandar

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”