#include <proc/p32mx230f064b.h>
// DEVCFG3
// USERID = No Setting
#pragma config PMDL1WAY = ON // Peripheral Module Disable Configuration (Allow only one reconfiguration)
#pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow only one reconfiguration)
#pragma config FUSBIDIO = OFF // USB USID Selection (Controlled by Port Function)
#pragma config FVBUSONIO = OFF // USB VBUS ON Selection (Controlled by Port Function)
// DEVCFG2
#pragma config FPLLIDIV = DIV_1 // PLL Input Divider (1x Divider)
#pragma config FPLLMUL = MUL_15 // PLL Multiplier (15x Multiplier)
#pragma config UPLLIDIV = DIV_1 // USB PLL Input Divider (1x Divider)
#pragma config UPLLEN = OFF // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_1 // System PLL Output Clock Divider (PLL Divide by 1)
// DEVCFG1
#pragma config FNOSC = PRI // Oscillator Selection Bits (Primary Osc (XT,HS,EC))
#pragma config FSOSCEN = ON // Secondary Oscillator Enable (Enabled)
#pragma config IESO = ON // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = OFF // Primary Oscillator Configuration (Primary osc disabled)
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)
#pragma config WINDIS = OFF // Watchdog Timer Window Enable (Watchdog Timer is in Non-Window Mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
#pragma config FWDTWINSZ = WISZ_25 // Watchdog Timer Window Size (Window Size is 25%)
// DEVCFG0
#pragma config JTAGEN = ON // JTAG Enable (JTAG Port Enabled)
#pragma config ICESEL = ICS_PGx3 // ICE/ICD Comm Channel Select (Communicate on PGEC3/PGED3)
#pragma config PWP = OFF // Program Flash Write Protect (Disable)
#pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF // Code Protect (Protection Disabled)
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <sys/attribs.h>
#include <plib.h>
int main() {
INTEnableSystemMultiVectoredInt();
//INTEnableSystemSingleVectoredInt();
ANSELB=0x8000; //RB15 como analogico y los demas como digitales
TRISB=0x8000; //1=entrada; 0=salida
LATB=1; //Reseteo los puertos
//Configuración ADC************************************************
AD1CHSbits.CH0SA=9; //Entrada de muestras por AN9
AD1CON1=0x00e4;
AD1CON2=0x0000;
AD1CON3=0x0103;
IEC0bits.AD1IE=1;
IPC5bits.AD1IP=7; //Prioridad
//IPC5bits.AD1IS=1; //Sub-prioridad
IFS0bits.AD1IF=0;
AD1CON1bits.ADON=1;
//******************************************************************/
//Configuración Timer 2 y 3 como 32 bits*********************************
T2CONbits.ON=0;
T2CONbits.TCKPS=0; //Prescaler 1:1
T3CONbits.ON=0;
T2CONbits.T32=1; //Timers 2 y 3 como contadores de 32 bits
TMR2=0; //Borro contenido de los registros del timer
PR2=0x00002710; //Cargo registros de comparación del timer (valor en el cual se resetea)
IPC3SET = 0x00000004; // Set priority level = 1
IPC3SET = 0x00000001; // Set sub-priority level = 1
// Could have also done this in single operation
// by assigning IPC5SET = 0x00000005
IFS0bits.T3IF=0; //Borro flag de interrupción
IPC3bits.T3IP=6; //Prioridad
//IPC3bits.T3IS=3; //Sub-prioridad
IEC0bits.T3IE=1; //Enable Timer5 interrupts
T2CONbits.ON=1; //Enciendo el timer
//*******************************************************************
while(1)
{
}
}
void __ISR(_ADC_VECTOR/*,IPL6AUTO*/) ADCHandler(void)
{
IFS0bits.AD1IF=0; //Borro flag de interrupción
T2CONbits.ON=0;
TMR2=0;
PR2=ADC1BUF0;
T2CONbits.ON=1;
}
void __ISR(_TIMER_3_VECTOR/*, IPL7AUTO*/) Timer3Handler(void)
{
IFS0bits.T3IF=0;
LATBbits.LATB14=!LATBbits.LATB14;
}
La prioridad de las interrupciones trabaja algo así:
Tu programa se ejecuta normalmente, se presenta una interrupcion de alta prioridad, el micro se dirige a la rutina de atencion de las interrupciones de alta prioridad y si mientras ejecutas el codigo de atencion a interrupcion surge otra interrupcion la vas a perder, salvo que antes de salir chequees que se ha activado el flag.
La prioridad de las interrupciones trabaja algo así:
Tu programa se ejecuta normalmente, se presenta una interrupcion de alta prioridad, el micro se dirige a la rutina de atencion de las interrupciones de alta prioridad y si mientras ejecutas el codigo de atencion a interrupcion surge otra interrupcion la vas a perder, salvo que antes de salir chequees que se ha activado el flag.
Eso no ocurre, se atiende igualmente la de baja prioridad, pero solo después de terminar con la de mayor prioridad.
Saludos!
Recordé un tema que hay que tener atención y por lo que veo lo tienes comentado, ojo en ello! Cuando usas múltiples vectores, en la interrupción debe estar correctamente indicado:
void __ISR(_RTCC_VECTOR, ipl3) RtccIsr(void){....
void __ISR(_TIMER_3_VECTOR, ipl2) Timer3Handler(void){...
#include <proc/p32mx230f064b.h>
// DEVCFG3
// USERID = No Setting
#pragma config PMDL1WAY = ON // Peripheral Module Disable Configuration (Allow only one reconfiguration)
#pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow only one reconfiguration)
#pragma config FUSBIDIO = OFF // USB USID Selection (Controlled by Port Function)
#pragma config FVBUSONIO = OFF // USB VBUS ON Selection (Controlled by Port Function)
// DEVCFG2
#pragma config FPLLIDIV = DIV_1 // PLL Input Divider (1x Divider)
#pragma config FPLLMUL = MUL_15 // PLL Multiplier (15x Multiplier)
#pragma config UPLLIDIV = DIV_1 // USB PLL Input Divider (1x Divider)
#pragma config UPLLEN = OFF // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_1 // System PLL Output Clock Divider (PLL Divide by 1)
// DEVCFG1
#pragma config FNOSC = PRI // Oscillator Selection Bits (Primary Osc (XT,HS,EC))
#pragma config FSOSCEN = ON // Secondary Oscillator Enable (Enabled)
#pragma config IESO = ON // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = OFF // Primary Oscillator Configuration (Primary osc disabled)
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)
#pragma config WINDIS = OFF // Watchdog Timer Window Enable (Watchdog Timer is in Non-Window Mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
#pragma config FWDTWINSZ = WISZ_25 // Watchdog Timer Window Size (Window Size is 25%)
// DEVCFG0
#pragma config JTAGEN = ON // JTAG Enable (JTAG Port Enabled)
#pragma config ICESEL = ICS_PGx3 // ICE/ICD Comm Channel Select (Communicate on PGEC3/PGED3)
#pragma config PWP = OFF // Program Flash Write Protect (Disable)
#pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF // Code Protect (Protection Disabled)
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <sys/attribs.h>
#include <plib.h>
int main() {
ANSELB=0x8000; //RB15 como analogico y los demas como digitales
TRISB=0x8000; //1=entrada; 0=salida
LATB=1; //Reseteo los puertos
//Configuración ADC************************************************
AD1CHSbits.CH0SA=9; //Entrada de muestras por AN9
AD1CON1=0x00e4;
AD1CON2=0x0000;
AD1CON3=0x0103;
IEC0bits.AD1IE=1;
IPC5bits.AD1IP=6; //Prioridad
//IPC5bits.AD1IS=1; //Sub-prioridad
IFS0bits.AD1IF=0;
AD1CON1bits.ADON=1;
//******************************************************************/
//Configuración Timer 2 y 3 como 32 bits*********************************
T2CONbits.ON=0;
T2CONbits.TCKPS=0; //Prescaler 1:1
T3CONbits.ON=0;
T2CONbits.T32=1; //Timers 2 y 3 como contadores de 32 bits
TMR2=0; //Borro contenido de los registros del timer
PR2=0x00002710; //Cargo registros de comparación del timer (valor en el cual se resetea)
IPC3SET = 0x00000004; // Set priority level = 1
IPC3SET = 0x00000001; // Set sub-priority level = 1
// Could have also done this in single operation
// by assigning IPC5SET = 0x00000005
IFS0bits.T3IF=0; //Borro flag de interrupción
IEC0bits.T3IE=1; //Enable Timer5 interrupts
IPC3bits.T3IP=7; //Prioridad
//IPC3bits.T3IS=3; //Sub-prioridad
T2CONbits.ON=1; //Enciendo el timer
//*******************************************************************
//INTEnableSystemMultiVectoredInt();
//INTEnableSystemSingleVectoredInt();
INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
INTEnableInterrupts();
while(1)
{
}
}
void __ISR(_ADC_VECTOR,/*IPL6AUTO*/) ADCHandler(void)
{
IFS0bits.AD1IF=0; //Borro flag de interrupción
/*T2CONbits.ON=0;
TMR2=0;
PR2=ADC1BUF0+0xFF;
T2CONbits.ON=1;*/
}
void __ISR(_TIMER_3_VECTOR/*,IPL7AUTO*/) Timer3Handler(void)
{
IFS0bits.T3IF=0;
LATBbits.LATB14=!LATBbits.LATB14;
}Respecto a esto Suky, tengo entendido que iplx (x es un numero del 1 al 7) define la prioridad de interrupción, pero si la tengo configurada mas arriba con la instrucción IPC3bits.T3IP=7 por ejemplo, esto es redundante, ¿O me equivoco?