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.

RE: MSP432P401R: How to trigger the ADC with a Timer

Other Parts Discussed in Thread: DAC161S055, LM4120

Thank you very much for your kind reply.
Now, I have generated PWW signal and I can see on oscilloscope. I have couple of questions more. Please guide me.

1) is there any formula to calculate timer period in Up mode configuration and duty cycle for PWM??
2) how can I calculate the sampling frequency ?? I am calculating it as SMCLK/(2^16-1)=(48e6/65535) and theoretical answer is 732 Hz but on oscilloscope I am just getting 45.9 Hz.
3) how can I synchronize the rising edge of PMW with Sample and hold of ADC and falling edge with conversion ??
I am going to attached my code also for your further consideration.
Many many thanks for your kind help. I am sorry if I am asking some basic questions also.




const Timer_A_UpModeConfig upModeConfig =
{
TIMER_A_CLOCKSOURCE_SMCLK, // Timer initialization by SMCLK Clock Source
TIMER_A_CLOCKSOURCE_DIVIDER_1, // ACLK/1 = ACLK=32KHz
65535, // Timer Period (2^15)
TIMER_A_TAIE_INTERRUPT_ENABLE, // Enable Timer ISR
TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE, // Enable Interrupt CCR0
TIMER_A_DO_CLEAR // Clear Counter
};

/* Timer_A Compare Configuration Parameter */
const Timer_A_CompareModeConfig compareConfig =
{
TIMER_A_CAPTURECOMPARE_REGISTER_1, // Compare and Capture register CCR1
TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE, // Disable CCR interrupt
TIMER_A_OUTPUTMODE_RESET_SET, // Compare Output Mode 7
8192 // Compare Value 8192 Period (2^13)
};

