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.

MSP430FR5949 Clock Speed

Other Parts Discussed in Thread: MSP430FR5949

Hello,

I am working on a project for a class and I am using an MSP430FR5949. One of the parts that I am working on is a siren so I'm trying to output a sine or sawtooth wave to a DAC and then to a class AB amplifier that I made and tested that it works. I was able to get a sine and a sawtooth wave out of my DAC and amplifier when I scoped it however without any delays it only outputs about 370 Hz. I'm using a lookup table with about 100 values to output my wave and so my frequency increases if I decrease the number of values in my lookup table however doing that also decreases the quality of my wave. Therefore, I tried to increase my clock speed to a higher frequency so that my program would run faster but for some reason it ended up decreasing my wave frequency to about 32 Hz. Here is my code that I used to set up the clock speed, am I missing something or doing something wrong? I also need to increase the clock speed because I am also trying to scan 3 ADCs very quickly in addition to outputting a siren on a speaker. Thank you very much, I appreciate all the help!

// Configure one FRAM waitstate as required by the device datasheet for MCLK
// operation beyond 8MHz _before_ configuring the clock system.
FRCTL0 = FRCTLPW | NWAITS_1;

// Clock System Setup
CSCTL0_H = CSKEY >> 8; // Unlock CS registers
CSCTL1 = DCORSEL | DCOFSEL_4; // Set DCO to 16MHz
CSCTL2 = SELS__DCOCLK;               //SMCLK --> DCO
CSCTL3 = DIVS__1; // Set all dividers
CSCTL0_H = 0; // Lock CS registers // Clock System Setup

  • Hi Hari, 

    I don't see any issues in the code you posted that could be causing the issue. How are you communicating with the DAC? Could this possibly be a communication issue that was thrown off by changing the clock speed?

    Would you mind posting the rest of your code using Syntax highlighter?

    Best regards, 
    Caleb Overbay

  • Hi Caleb,

    I'm communicating with the DAC through SPI and I can see the output wave when I scope it however I can't output it at higher frequencies. Here is the code that I am using. I was unable to copy and paste the syntax highlighter code it wouldn't insert the code with the colors for some reason. Thank you for your help!

    #include <msp430.h>

    volatile unsigned char TXDATA;

    int sawtooth[150] = {0x2,0x3,0x5,0x7,0x9,0xa,0xc,0xe,0xf,0x11,0x13,0x14,0x16,0x18,0x1a,
    0x1b,0x1d,0x1f,0x20,0x22,0x24,0x25,0x27,0x29,0x2b,0x2c,0x2e,0x30,0x31,0x33,
    0x35,0x36,0x38,0x3a,0x3c,0x3d,0x3f,0x41,0x42,0x44,0x46,0x47,0x49,0x4b,0x4d,
    0x4e,0x50,0x52,0x53,0x55,0x57,0x58,0x5a,0x5c,0x5e,0x5f,0x61,0x63,0x64,0x66,
    0x68,0x69,0x6b,0x6d,0x6f,0x70,0x72,0x74,0x75,0x77,0x79,0x7a,0x7c,0x7e,0x80,
    0x81,0x83,0x85,0x86,0x88,0x8a,0x8b,0x8d,0x8f,0x91,0x92,0x94,0x96,0x97,0x99,
    0x9b,0x9c,0x9e,0xa0,0xa2,0xa3,0xa5,0xa7,0xa8,0xaa,0xac,0xad,0xaf,0xb1,0xb3,
    0xb4,0xb6,0xb8,0xb9,0xbb,0xbd,0xbe,0xc0,0xc2,0xc4,0xc5,0xc7,0xc9,0xca,0xcc,
    0xce,0xcf,0xd1,0xd3,0xd5,0xd6,0xd8,0xda,0xdb,0xdd,0xdf,0xe0,0xe2,0xe4,0xe5,
    0xe7,0xe9,0xeb,0xec,0xee,0xf0,0xf1,0xf3,0xf5,0xf6,0xf8,0xfa,0xfc,0xfd,0xff};


    int sin[10] = {0x80,0xca,0xf9,0xf9,0xca,0x80,0x35,0x6,
    0x6,0x35,0x80};

    void SPI_DATA(unsigned int a);
    void SPI_TRANSFER(char TXDATA);
    int i = 0;


    int main(void)
    {
    WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

    // Configure one FRAM waitstate as required by the device datasheet for MCLK
    // operation beyond 8MHz _before_ configuring the clock system.
    //FRCTL0 = FRCTLPW | NWAITS_1;

    // Clock System Setup
    //CSCTL0_H = CSKEY >> 8; // Unlock CS registers
    //CSCTL1 = DCOFSEL_0; // Set DCO to 16MHz
    //CSCTL2 = SELS__DCOCLK;
    //CSCTL3 = DIVS__1; // Set all dividers
    //CSCTL0_H = 0; // Lock CS registers // Clock System Setup

    // Configure GPIO
    P2OUT |= BIT7;
    P2DIR |= BIT4 | BIT5 | BIT7; //P2.7 = dac cs
    P2SEL1 |= BIT4 | BIT5 | BIT6; //A1 CLK, SIMO, SOMI




    //PJSEL0 |= BIT4 | BIT5; // For XT1

    // Disable the GPIO power-on default high-impedance mode to activate
    // previously configured port settings
    PM5CTL0 &= ~LOCKLPM5;

    // Configure USCI_A0 for SPI operation
    UCA1CTLW0 = UCSWRST; // **Put state machine in reset**
    UCA1CTLW0 |= UCMST | UCSYNC | UCMSB | UCCKPH; // 3-pin, 8-bit SPI master
    // Clock polarity high, MSB
    UCA1CTLW0 |= UCSSEL__SMCLK; // ACLK
    UCA1BR0 = 0x00; // /2
    UCA1BR1 = 0; //
    UCA1MCTLW = 0; // No modulation
    UCA1CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
    //UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt
    //TXData = 0x1; // Holds TX data

    while(1)
    {
    //UCA0IE |= UCTXIE;
    //__bis_SR_register(LPM0_bits | GIE); // CPU off, enable interrupts

    for(i = 0; i < 10; i++){
    //__delay_cycles(30); // Delay before next transmission

    SPI_DATA(sin[i]); // Increment transmit data

    }
    }
    }

    void SPI_DATA(unsigned int a){

    unsigned int temp = a;
    unsigned int DAC = 0;

    temp = temp << 2; //shift 2 bits for DCs
    temp |= 0xF000; //control bits output A and B
    DAC = temp;
    TXDATA = DAC >> 8; //send MSB
    P2OUT &= ~BIT7; //set CS low 0111 1111
    SPI_TRANSFER(TXDATA);
    TXDATA = DAC; //send LSB
    SPI_TRANSFER(TXDATA);
    P2OUT |= BIT7; //set cs high

    }

    void SPI_TRANSFER(char TXDATA){
    while(!(UCA1IFG & UCTXIFG));
    UCA1TXBUF = TXDATA; // Transmit characters
    while(UCA1STATW & UCBUSY);
    //return UCA1RXBUF;
    }
  • Hi Hari,

    Is there are reason you're not using interrupts  and the STE(CS) to do the SPI transfers? I think you could gain some speed by making things interrupt based first. There are examples for how to do this in the TI Resource Explorer in CCS.

    Also,  you're using the SMCLK as the source for your SPI communication with no divider. This means that when you change the speed of the DCO, the SPI communication speed changes as well and 16MHz may be too high of a communication speed for your DAC and/or the MSP. This previous E2E post gives a good description of how to calculate the max SPI speed: SPI Unreliable at Speed on MSP430G2553.

    I would start with changing things to be interrupt based and go from there. 

    Best regards, 

    Caleb Overbay

  • Hi Hari,

    Have you made any progress on this issue that you'd like to share?

    Best regards,
    Caleb Overbay

**Attention** This is a public forum