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.

Compiler/MSP432P401R: Fastest way to index

Part Number: MSP432P401R

Tool/software: TI C/C++ Compiler

I am not sure if this belongs here or the compiler forum, but here goes. I am using the red launchpad to drive a 12 bit DAC as quickly as possible. I need to know the fastest way to get data out of my array and onto the GPIO ports. Here is what I have now:

/*
 * Program to control FET switches for bridge simulation
 * NO DAC!
 *
 * Ports used:
 * Port J: Pins 2 &3 - Crystal
 * Port 1: Pin 0: Red LED
 *
 * Port4: DAC 8 bit port
 * Port3:0
 * Strobe - active low
 * When pulled low and high data is latched into the input register and then the DAC register
 */
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>

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

void strobe(void);
volatile uint32_t ii;


int main(void)
{

    int i, delay;

    uint8_t msb[41] =    { 80, 76, 73, 70, 68, 67, 66, 63, 62, 60,
                           59, 59, 58, 57, 57, 56, 56, 56, 55, 55,
                           55, 54, 54, 54, 54, 54, 53, 53, 53, 53,
                           53, 53, 52, 52, 52, 51, 51, 50, 46, 43,
                           40};

    uint8_t lsb0[41] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        0};

    uint8_t lsb[41] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x80, 0x00, 0x00, 0x80, 0x00, 0xD0, 0x70, 0x00, 0xD0, 0x70,
                        0x00, 0xD0, 0xA0, 0x70, 0x30, 0x00, 0xE0, 0xB0, 0x80, 0x40,
                        0x20, 0x00, 0xB0, 0x60, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
                        0x00};

    /* Halting the Watchdog */
    MAP_WDT_A_holdTimer();

    //![Simple CS Config]
    /* Configuring pins for peripheral/crystal usage and LED for output */
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
                                                    GPIO_PIN3 | GPIO_PIN2, GPIO_PRIMARY_MODULE_FUNCTION);
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); // Main Red LED
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);

    MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN6);


    /* Just in case the user wants to use the getACLK, getMCLK, etc. functions,
     * let's set the clock frequency in the code. 
     */
    CS_setExternalClockSourceFrequency(32000,48000000);

    /* Starting HFXT in non-bypass mode without a timeout. Before we start
     * we have to change VCORE to 1 to support the 48MHz frequency */
    MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
    MAP_FlashCtl_setWaitState(FLASH_BANK0, 1);
    MAP_FlashCtl_setWaitState(FLASH_BANK1, 1);
    CS_startHFXT(false);

    /* Initializing MCLK to HFXT (effectively 48MHz) */
    MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
    //![Simple CS Config]

    /* Enabling MASTER interrupts */
    MAP_Interrupt_enableMaster();

    // Housekeeping
    //MSB
    P4DIR = 0xFF; // All port 4 are outputs
    P4OUT = 0;

    //LSB (top 4 bits)
    P5DIR = 0xFF;
    P5OUT = 0;

    P3DIR |= 0x01 ; // 3.0 is an out.
    P3OUT = 0x01; // turn on 3.0 (active low)

    while (1)
    {

        delay = 1;

        P4OUT = 255;
        strobe();

        // Delay to let the ADC catch up
        for (ii=0; ii<100; ii++);


        //Trigger
        MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
        MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);

        P4OUT = 255;
        strobe();

// This is the part that needs to be as fast as possible!!!!

        if (delay != 0)
        {
            for (i = 0; i<41; i++)
            {
                P4OUT = msb[i];
                P5OUT = lsb[i];
                strobe();
            }

        }

        P4OUT = 0;
        strobe();

        // Delay to let the ADC catch up
        // Long delay to cool the FET
        for (ii=0; ii<200000; ii++);

    } /* while*/

}

void strobe(void)
{
    // Do a strobe on 3.0
    P3OUT = 0x00;
    __delay_cycles(2);

    P3OUT = 0x01;
}


I am not an ARM assembly expert, so if there are any better data types or indexing schemes or levels of optimization I am willing to entertain them.

  • Hello Keith.

    The fastest way is in assembly. We really do not provide any example for ASM coding, but can surely check if there is some example on the forum or web for ARM ASM coding. But in C code, what you have done would be the method to get it out quickly.
  • Just for the record:

    I changed the indexers to register and enabled Global Optimization*.

    That took the time from the longest loop from 30 us down to 8! It also messed up my delay for loops, but I can live with that! 8^)

    *I maxed the speed/size optimization slider to the speed side.

**Attention** This is a public forum