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.

LED drive

Other Parts Discussed in Thread: MSP430F4250

How to drive 7-segment LED display by using MSP430F4250, we are using 4 digit(comon anode) 7 segment display. Our timer A setting as below:

{

WDTCTL = WDTPW + WDTHOLD; 
FLL_CTL0 |= XCAP18PF; 

TACTL = TASSEL_2 + MC_2 + TAIE + ID_3; 

_BIS_SR(LPM0_bits + GIE); 

}

and our LED setting as below:

#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A(void)
{
CurrentTickCount_A++;
if(CurrentTickCount_A >= 100)
{

CurrentTickCount_A=0;

int digits[4];
unsigned int n;
int i;

n=OnDispVal;
i=0;
//n=OnDispVal; //Here I am displaying changing value on LED (FNDs).

while(n)
{
digits[i]=n%10;

i++;
n=n/10;

}

fnd_display(digits[dis],dis);

dis++;
if(dis>=4)
{dis=0;}

}
}

Our problems are it can't display the changing value on LED and it may be because of timer interrupt service routine too fast? We try to change IDx(TACTL), but it not change the timing at all.

Thanks for helping.

  • How to properly (legibly) present source code: http://bit.ly/W4Fb6s

  • We can show the digit number, but it keep on looping inside the interrupt service routine and can't jump out to do my main routine task. Any suggestions? Thanks you.

  • Tong Chuan Keong said:
    Any suggestions?

    How about posting your code in a legible - ie, properly indented - form ?

  • #include <msp430x42x0.h>

    void main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    FLL_CTL0 |= XCAP14PF; // Configure load caps
    TACTL = TASSEL_2 + MC_2 + TAIE; // SMCLK, cont. mode, interrupt

    _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt

    OnDispVal = Findsensor();
    }

    #pragma vector=TIMERA1_VECTOR
    __interrupt void Timer_A(void)
    {
    CurrentTickCount_A++;
    if(CurrentTickCount_A >= 50)
    {
    CurrentTickCount_A=0;

    int digits[4];
    unsigned int n;
    int i;
    n=OnDispVal; //n=OnDispVal; //Here I am displaying 234 on FNDs.
    i=0;

    while(n)
    {
    digits[i]=n%10;
    i++;
    n=n/10;
    }

    switch(dis)
    {
    case 0:
    P5OUT = 0x0E;
    break;
    case 1:
    P5OUT = 0x0D;
    break;
    case 2:
    P5OUT = 0x0B;
    break;
    case 3:
    P5OUT = 0x07;
    break;
    }

    P2OUT = lup[digits[dis]];

    dis++;
    if(dis>=4)
    {dis=0;}
    }
    __bic_SR_register_on_exit(LPM0_bits); // Exit LPM3 on ISR exit
    }

    The purpose of this program is to take the sensor value-->Findsensor(); and display real time sensor value on the 7-segment LED.

    P5OUT is common Anode while P2OUT is 8 pins cathode. 

    Now the 7-segment LED can show the digit number, but it keep on looping inside the interrupt service routine-->__interrupt void Timer_A(void)

    and can't jump out to do my main routine task-->Findsensor(); 

    That mean it can't show the real time sensor value on the 7-segment LED display.

    Any body can help me on this? Thanks you.

  • Tong Chuan Keong said:
    Any body can help me on this?

    That would be more likely if you made the effort to post your code in a legible, properly indented,  form...

  • Andy Neil said:
    How about posting your code in a legible - ie, properly indented - form

    Andy, you know that the editor will swallow indentation spaces when you paste code from certain sources? After all, HTML by itself doesn't know indentation.

    But to answer the original question:
    The ISR doesn't clear the IFG bit that caused the interrupt. So the ISR is called over and over again, effectively freezing main.

    BTW:
    If possible, small code 'funclets' should be put directly into an ISR rather than calling them as sub-funciton. Funciton calls require saving quite a few registers on the stack even though it wouldn't be necessary otherwise. And ISRs should exit as fast as possible, avoiding everything that takes time.
    This also applies to divisions and modulo operations. These are sloooow.

    For a fast conversion of value to digits, there are two threads in this forum which even contain code that is based on additiosn and subtractions only. By magnitudes faster.
    Even
    a = x/10; y = x-(10*a);x=a;
    is much faster than
    y=x%10; x/=10;
    (only one division and one multiplication - which is even done in hardware if your MSP has a hardware multiplier)

  • Jens-Michael Gross said:
    Andy, you know that the editor will swallow indentation spaces when you paste code from certain sources? After all, HTML by itself doesn't know indentation.

    I do - which is why I posted a link earlier explaining how to do it!

  • Andy Neil said:
    I posted a link earlier explaining how to do it!

    Sorry, but the link points the URL for the forum reply, not to the tiny URL.. You probably overwrote the intended URL in the clipboard by the forum reply link before applying it to your post. ;)
    But well, you can copy the text itself and paste it into th eURL bar to get to the explanation.

    Anyway, your (quite exhaustive) explanation of how to post code lacks one thing: It is important that the text you paste into the E2E editor is plain ASCII text without any formatting information (font/bold/whatever). Else the editor will see this formatting and embed it into the later generated HTML code, overriding the default editor style - with the side-effect that leading spaces are swallowed (HTML standard).

    For a very short time, the forum editor did have a nice popup window for pre-formatted code that also did syntax highlighting, indenting etc. Configuring it was a bit difficult (the options were a bit unclear). Too bad that this has been removed again instead of improved.

  • Jens-Michael Gross said:
    the link points the URL for the forum reply, not to the tiny URL

    Hmmm - so it does!

    The text is correct -  http://bit.ly/W4Fb6s - but the link, as you say, goes to the reply form!

    So why did the OP not mention that the link didn't work...?

    Jens-Michael Gross said:
    It is important that the text you paste into the E2E editor is plain ASCII text without any formatting information (font/bold/whatever). Else the editor will see this formatting and embed it into the later generated HTML code, overriding the default editor style - with the side-effect that leading spaces are swallowed (HTML standard).

    OK;  I guess my source code always is plain ASCII text  (why would it be anything else?) .

    Jens-Michael Gross said:
    For a very short time, the forum editor did have a nice popup window for pre-formatted code that also did syntax highlighting, indenting etc. Configuring it was a bit difficult (the options were a bit unclear). Too bad that this has been removed again instead of improved.

    There is an ongoing discussion about that on the Suggestions & Feedback Forum:

    http://e2e.ti.com/group/helpcentral/f/263/t/199714.aspx

    It seems they are "working on it"...

     

     

  • I've added your note about plain ASCII text on that post.

  • Andy Neil said:
    (why would it be anything else?) .

    Depends on the editor you copy from.
    Even the standard windows text field can accept palin ASCII data and RTF data and HTML data, depending on its settings. If the text in clipboard contains formatting, it is accepted as-is. Unless you forbid inserting anything but plain text. Then the clipboard content is either refused or converted into plain text. Clipboard transfers can be really confusing.

**Attention** This is a public forum