/* Timer_A PMW Configuration Parameter */
Timer_A_PWMConfig pwmConfig =
{
TIMER_A_CLOCKSOURCE_SMCLK,
TIMER_A_CLOCKSOURCE_DIVIDER_1,
65535, // Timer Period (2^15)
TIMER_A_CAPTURECOMPARE_REGISTER_1,
TIMER_A_OUTPUTMODE_RESET_SET, // Compare Output Mode 7
8192 // duty cycle 25%
};
  • Splitted from Threat ID

    In system_msp432p401r.c you have

    #define  __SYSTEM_CLOCK    3000000

    This configures the clock for MCLK and SMCLK to 3MHz

    So your formula is OK with SMCLK/(2^16-1)=(3e6/65535) = 45.77 Hz

    This is also the Period of the PWM in this case.

    As this is directly used to Sample and start the conversion this is already synchronized.

    With the configuration shown above the high phase of the PWM is used to sample and when going low the conversion is started and executed.

    Note: please be careful with using

    Timer_A_CompareModeConfig

    Timer_A_UpModeConfig

    and

    Timer_A_generatePWM

    structures and the corresponding function calls. They do both the same with different methods. Using both at the same time may does not result in what you want.

    Regards,

     Stefan

  • I got your answer. Actually, it is my theses to implement digital filters on MSP432P01R and for that I will use DAC161S055EVM to make it MSP432-DAC.

    My idea is that May be , I can design timing of ADC sampling and conversion in such a way that when ADC will finish conversion on rising edge of PMW , at same time this digital data should pass through from digital filter (FIR filter in my case) and should be transfer to DAC respectively.
    (I am trying to relate Upmode config here )
    For that, I will use SPI master configuration. This is the reason , I want to know exact rising and falling edge time so that I can synchronize DAC.

    But I will work on ADC part first then I will proceed further. If you have any better suggestion or any example which is related to my idea. Please present it to me. It will be really kind of you Sir.
    Many Thanks Sir for your all help and advices. I have a lot of regard for you.
  • Hi Hasan,
    you have a typical signal chain:
    - ADC data capture
    - Data processing
    - Data output
    First with the Timer you capture the data synchronized. Now you hand over the data to the processing part. For this you can use the interrupt to trigger taking the data from the CPU and process. Depending on the CPU load and response rate of input to output you can also use the DMA to collect a block of data before doing the processing.

    To output the data you once again need trigger signal with gives you a synchronization of the data and ensures that the data on the output of the DAC is updated in equi-distant time slices to avoid jitters.
    For this you can of course use the PWM signal for the ADC triggering also for the DAC input signal LDACB. You just need to ensure that the SPI is also sending the data in the right time slices for the next DAC sample.
  • Hi Stefan,

    I have done with ADC part with your help and it is working fine now. From last 2 days, I am trying to do SPI communication between DAC161s055evm and MSP432.
    In dac161so55 data sheet page 16 , it is written that data can be sent from PREREG TO DACREG by hardware and software both with LDAC command.

    1) can you please tell me the command to toggle the LDACB pin to send data from PREREG to DACREG ??
    2) and it is written in datasheet again that DAC will work with reference voltage but how can i supply Vref to DAC161s055 because it is connected with LM4120 and there is no discription how to start DAC161s055 from LM4120.

    Many thanks for your every reply.
  • Hi,

    great that the ADC code works.

    As you can see from the DAC161s055evm schematic the LDACB is connected to JD-5 which is Pin 36 on the MSP432 Lanchpad or P6.6 on the MSP432 Device - so you need to control P6.6 as digital output

    Regarding the reference i just can see that the Reference input of the DAC is hardwired to the LM4120 so that this does supply the reference voltage. I do not think that you have to do extra steps here but you may can ask that specific question in the forum for the ADC so to get the answer from the expert there.

    Regards,
    Stefan
  • Hi Stefan,
    More I am working and getting more issues day by day.
    I have two issues now and need your advice.

    1) I used SPI master increment example from driver library to do communication between msp432 and dac161s055 and it worked very well in start. But, now SDO port is not responpding anymore and there is no signal on it and it is P 1.7 (SDO or SOMI). I have changed nothing in my code. What can be the possibility for this problem??

    2) In dac161s055, there is 24 bit (3 byte) data communication and for asserting communication , SCLK should turn on for 24 clock cycles but in my case (using already mentioned example) I am getting just 8 clock pulses and which is not sufficient for my requirement. Please tell me how can I increase the clock cycles of SCLK in SPI communication?? Even though I tried to send 24 bit data but clcok cycles are not chnaging.

    Code is attached for below:

    const eUSCI_SPI_MasterConfig spiMasterConfig =
    {
    EUSCI_B_SPI_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
    24000000, // SMCLK = 24MHZ
    1000000, // SPICLK = 1 MHz
    EUSCI_B_SPI_MSB_FIRST, // MSB First
    EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT, // Phase
    EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW, // High polarity
    EUSCI_B_SPI_3PIN
    };
    /* Statics */
    static volatile uint_fast16_t resultsBuffer[UINT8_MAX];
    static volatile uint8_t resPos;
    static volatile uint8_t RXData = 0;
    static uint32_t TXData=0;

    /* Selecting P1.5 P1.6 and P1.7 in SPI mode */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
    GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);

    /* P 6.0 and P6.6 for CSB and LDACB */
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P6, GPIO_PIN0);
    MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P6, GPIO_PIN0);
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P6, GPIO_PIN6);
    MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P6, GPIO_PIN6);

    /* Enabling interrupts */
    SPI_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_SPI_RECEIVE_INTERRUPT);
    Interrupt_enableInterrupt(INT_EUSCIB0);
    Interrupt_enableSleepOnIsrExit();

    TXData = 0xFFFFFF;

    /* Polling to see if the TX buffer is ready */
    while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT)));

    /* Transmitting data to slave */
    SPI_transmitData(EUSCI_B0_BASE, TXData);

    //interrupt handler
    void EUSCIB0_IRQHandler(void)
    {
    uint32_t status = SPI_getEnabledInterruptStatus(EUSCI_B0_BASE);
    uint32_t jj;

    SPI_clearInterruptFlag(EUSCI_B0_BASE, status);

    if(status & EUSCI_B_SPI_RECEIVE_INTERRUPT)
    {
    /* USCI_B0 TX buffer ready? */
    while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_B_SPI_TRANSMIT_INTERRUPT)));

    RXData = SPI_receiveData(EUSCI_B0_BASE);

    /* Send the next data packet */
    SPI_transmitData(EUSCI_B0_BASE, ++TXData);

    /* Delay between transmissions for slave to process information */
    for(jj=50;jj<50;jj++);
    }

    }

    P:S: I am just new on embedded system side. So, may be my questions can be very basic.

    Many thanks for your kind reply.

    regards,

    Hasan
  • Hi,

    do you have further questions regarding this topic? If not, please select "Resolved" for the post that solved your issue so this thread can be closed out. If you have a different question, please select "Ask a related question" or " Ask a new question".
    Thanks a lot!

    Best regards,
    Stefan

**Attention** This is a public forum