Timer1 PR1 Problem

Beta Testing discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
shahab_esf_sadedel
Posts: 5
Joined: 20 Nov 2010 11:04

Timer1 PR1 Problem

#1 Post by shahab_esf_sadedel » 26 Mar 2012 13:52

hi every body

im working with Timer1 in dsPIC30F4011 and i have a problem when
i want using this timer to generating 1us delay,
i couldnt generate below 18.8us with this timer
im decrease PR1 to 4 but its not work

this is my codes:

Code: Select all

void Timer1Int() org 0x1A      // Timer1 address in the interrupt vector table
{
  // Place your codes here-------------------
  LATD = ~PORTD;          // PORTD inversion
  //-----------------------------------------
  IFS0 = IFS0 & 0xFFF7;   // Interrupt flag reset
}

void timer1_init(void);

void main()
{

     TRISD = 0x00;              // PORTD is output
     LATD  = 0x00;              // Set initial value at port D
     //timer1_init();

  while(1)
  {
     LATD = ~LATD;          // PORTD inversion
  };
}

 void timer1_init(void)
 {
      T1CON = 0x0000;             // Stops the Timer1 and reset control reg
      TMR1  = 0x0000;             // Clear contents of the timer register
      PR1   = 4;              // Load the Period register with desired value
      IPC0  = IPC0 | 0x1000;     // Priority level is 1
      IFS0  = IFS0 & 0xFFF7;    // Interrupt flag reset
      IEC0  = IEC0 | 0x0008;     // Timer1 interrupt enabled
      T1CON = 0x8000;            // Timer1 enabled (internal clock divided by 1 & FOSC/4)
      
 }
please Help me!!!!!!!! :roll:

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Timer1 PR1 Problem

#2 Post by janko.kaljevic » 27 Mar 2012 10:32

Hello,

Please can you tell me which oscillator settings are you using?

Best regards.

shahab_esf_sadedel
Posts: 5
Joined: 20 Nov 2010 11:04

Re: Timer1 PR1 Problem

#3 Post by shahab_esf_sadedel » 03 Apr 2012 07:23

thanks for attention
im using 7.3728MHz crystal with 16x PLL

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Timer1 PR1 Problem

#4 Post by janko.kaljevic » 03 Apr 2012 09:56

Hello,

I have managed to make it trigger every 2us.
Please find the code bellow:

Code: Select all

void Timer1Int() iv IVT_ADDR_T1INTERRUPT {
  T1IF_bit = 0;             // Clear T1IF
  LATB = ~ PORTB;           // Invert PORTB
}
...
  ADPCFG = 0xFFFF;          // Initialize AN pins as digital
  TRISB  = 0;               // initialize PORTB as output
  LATB   = 0xAAAA;          // Initialize PORTB value
  T1CON = 0x0000;             // Stops the Timer1 and reset control reg
  TMR1  = 0x0000;             // Clear contents of the timer register
  PR1   = 60;              // Load the Period register with desired value
  IPC0  = IPC0 | 0x1000;     // Priority level is 1
  T1IF_bit = 0;    // Interrupt flag reset
  T1IE_bit = 1;      // Timer1 interrupt enabled
  T1CON = 0x8000;            // Timer1 enabled (internal clock divided by 1 & FOSC/4)
...
Maximum that I have managed to accomplish on my sample is 1.5us.

Best regards.

shahab_esf_sadedel
Posts: 5
Joined: 20 Nov 2010 11:04

Re: Timer1 PR1 Problem

#5 Post by shahab_esf_sadedel » 15 Apr 2012 08:38

thanks a lot
its very useful

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 Beta Testing”