You have no items in your shopping cart.

Subtotal: 0.00

How to Interface External Interrupts with dsPIC Evaluation Board

dsPIC30F4011 Evaluation board

The dsPIC30F4011 Evaluation board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through USB port.

Microchip’s dsPIC30F (dsPIC30F4011), Evaluation Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 16-bit Microcontrollers.

External Interrupts

An interrupt caused by an external source such as the computer operator, external sensor or monitoring device, or another computer. Interrupts are special events that require immediate attention.

Interfacing External Interrupts

Fig. 1 shows how to interface the External Interrupt to microcontroller. Interrupts cause the processor to cease the running task to serve a special task for which the interrupt event had occurred. After the special task is over, the processor resumes performing the original task.

The processor can also serve these events by polling method. But polling is an inefficient technique as compared to interrupts. In the polling method, the processor has to continuously wait for the event signal. Thus it always remains busy using extra resources.





Fig. 1 Interfacing External Interrupts to Microcontroller

Interfacing External Interrupts with dsPIC30F4011

We now want to display some messages in PC when occur an external interrupt signal in dsPIC30F4011 Evaluation board. The Interrupt signal is occurred by using switches. When the switch is pressed to LOW, then the external interrupt is occurred.

The Vectored Interrupt Controller (VIC) takes 32 interrupt request inputs and programmable assigns them into 3 categories, FIQ, vectored IRQ, and non-vectored IRQ.

The dsPIC30F4011 Evaluation board has two numbers of External Interrupts, connected with I/O Port lines (PORTE.8, PORTD.0 & PORTD.1) as switches.

Pin Assignment with dsPIC30F4011



 

Interrupts

dsPIC Lines

Connections

Tactile Switch

DS1307

SW2 – (INT0)

RE8





SW3 – (INT2)

RD0

 

SW4 – (INT1)

RD1

 
 



Circuit Diagram to Interface Ext-Interrupt with dsPIC





Source Code

The Interfacing External Interrupt with dsPIC program is very simple and straight forward, that accessed by using switches. When the two external interrupts occurring, some messages are displayed in PC through serial port at 9600 baud rate. The C program is written in Mplab software & compiled the code by using Microchip C30 Compiler.

C Program to interface Ext-Interrupt with dsPIC30F4011

#include

#include "p30f4011.h"

_FOSC(CSW_FSCM_OFF & XT);

_FWDT(WDT_OFF);

_FBORPOR(PBOR_ON & MCLR_EN);

_FGS(CODE_PROT_OFF);

#define XTFREQ 20000000

#define FOSC XTFREQ/4

#define BAUDRATE 9600

#define BRGVAL ((FOSC/BAUDRATE)/16)-1

#define INT0 IFS0bits.INT0IF

#define INT1 IFS1bits.INT1IF

#define INT2 IFS1bits.INT2IF void Interrupt_init(void);

void DelayMs(unsigned int);

int main()

{

DelayMs(10);

ADPCFG = 0xffff;

TRISB = 0x0000;

Interrupt_init();

DelayMs(10);

while(1)

{

}

return 0;

}

void Interrupt_init(void)

{

INTCON1 = 0x0000;

INTCON2 = 0x0000;

IFS0 = 0x0000;

IFS1 = 0x0000;

IEC0 = 0x0001;

IEC1 = 0x0081;

IPC0 = 0x0007;

IPC4 = 0x0006;

IPC5 = 0x5000;

}

void _ISR _INT0Interrupt(void)

{

DelayMs(10);

INT0 = 0;

LATBbits.LATB3 ^=1;

}

void _ISR _INT1Interrupt(void)

{

DelayMs(10);

INT1 = 0;

LATBbits.LATB4 ^=1;

}

void _ISR _INT2Interrupt(void)

{

DelayMs(10);

INT2 = 0;

LATBbits.LATB5 ^=1;

}

void DelayMs(unsigned int Ms)

{

unsigned int delay_cnst;

while(Ms>0)

{

Ms--;

for(delay_cnst = 0;delay_cnst <276;delay_cnst++);

}

}

To compile the above C code you need the Mplab software & Microchip C30 Compiler. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In Mplab, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without dsPIC30F4011 Evaluation board.

The PICKIT2 software is used to download the hex file into your microcontroller IC dsPIC30F4011 through USB.

Testing the External Interrupts with dsPIC30F4011

Give +9V power supply to dsPIC30F4011 Evaluation board; the serial cable is connected between the dsPIC30F4011 Evaluation board and PC. Open the Hyper Terminal screen, select which port you are using and set the default settings. Now the screen should show which external interrupt is selected.

When you pressed the external interrupt key, the screen should update which interrupt is now pressed. The Interrupts are controlled by using switches. If any data is not coming in Hyper Terminal, then you just check the serial cable is working or not. Otherwise you just check the code with debugging mode in Mplab. If you want to see more details about debugging just see the videos in below link

  • How to Create & Debug a Project in Mplab using dsPIC30F.

General Information

  • For proper working use the components of exact values as shown in Circuit file. Use new components.
  • Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.
  • Use the exact value crystal shown in schematic.
  • More instructions are available in following articles,

dSPIC Evaluation Board

How to Interface UART with dsPIC Evaluation Board

Interfacing Keys with dsPIC30F4011.

User Manual for DSPIC30F4011 Evaluation Kit

Creating & Debugging a Project in MPLAB using dsPIC30F