This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: MSP432P401R
Hello,
I want to count number of pulses of encoder on high to low edge triggered on port pin ( rising edge) using MSP432. I have taken variable "a" in interrupt. when interrupt is occurred on rising edge my count is increment by 1. but my interrupt is triggered on both edge. i got pulses 1000 as i expected is 500 only.
The program is shown below:-
int a = 0;
void main(void)
{
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer
P6->DIR &= ~BIT0; // set P6.0 as a input direction
P6->REN = BIT0; // Enable pull-up resistor
P6->IFG &= ~ BIT0; // P1.4 IFG cleared
P6->IES &=~ BIT0; // high to low
P6->IE |= BIT0; // P1.4 interrupt enabled
// Enable Port 1 interrupt on the NVIC
NVIC->ISER[1] = 1 << ((PORT6_IRQn) & 31);
// wake up on exit from ISR
SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk;
for(;;){}
}
// Port 1 interrupt service routine
void PORT6_IRQHandler(void)
{
if(P6IFG & BIT0)
{
a=a+1;
}
P6->IFG &= ~BIT0;
}
please tell me where i am going wrong in code??
Thanks
Hi,
My issue is resolved. now i want to triggered 2 port interrupt at a time because my encoder has 3 output pins A,B &Z which is connected to port pin.
My code is below:-
#include "msp.h"
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Standard Includes */
#include <stdint.h>
#include <string.h>
int a,b;
float count;
float count2;
int main(void)
{
// Hold the watchdog
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD;
// Configuring P1.0 as output and P1.1 (switch) as input with pull-up
// resistor. Rest of pins are configured as output low.
// Notice intentional '=' assignment since all P1 pins are being
// deliberately configured
P6->DIR = ~BIT0;
P3->DIR = ~BIT2;
P6->IES = BIT0; // Interrupt on high-to-low transition
P3->IES = BIT2; // Interrupt on high-to-low transition
P6->IFG = 0; // Clear all P1 interrupt flags
P3->IFG = 0; // Clear all P1 interrupt flags
P6->IE = BIT0; // Enable interrupt for P1.1
P3->IE = BIT2; // Enable interrupt for P1.1
/* Configuring interrupt priorities and setting the priority mask to 0x40 */
MAP_Interrupt_setPriority(INT_PORT6, 0x00);
MAP_Interrupt_setPriority(INT_PORT3, 0x20);
// Enable Port 1 interrupt on the NVIC
NVIC->ISER[1] = 1 << ((PORT6_IRQn) & 31);
NVIC->ISER[2] = 1 << ((PORT3_IRQn) & 31);
// Terminate all remaining pins on the device
P2->DIR |= 0xFF; P2->OUT = 0;
P4->DIR |= 0xFF; P4->OUT = 0;
P5->DIR |= 0xFF; P5->OUT = 0;
P1->DIR |= 0xFF; P1->OUT = 0;
P7->DIR |= 0xFF; P7->OUT = 0;
P8->DIR |= 0xFF; P8->OUT = 0;
P9->DIR |= 0xFF; P9->OUT = 0;
P10->DIR |= 0xFF; P10->OUT = 0;
// Configure Port J
PJ->DIR |= (BIT0| BIT1 | BIT2 | BIT3);
PJ->OUT &= ~(BIT0 | BIT1 | BIT2 | BIT3);
// Enable PCM rude mode, which allows to device to enter LPM3 without waiting for peripherals
PCM->CTL1 = PCM_CTL0_KEY_VAL | PCM_CTL1_FORCE_LPM_ENTRY;
// Enable global interrupt
__enable_irq();
for(;;){}
}
/* Port1 ISR */
void PORT6_IRQHandler(void)
{
// Toggling the output on the LED
if(P6->IFG & BIT0)
{
a=a+1;
count=a*(0.001);
}
P6->IFG &= ~BIT0;
}
/* Port1 ISR */
void PORT3_IRQHandler(void)
{
// Toggling the output on the LED
if(P3->IFG & BIT2)
{
b=b+1;
count2=a*(0.001);
}
P3->IFG &= ~BIT2;
}
the value '"a" is increment but value"b" shows 0.why??
please give example code for 2 interrupt triggered at a time and how to set priority???
**Attention** This is a public forum