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.

CCS/MSP432P401R: Applying Timer into the Multiplexer

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hi there, 

I am creating a system that can control each LED on MSP432P401R and record how long each LED is on. So far I have found a way to control each LED with BTN1, but I still have to apply systick to record the time duration. I think it has something to do with SysTick_getValue() but when I tried to apply it into my system it just didn't work.

I have copied my code down below, please help me out! Thanks!

Keith.

/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>

/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>

int count = 0;
void delay_ms(uint16_t ms);

int main(void)
{
/* Stop Watchdog */
MAP_WDT_A_holdTimer();
/* Configuring P1.0 as output and P1.1 (switch) as input */
MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
/* Configuring P1.1 as an input and enabling interrupts */
MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
MAP_GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN1,
GPIO_HIGH_TO_LOW_TRANSITION);
MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1);

SysTick_enableModule();
SysTick_setPeriod(30000); /* Frequency of MCLK is 3MHz, therefore the counter rolls over every 0.01sec */

MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);
MAP_Interrupt_enableInterrupt(INT_PORT1);

/* Enabling MASTER interrupts */
MAP_Interrupt_enableMaster();
while (1)
{

}
}

void PORT1_IRQHandler(void)
{
uint32_t status;
uint32_t start, end, a, b, c, d; /* a, b, c, d represent the time duration for each LED */
start=0; /* the start value has to be initialized otherwise there will be an error for the first channel 1 calculation */
status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P1);
MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, status);

if (status & GPIO_PIN1)
{
count++;
if (count == 1)
{
end = SysTick_getValue();
a = end - start;
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2,
GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);

delay_ms(500);
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
start = SysTick_getValue();
}
if (count == 2)
{
end = SysTick_getValue();
a = end - start;
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2,
GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
delay_ms(500);
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0);
start = SysTick_getValue();
}
if (count == 3)
{
end = SysTick_getValue();
a = end - start;
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2,
GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
delay_ms(500);
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1);
start = SysTick_getValue();
}
if (count == 4)
{
end = SysTick_getValue();
a = end - start;
count = 0;
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2,
GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
delay_ms(500);
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN2);
start = SysTick_getValue();
}
}

}
void delay_ms(uint16_t ms)
{
uint16_t delay;
volatile uint32_t i;
for (delay = ms; delay > 0; delay--)
{
for (i = 300; i > 0; i--)
{
}
}
}

  • Hi Keith,

    Does the SysTick_getValue() return anything other than 0?

    If you setup a breakpoint after initializing the SysTick and examine the STCSR STCVR and STRVR registers?

  • Dennis,

    I checked the expression, valuable and disassembly windows and there was no returned value at all. 

    What am I supposed to see if I set up a breakpoint after initializing the SysTick and examine the registers that you mentioned?

     

  • I always enable the interrupt and use my own counter:

    // Configure SysTick
        MAP_SysTick_enableModule();
        // 48M = 1 sec, 4.8M = 100ms, 480000 = 10ms...
        MAP_SysTick_setPeriod(48000); // Every 1 msec
        MAP_SysTick_enableInterrupt();

    void SysTick_Handler(void)
    {
        Millis++;

        if (Millis%10000 == 0)
        {
            // Every 10 seconds
            MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);

        }
    }

  • I know exactly what you are doing here but I don't see how this will apply to my situation. I don't really need system clock for interrupt. In my case I need to have my GPIO for interrupts, and the clock is used to record the duration between I click the button. In other word, I use the clock just to record the time. The clock will not have any impact on the input and output at all.

  • SysTick_getValue returns something for me. You have to look in R0, since the result is thrown away along with end and a, since they're never used.

    I suggest you move all those local variables outside the ISR and maybe make them "volatile" for good measure.

  • 1. your code is hard to read;

    2. looping around in the isr makes no sense;

    3. I think you can re-arrange the code: the isr would return a flag (and potentially time), to be processed in the main loop.

    4. consider the use of SysTick->VAL for faster return of value -> depending on your header file used.

    5. looks like you need "start" to be static.

  • Hi Keith,


    I haven’t heard from you for some time now, so I’m assuming you were able to resolve your issue.
    If this isn’t the case, please click the "This did NOT resolve my issue" button and reply to this thread with more information.
    If this thread locks, please click the "Ask a related question" button and in the new thread describe the current status of your issue and any additional details you may have to assist us in helping to solve your issues.


  • Hi Dennis,

    I am still having a hard time trying to figure out this issue. I think the biggest problem for me right now is that I can't access the variables in the expression window or disassembly. I thought I could find the value of a whether it is running or not because I initiate it. Unfortunately this is just not the case. 

    Could you run the code and let me know where I can find the readings of the variables? If I can access those numbers I think I'll be able to figure out what goes wrong. 

    Keith

  • > I suggest you move all those local variables outside the ISR and maybe make them "volatile" for good measure.

  • Do you know how I can read the variables? I tried to find them on expression but they weren't there at all

  • If your variables are declared outside the ISR you should be able to type their names into the Expressions viiew.

    If they are (still) declared inside the ISR, they don't exist since the compiler removed them.

  • Hi Keith,

    As you have already discovered, the local variable banana is local to func1,  like wise apple and pear are local to main.

    If you hit a breakpoint in func1, only banana is visible and reverse is true when you hit a breakpoint in main.

    For example:

    Now if you make a variable "global", as Bruce has suggested and like I did by adding peach outside of either main or func1, it is visible as long as you set a breakpoint in this file.

  • Hi Dennis,

    I am wondering if you have to type all the variables in your expression window, or they can automatically show up when your program is debugged?

  • Hi Keith,

    You have to type the variables you wish to view in the expression window.  They don't appear automatically.

  • Hi Dennis,

    Thanks, I can see the variables now, but everytime I click the button the variables are incredibly large like ten thousands or something like that. I wonder when I use getvalue() do I return the time or the count number?  

  • Hi Keith,

    If you followed Keith's example and are generating a tick every 1msec, then it is possible to see large values.  Example 10sec = 10,000 msec.

    Are you measuring the time the LED is on or the time from when it goes from ON to OFF and ON again?

  • Hi Keith,

    I'll assume you were able to resolve your issue so I will go ahead and close this thread.
    If this isn’t the case, please click the "This did NOT resolve my issue" button and reply to this thread with more information.
    If this thread locks, please click the "Ask a related question" button and in the new thread describe the current status of your issue and any additional details you may have to assist us in helping to solve your issues.


**Attention** This is a public forum