AnsweredAssumed Answered

BF506F EZ-KIT Push Botton (PB0) INTERRUPT GENERATION

Question asked by odemirci on Nov 11, 2011

Hello,

 

I am using visialDSP++5.0 Update9.1 and BF506F EZ-KIT-LITE Demo board. I like to write a code so that when I press the PB0 (Push Botton) then I will generate a peripheral interrupt. I am enclosing the whole code here. The only problem is that when I press the PB0 it generates many interrupt eventhough I set the PORTFIO_EDGE. Any suggestions please?

 

Osman Demrci

TEP Electric

 

/*****************************************************************************
* myfirst.asm
*****************************************************************************/
// PF0 --> LED2
// PF1 --> LED3
// PF2 --> LED4
// PF3 --> PB0
// PF4 --> PB1

     
#include <defBF506F.h>
#include <defBF50x_base.h>

/* Mark the beginning of a logical section mirroring an array of contiguous
   locations in processor memory. Statements between one '.SECTION' and the
   following '.SECTION' directive comprise the contents of a section. Here,
   we place the global symbol '_main' and the associated code into the
   'program' section.*/
.SECTION program;

/* The .ALIGN directive forces the address alignment of an instruction or
   data item. Here, ensure the first element of the section is aligned.*/
.ALIGN 4;

/* Set the scope of the '_main' symbol to global. This makes the symbol
   available for reference in object files that are linked to the current
   one. Use '.EXTERN' to refer to a global symbol from another file.*/
.GLOBAL _main;

 

/* Declare the '_main' symbol. */
_main:

// START: SET BF506F PINs   
  P0.L=LO(PORTFIO_DIR);  // 0xFFC0 0730:GPIO Direction Registers
  P0.H=HI(PORTFIO_DIR);  // 0:input, 1:output
  R0.L=0x0007;           // PF0=LED2,PF1=LED3,PF2=LED4 is outputs
  W[P0]=R0.L;            // PF3=PB0, PF4=PB1 and rest are inputs

  P0.L=LO(PORTFIO_INEN); // 0xFFC0 0740:GPIO Input Enable Registers
  P0.H=HI(PORTFIO_INEN); // 0:Input Buffer Disabled, 1:Input Buffer Enabled
  R0.L=0x0018;           // PF3 and PF4 are buffered inputs
  W[P0]=R0.L;            // PF3==PB0 and PF4=PB1
                       
  // set port f polarity register
  // 0=rising edge, 1=falling edge
  P0.L = LO(PORTFIO_POLAR); // 0xFFC0 0734
  P0.H = HI(PORTFIO_POLAR);
  R0.L = 0x00000;
  W[P0] = R0.L;
 
  // set port f sensetivity register
  // 0=Level, 1=Edge (if not edge then you get interrupt all time)
  P0.L = LO(PORTFIO_EDGE);
  P0.H = HI(PORTFIO_EDGE);
  R0.H = 0x00008; // PF3 is edge sensetive
  W[P0] = R0.L; 
 
// END: SET BF506F PINs  

 

 

// START: setting PortF_A interrupt
P0.L = LO(PORTFIO_MASKA);  // 0xFFC0 0710
P0.H = HI(PORTFIO_MASKA);
R0.L = 0x0008;  // (PF4)PB1=0x0010, (PF3)PB0=0x0008
W[P0] = R0.L;

P0.L = LO(SIC_IMASK0);
P0.H = HI(SIC_IMASK0);
R0.L = 0x0000;  
R0.H = 0x2000;   // Set Bit29=1 yani enable Portf_a interrupts
[P0] = R0;

P0.L = LO(SIC_IAR3);
P0.H = HI(SIC_IAR3);
R0.L = 0x0000;  
R0.H = 0x0060; //(pins20 to 23)=6 ise IVG13(EVT13) priority selected
[P0] = R0;

// initiate interupt
P1.L = LO(IMASK);  // IMASK 0xFFE0 2104: Interrupt Controller
P1.H = HI(IMASK);
R0.L = LO(portf_a_isr);
R0.H = HI(portf_a_isr);
[P1 + EVT13 - IMASK] = r0;  // [p1 + 0xFFE0 201C - 0xFFE0 2104]
R0 = [P1];
BITSET(R0, 13); // Enable IVG13 priority interrupt
[P1] = R0;
// END: setting PortF_A interrupt

 

 

// START: CORE TIMER INTERRUPT SETUP  
// Register service routine at EVT6 and unmask interrupt
P1.L = LO(IMASK);  // IMASK: Interrupt Controller
P1.H = HI(IMASK);
R0.L = LO(core_timer_isr);
R0.H = HI(core_timer_isr);
[P1 + EVT6 - IMASK] = R0;  // EVT6: Event Vector Register 0xFFA0 0182
R0 = [P1];
BITSET(R0, bitpos(EVT_IVTMR));
[P1] = R0;
// TIMER SETUP
// Prescaler = 50, Period = 10,000,000, First Period = 20,000,000
P1.L = LO(TCNTL); // 0xFFE0 3000: Core Timer Control Register
P1.H = HI(TCNTL);
R0 = 50 (z);
[P1 + TSCALE - TCNTL] = R0;
R0.L = LO(1000000);
R0.H = HI(1000000);
[P1 + TPERIOD - TCNTL] = R0;
R0 <<= 1;
[P1 + TCOUNT - TCNTL] = R0;
// start in auto-reload mode
R0 = TAUTORLD | TMPWR | TMREN (z);
[P1] = R0;
// END: CORE TIMER INTERRUPT SETUP


  r1=0;
  r2=0;
  r3=0;

 

_main.forever:

jump _main.forever;
_main.end:

 

// START: CORE TIMER INTERRUPT SERVICE ROUTINE
core_timer_isr:
[--sp] = astat;
[--sp] = (r7:7, p5:5); // push used registers

  R1+= 1;
  P5.L=LO(PORTFIO_TOGGLE); // 0xFFC0 070C
  P5.H=HI(PORTFIO_TOGGLE);
  R7.L=0x0004;       // W-1-to-toggle: LED2=0x0001, LED3=0x0002, LED4=0x0004
  W[P0]=R7.L;

ssync;                  // sync system
(r7:7, p5:5) = [sp++];  // pop registers
astat = [sp++];
RTI;                   /* return from interrupt */
core_timer_isr.end: 
// END: CORE TIMER INTERRUPT SERVICE ROUTINE

 


// START: PORTF_A INTERRUPT SERVICE ROUTINE  
portf_a_isr:
//[--SP] = RETI;
[--sp] = astat;
[--sp] = (r7:7, p5:5); // push used registers
  // clear interrupt request on GPIO pin PF3
  // no matter whether used A or B channel
  P5.L = LO(PORTFIO_CLEAR);
  P5.H = HI(PORTFIO_CLEAR);
  R7.L = 0x0008;  // clear PF3
  W[P5] = R7.L;

  // place user code here
  R2+= 1;
  P0.L=LO(PORTFIO_TOGGLE); // 0xFFC0 070C
  P0.H=HI(PORTFIO_TOGGLE);
  R0.L=0x0002;       // W-1-to-toggle: LED2=0x0001, LED3=0x0002, LED4=0x0004
  W[P0]=R0.L;
   
ssync;                 // sync system
(r7:7, p5:5) = [sp++]; // pop registers
astat = [sp++];
//RETI = [SP++];
rti;                   // return from interrupt
portf_a_isr.end:
// END: PORTF_A INTERRUPT SERVICE ROUTINE

Outcomes