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.

MSP430F5529: Variable issue

Part Number: MSP430F5529


Hi team,

Here's an issue from the customer may need your help:

When using timer_a, TA0CCR0 is set to 9. Customer want to set a variable n, and every time the counter counts to 9, n adds 1. How to set it? Could you help resolve this case? Thanks.

Best Regards,

Cherry

  • Hi Cherry,

    I give you a code example for you to refer: MSP430F55xx_ta0_02.c (ti.com).

    You need to change:

    1. change TA0CCR0=9

    2. Delete  the code "P1OUT ^= 0x01", and add you variable n here. When TIMER0_A0_ interrupt, n adds 1.

    Best Regard

    Joe

  • Hi Joe,

    Thanks for your help!

    add you variable n here

    The n here doesn't seem to work in the main program. For example, if the interrupt program uses n++ to count, it is expected that the timer can be turned off from n to 9, but the test found that there was actually always an output and Timer Awas always working.

    Here's a similar question from one customer: https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1081103/msp430f5529-how-to-turn-off-the-interrupt-of-timer-a

    What they want to design is a program that assigns the data stored in flash to the array, and then outputs an array value at a timer interrupt. But because the data is too large, the array defined in ccs cannot be stored at once, so they want to return a value to the main program when the timer accumulates interrupts to a certain number of times, with this feedback value to turn off the interrupt rewrite array and then repeat the output process.

    Thanks and regards,

    Cherry

  • Hi Cherry,

    I define n in the function: __interrupt void Timer_B (void), when n add to 9, P1.0=1, my program run to here.

    you can change while(1) and add timer output here. you can try this, but I am not sure it will meet you requirements.

    Best regards

    Joe

  • Hi Joe,

    Thanks.

    They are confused about the timer_b and the timer_a used here at the same time?   The have used timer_a to count and output.

    Also, may I know where is the _interrupt void Timer_B (void) interrupt function defined?

    Thanks and regards,

    Cherry

  • Hi Cherry,

    The code above is just an example, and the customer can use TimerA, they don't need TimerB.

    of course, TimerA and TimerB can used at the same time.

    the _interrupt void Timer_B (void) interrupt function defined in the msp430f5529.h file.

    you can open declaration from this code: #pragma vector = TIMER0_A0_VECTOR, it turn to msp430f5529.h

    Best regard

    Joe

  • Hi Joe,

    Thanks for your help again!

    They want to design a program that assigns the data stored in flash to the array, and then outputs an array value at a timer interrupt. But because the data is too big, the array they defined in ccs seems to be unstowed at once, so they want to have the timer count n, and when n=9, the main program can turn off the timer by listening on this n value. Rewrite the array and turn on the timer output. The customer used the volatile definition and now find that the value of n in memory can be accumulated, but since the main function does not loop through the value of n, the main function cannot reset the output array even though the value of n changes in the subfunction.

    Or is there any way in ccs to increase the capacity of an array? The unsigned short a[3000] array that define now can only put up to 3000 data, and it will report an error when gets larger.

    Thanks and regards,

    Cherry

  • Hi Cherry,

    1. Can you check where you define the n? you need define it as a global variables(Outside the main function). 

    2. in the main function, you need open the interrupt: _bis_SR_register();  then add you function here(turn off timer), at last, open the LPM0.

    like this. FYI

    Best Regard

    Joe

  • Hi Joe,

    They've done some attempts as above, the value of the array m was replaced at n=9, but the program above did not take effect, and it was detected that the counter was still working, and the array m was not replaced. The main function and interrupt program are as below:

    Thanks and regards,

    Cherry

  • > TA0CTL |=MC__STOP;

    This doesn't stop the timer (since MC__STOP == 0). Try instead:

    > TA0CTL &= ~MC_3;   // MC=0 to stop timer

  • Hello Bruce,

    Thanks for your help. It still don't work.

    The customer's program is as follows:

    Two four-bit, one-dimensional arrays m and M are defined, with each interrupt trigger output m0 to m3 from the m array first, where the four values are completed, and the customer wants to stop the interrupt and assign the value from the M array to m. Then continue to output the new m0 to m3.

    Thanks and regards,

    Cherry

  • Hi,

    May I know is there any update?

    Thanks and regards,

    Cherry

  • Hi Cherry,

    the value of the array m was replaced at n=9, but the program above did not take effect, and it was detected that the counter was still working, and the array m was not replaced

    So the data m[i] can replaced or not?  you can add TA0CTL &= ~MC_0 as Bruce said to see if timer could stop.

    I have no board for this debug at this time, maybe I can check it later.

    Best regard 

    Joe

  • In the ISR, the timer interrupt is disabled, so there's no reason you couldn't copy M[] to m[] (immediately) in the "if(k==4)" block.

    I should point out that 9 is a very small number to put in TA0CCR0 (clocked with SMCLK). The ISR can't complete in that amount of time, so it will run continuously, and it will never return to main(). Moreover, the time spacing between the bits won't be maintained. Where does the number 9 originate?

    Can you describe the overall goal? From the original question, it seems that you want to copy a Flash block to a RAM block so you can output it. Is there a reason it can't be sent directly from Flash?

  • Hi Joe and Bruce,

    Sending directly from flash causes d=*p and then output d to cause the length of time of each bit of data to be at an error with the length originally set. For example, if the output was 0.5 ms, the read and output from flash would be around 0.67 ms.

    Add this sentence TA0CTL &= ~MC_0, it looks like the timer is not paused. Can you provide a complete routine on how to pause an interrupt? For example, when an interrupt program occurs n=100 times, causes the timer, interrupt, to pause until the value of n is cleared.

    Thanks and regards,

    Cherry

  • >TA0CTL &= ~MC_0

    >>This doesn't stop the timer (since MC__STOP[==MC_0] == 0). Try instead:

    >>> TA0CTL &= ~MC_3;   // MC=0 to stop timer

    Stopping the timer will stop new interrupts until some other action is taken (i.e. the timer is started again). There could be one pending interrupt which would trigger after you return from the ISR. To prevent this, add:

    > TA0CCTL0 &= ~CCIFG;  // Clear possible pending CCR0 interrupt

**Attention** This is a public forum