Created Thu, 20 Sep 2012 20:17:19 +0000 by Egwyn
Thu, 20 Sep 2012 20:17:19 +0000
Hi Ã'm using a max32 with a MPIDE to get an interrupt every 40us, I do it with the following sketch, this is part of the all code.
#include <plib.h>
#include <Time.h>
#define F_m 25000 // 40us
#define Pout1 13 //
void setup()
{
pinMode(Pout1,OUTPUT);
OpenTimer5(T5_ON, F_CPU / F_m);
ConfigIntTimer5(T5_INT_ON | T5_INT_PRIOR_3);
}
void loop(){}
extern "C"
{
void __ISR(_TIMER_5_VECTOR,ipl3) Control(void)
{
digitalWrite(Pout1,HIGH);
digitalWrite(Pout1,LOW);
mT5ClearIntFlag(); // Clear Flag
}
}
But now I need change it to MPLAB, and I'm using the following code, the problem is that I am getting the interrupt every 400us. Could someone help me find where is my error. thanks
//****************************************************************************************
//* Libs
//****************************************************************************************
#include <string.h>
#include <proc/p32mx795f512l.h>
#include <plib.h>
//****************************************************************************************
//* PIC32MX795F512L Configuration
//****************************************************************************************
#pragma config FCANIO = OFF // Use Alternate Pins for chipKIT MAX32
#pragma config POSCMOD = HS // Primary Oscillator
#pragma config FNOSC = PRI // Oscillator Selection
#pragma config FPBDIV = DIV_2 // Peripheral Clock divisor
#pragma config FWDTEN = OFF // Watchdog Timer
#pragma config WDTPS = PS1 // Watchdog Timer Postscale
#pragma config FCKSM = CSDCMD // Clock Switching & Fail Safe Clock Monitor
#pragma config OSCIOFNC = OFF // CLKO Enable
#pragma config IESO = OFF // Internal/External Switch-over
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (KLO was off)
#pragma config CP = OFF // Code Protect
#pragma config BWP = OFF // Boot Flash Write Protect
#pragma config PWP = OFF // Program Flash Write Protect
#pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select
#pragma config DEBUG = ON // Background Debugger Enable
//*****************************************************************************************
//* DEFINICION DE COSTANTES
//*****************************************************************************************
#define SYSTEM_FRECUENCY 80000000L
#define PBUS_CLOCK 40000000L
#define SAMPLE_RATE 25000
//****************************************************************************************
//* Main
//****************************************************************************************
int main(void)
{
//****************************************************************************************
//* TUNE-UP
//****************************************************************************************
SYSTEMConfigPerformance(SYSTEM_FRECUENCY); //
mOSCSetPBDIV( OSC_PB_DIV_2 );
//****************************************************************************************
//* TIMER5
//****************************************************************************************
OpenTimer5(T5_ON | T2_PS_1_1, PBUS_CLOCK / SAMPLE_RATE);
ConfigIntTimer5(T5_ON | T5_INT_PRIOR_3);
INTEnableSystemMultiVectoredInt();
//****************************************************************************************
//* Initial States
//****************************************************************************************
mPORTASetPinsDigitalOut(BIT_3);
mPORTAClearBits(BIT_3);
}
//****************************************************************************************
//* RUTINA DE INTERRUPCION TIMER5
//****************************************************************************************
void __ISR(_TIMER_5_VECTOR,ipl3)Timer5Handler(void)
{
mPORTAToggleBits(BIT_3); // -------
asm("nop"); // 1
asm("nop"); // 1
asm("nop"); // 1
asm("nop"); // 1
mPORTAToggleBits(BIT_3); // -------
mT5ClearIntFlag(); // Clear interrupt flag
}
Mon, 24 Sep 2012 17:33:41 +0000
Solved ... It was so stupid, the correct frecuency on board is 8MHz .. ;), just correct that on C and work fine !