Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC32 interrupt timer 32bit problem

Status
Not open for further replies.

mihail19871987

Newbie level 3
Newbie level 3
Joined
Feb 22, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Bulgaria
Visit site
Activity points
19
Code:
// Include Header Files
#include <p32xxxx.h>                // Include PIC32 specifics header file
#include <plib.h>                   // Include the PIC32 Peripheral Library

// Config Bits
#pragma config FNOSC = FRCPLL       // Internal Fast RC oscillator (8 MHz) w/ PLL
#pragma config FPLLIDIV = DIV_2     // Divide FRC before PLL (now 4 MHz)
#pragma config FPLLMUL = MUL_20     // PLL Multiply (now 80 MHz)
#pragma config FPLLODIV = DIV_2     // Divide After PLL (now 40 MHz)
                                    // see figure 8.1 in datasheet for more info
#pragma config FWDTEN = OFF         // Watchdog Timer Disabled
#pragma config ICESEL = ICS_PGx1    // ICE/ICD Comm Channel Select (pins 4,5)
#pragma config JTAGEN = OFF         // Disable JTAG
#pragma config FSOSCEN = OFF        // Disable Secondary Oscillator
#define SYSCLK 40000000L            

int main(){
    SYSTEMConfigPerformance(SYSCLK);
    TRISBbits.TRISB5 = 0;   // Set RB5 as digital output
    INTEnableSystemMultiVectoredInt();
 
        //T4CON = 0x0;                 // Stop 16-bit Timer4 and clear control register
        //T5CON = 0x0;                 // Stop 16-bit Timer5 and clear control register
        T4CONSET = 0x0038;           // Enable 32-bit mode, prescaler at 1:8,
        TMR4 = 0x0;                  // Clear contents of the TMR4 and TMR5
        PR4 = 0x00FFFFFF;            // Load PR4 and PR5 registers with 32-bit value
        IPC5SET = 0x00000004;        // Set priority level = 1
   
        IFS0CLR = 0x00100000;        // Clear the Timer5 interrupt status flag
        IEC0SET = 0x00100000;        // Enable Timer5 interrupts
        T4CONSET = 0x8000;           // Start timer
    while(1);
    return 1;
}

void __ISR(20, ipl1) Timer1IntHandler(void){
    LATBINV = 0x0020;
    IFS0CLR = 0x00100000; 
}
MX220F032B
What is wrong?
 

We need to ask you the same question: what is wrong?
Does it not program?
Does it not run?
It the timing not right?
How do you know there is a problem?
Susan
 

Which Timer interrupt you want to use and what should be the timer interrupt period ?
 

I think that I've posted the code speak for itself.
I want to run break in period PR4 = 0x00FFFFFF = 16,777,215 cycles at 40/8 = 5MHZ;
Should get a interrupt after about 3-4 seconds...
With 16 bit timer made it there had no problems but no success 32
 

For a start I would never have known from your code that Timer 4 was working as a 16-bit timer but that Timer4/5 was not working as a 32-bit timer. This is why you need to explain what it working and what is not.
The problem is that for 32-bit timers, the interrupts are generated from the 'odd' numbered timer (last bullet point in the "Timers" FRM section, section 14.3.2 on page 14-11). You have correctly adjusted the vector number in the ISR (however the name of the ISR is very misleading in my opinion) but not the IEC0<24> as specified in the data sheet (page 88 in the "T5 - Timer5" entry).
Susan
 

I take it from your last comment that you have not read the data sheet, nor the FRM sections. It is absolutely essential that you read and understand these (at least).
Anyway, I downloaded the same tool and selected a PIC32, 40MHz clock and (approx) 3.35 seconds for the Timer4/5 32-bit and it generated the following Mikroc code:
Code:
//Timer4/5
//Prescaler 1:1; PR5 Preload = 2044; PR4 Preload = 46460; Actual Interrupt Time = 3.35 s
 
//Place/Copy this part in declaration section
void InitTimer4_5(){
  T4CON		 = 0x0;
  T5CON		 = 0x0;
  TMR4			 = 0;
  TMR5			 = 0;
  T5IE_bit		 = 1;
  T5IF_bit		 = 0;
  T5IP0_bit		 = 1;
  T5IP1_bit		 = 1;
  T5IP2_bit		 = 1;
  PR5			 = 2044;
  PR4			 = 46460;
  T4CONbits.TON	 = 1;
  T4CONbits.T32	 = 1;
}
 
void Timer4_5Interrupt() iv IVT_TIMER_5 ilevel 7 ics ICS_SRS{
  T5IF_bit		 = 0;
  //Enter your code here 
}
Apart from a big "no no" of enabling the timer and THEN making it 32-bit, there is only a very passing resemblance to your code in my opinion.
Anyway - have you fixed the problem I identified (setting the wrong IE bit) and does ti now work?
Susan
 

Just use mikroElektronika Timer Calculator tool to generate the timer initialization and timer interrupt code and convert it to XC32 code.

Wowww!!! :smile: thankss!!
Now it's work!!
The blinking is after 0.5 seconds.

The source code is:
// Include Header Files
#include <p32xxxx.h> // Include PIC32 specifics header file
#include <plib.h> // Include the PIC32 Peripheral Library
#include<xc.h>
// Config Bits
#pragma config FNOSC = FRCPLL // Internal Fast RC oscillator (8 MHz) w/ PLL
#pragma config FPLLIDIV = DIV_2 // Divide FRC before PLL (now 4 MHz)
#pragma config FPLLMUL = MUL_20 // PLL Multiply (now 80 MHz)
#pragma config FPLLODIV = DIV_2 // Divide After PLL (now 40 MHz)
// see figure 8.1 in datasheet for more info
#pragma config FWDTEN = OFF // Watchdog Timer Disabled
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (pins 4,5)
#pragma config JTAGEN = OFF // Disable JTAG
#pragma config FSOSCEN = ON // Disable Secondary Oscillator

#define SYSCLK 40000000L

int main(){

SYSTEMConfigPerformance(SYSCLK);
INTEnableSystemMultiVectoredInt();
TRISBbits.TRISB5 = 0; // Set RB5 as digital output

T2CON = 0x0;
T3CON = 0x0;
TMR2 = 0;
TMR3 = 0;
IEC0SET = 0x4000;
IFS0CLR = 0x4000;
IPC3SET = 0x1C;
PR3 = 305;
PR2 = 11825;
T2CONbits.TON = 1;
T2CONbits.T32 = 1;

while(1);
return 1;
}
void __ISR(12, ipl7) Timer1IntHandler(void){
LATBINV = 0x0020;
IFS0CLR = 0x4000;
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top