43oh

Newbie having problems with interrupts and inputs.

Recommended Posts

@@bobnova

if(value == 0x40){ digit1=0;  }
//if(value == 0x79){ digit1=1; P2OUT ^=BIT4;  } //0x79   0xb01111001
//if(value == 0x24){ digit1=2;    } // 0x24   0xb00100100

this is where my problem is.

I disabled this and toggled P2.2 or bit 4 and i get the same results as you in my O scope.!!!!
Now the question is, where would i do my "if P1IN = Something then digit1=number"? should i do it in the forever loop or in the interrupt itself?
Share on other sites

I think I would probably do it in the loop, but that's mostly just because I've been told to keep ISRs as short and fast as possible. Given a 4KHz input you have some time in there so it probably doesn't matter too much, unless there is something special about being inside an ISR that I'm not aware of.

I'd set value to P1IN inside the ISR, and put some code inside the loop that looks to see if value is anything but some number you know it won't get from the input (0xFF, for instance). If it is, then the loop code can figure out what the digit is, and then set value to 0xFF so it knows not to do it again until the ISR has fired and change it.

Whether this is the best way or not I've no idea, but it's where I would start personally.

You'd save some RAM if digit was the only global variable and value was only used inside the ISR, for whatever that's worth.

Saving one byte probably won't matter much, there's another 511 where that one came from after all.

Share on other sites

```while(1) //Loop forever
{
if(flag1 == 1)
{

if(value == 0x40){digit1=0;}
if(value == 0x79){digit1=1; P2OUT ^=BIT4;}
if(value == 0x24){digit1=2;  }

//value=0;
flag1 = 0;
}

}
}

// Port 2 interrupt service routine
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
{

value=P1IN;
flag1=1;

P2IFG &= ~BIT2 ; // P1.4 IFG cleared

}

```

im outputting 0x79 which corresponds to digit 1 on the 7 segment display. if the "P2OUT ^= BIT4;" is inside that if statement my led never toggles meaning that the P1IN value is never 0x79. if i put the "P2OUT ^= BIT4" outside the if statements my LED toggle so i know its working.. Any ideas to check if my P1IN equals something? or should i do it byte by byte?

Share on other sites

I would make sure the wiring is correct before I went too far. 0x79 is = 0b01111001, so pin P1_0 high, 1_1 and 1_2 low, then 3/4/5/6 high, then 1_7 low.

If you can measure your input pins with a multimeter and that's what you read, then I'm stumped as to why it isn't triggering in your code.

Share on other sites

@@bobnova, Yes thats exactly what im showing when i pause the code.

Another question i had is that since i have 2 digit displays, can i use the same port for 2 interrupts?

Share on other sites

Same port or same pin?

Share on other sites

You should be able to, kick the interrupt off by checking which flags are set, that will tell you (and it) which pin triggered the interrupt.

EDIT:

Sneaky hidden page.

What he said.

Same port, yes.

Same pin, no (or at least, much harder).

Share on other sites

@@bobnova. @@abecedarian yeah this is what i did

#pragma vector=PORT2_VECTOR
__interrupt void Port_2A(void)
{

if(P2IFG & BIT2) {
flag1=1;
value=P1IN;
P2IFG &= ~BIT2;
}
if(P2IFG & BIT1) {
flag2=1;
P2IFG &= ~BIT1;
}

seems to work fine.

I still need a way to check all 7 inputs in port one and match them to a set pattern to read digits 0-9 ;/
Share on other sites

I don't know why the matching isn't working. I haven't actually done it myself before but that matches what I've read in the datasheet and such.

Have you checked the value of value via the debug?

Something that might be interesting to try is a very small delay at the beginning of the ISR. Maybe the P2_2 input circuitry is firing before the P1_x bits?

Where exactly are the signal wires connected on the LED setup? Before or after the current limiting bits for the LEDs? It should be working however it is, but I was thinking that maybe if it's before the current limiting their LOW state is higher than P2_2's LOW state and because of that it hits the trigger point sooner.

I'd add a _delay_cycles(50) right at the beginning of the ISR to give P1_x 50

Share on other sites

So... you need to read 7 pins and make a dual 10 digit display representing the states of those pins, or something else is making the display and you need to read it??

Goal.- read and interpret a dual 7 segment LED display with 10 pins.

I'm newer than @@bobnova despite other evidence suggesting otherwise so....

Seems you'd be able to (obviously with protection circuitry) detect the 'going high' or 'going low' state of a digit's anode or cathode, enter an interrupt vector and then stop interrupts, read the state of that digit's segments into a global, volatile array and set a flag, then return to main, process the flag and volatile, enable interrupts, and keep going.

edit-

In quick retrospect, my idea wouldn't work since it would require the anode or cathode to change. What might be happening is you're having an issue with nested interrupts since you're polling a whole Port and not a pin, so multiple interrupts, which would happen if multiple segments change, would stack up and have to unroll to process?

Share on other sites

@@bobnova, the delay helped a bit, I have move on to check every bit instead of the whole port at the same time. But i dont think this is efficient at all,

if(State_A==0 && State_B==0 && State_C==0 && State_D==0 && State_E==0 && State_F==0 && State_G==1){digit2=0;}

Im not sure if this method will take longer than creating an array and reading it in a for loop?

I also changed my interrupts and disabled the opposite interrupt after one is triggered for example:

interrupt 1 is triggered

{

disable interrupt 1

enable interrupt 2

}

interrupt 2 is triggered

{

disable interrupt 2

enable interrupt 1

}

seems to work great!! my only problem now is displaying the correct number that i am reading for example, id the LED is displaying 78

my monitor would show something like this:

78

78

78

78

778

78

78

780

78

780

78

78

78

maybe is a timing issue?

@@abecedarian, the goal is to read a 2 digit, 7 segment LED display with only 10 pins. 2 of those pins are driver pins, the other 8 control the 7 segments and a decimal point.

Thank for all of you guys' help!!

seems im getting closer to having this done.

PS. If i store digit1 and digit2 into variables lets say x and y, could i send these 2 variables to another msp430? or even another MCU like the C2000 via SCI or any other communication protocol?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
• Blog

• Activity

×
• Create New...