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: How can read PWM adc from adc12?

Other Parts Discussed in Thread: MSP430F5529

Dear all,

I want to read PWM adc value in pwm high triggrt moment. 

I use TA2_2 to output PWM. Now I want to read adc value when PWM high trigger moment?

How should setting? (on below is my setting, but not useful)

---- PWM ----

GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN5);

control_pilot_pwm_params.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
control_pilot_pwm_params.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_8;
control_pilot_pwm_params.timerPeriod = PWM_TIMER_PERIOD;
control_pilot_pwm_params.compareRegister = PWM_COMPARE_RESGISTER;
control_pilot_pwm_params.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;
control_pilot_pwm_params.dutyCycle = dutycycle;

---  ADC12 ---

GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN4);

/* Initialize the ADC12_A Module */
ADC12_A_init(ADC12_A_BASE,
ADC12_A_SAMPLEHOLDSOURCE_SC,
ADC12_A_CLOCKSOURCE_ADC12OSC,
ADC12_A_CLOCKDIVIDER_1);

ADC12_A_setupSamplingTimer(ADC12_A_BASE,
ADC12_A_CYCLEHOLD_96_CYCLES,
ADC12_A_CYCLEHOLD_4_CYCLES,
ADC12_A_MULTIPLESAMPLESDISABLE);

/* Configure Memory Buffer */
ADC12_A_configureMemoryParam config_param = {0};
config_param.memoryBufferControlIndex = ADC12_A_MEMORY_0;
config_param.inputSourceSelect = ADC12_A_INPUT_A4;
config_param.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
config_param.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
config_param.endOfSequence = ADC12_A_ENDOFSEQUENCE;

ADC12_A_configureMemory(ADC12_A_BASE,
&config_param);

ADC12_A_setResolution(ADC12_A_BASE,
ADC12_A_RESOLUTION_12BIT);

ADC12_A_enable(ADC12_A_BASE);

  • Hi Weihuang,

    Actually, MSP430F5529 can use Timer to trigger ADC sampling, you can use this register to control the sampliny source:

    And you can find the trigger source in datasheet:

    Then you can refer those example code:

    https://dev.ti.com/tirex/explore/node?node=ACnpdkh9h39muQoWLY8rUg__IOGqZri__LATEST

    Thanks!

    Best Regards

    Johnson

    Best Regards

    Johnson

  • Hi Johnson,

    My PWM output is use P2_5/TA2_2 (1kHZ and 20% duty-cycle) and want to capture adc on high pluse.

    According your information, I need init TA0_1 to 1kHz frequency. Is right?

    Then set ADC12 clock source to ADC12_A_CLOCKSOURCE_SMCLK and sampleHoldSignalSourceSelect to ADC12_A_SAMPLEHOLDSOURCE_1?

    Is that setting can reach my goal?

    My code:

    --- Timer setting ---

    //Start timer in continuous mode sourced by SMCLK

    Timer_A_initContinuousModeParam initContParam = {0};

    initContParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;

    initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; 

    initContParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;

    initContParam.timerClear = TIMER_A_DO_CLEAR;

    initContParam.startTimer = false;

    Timer_A_initContinuousMode(TIMER_A0_BASE, &initContParam);

    //Initialise compare mode

    Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1);

    Timer_A_initCompareModeParam initCompParam = {0};

    initCompParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;

    initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;

    initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_SET_RESET;

    initCompParam.compareValue = COMPARE_VALUE;

    Timer_A_initCompareMode(TIMER_A0_BASE, &initCompParam);

    Timer_A_startCounter(TIMER_A0_BASE,TIMER_A_CONTINUOUS_MODE);

    --- ADC setting ---

    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN4);

    /* Initialize the ADC12_A Module */
    ADC12_A_init(ADC12_A_BASE,
    ADC12_A_SAMPLEHOLDSOURCE_1,
    ADC12_A_CLOCKSOURCE_SMCLK,
    ADC12_A_CLOCKDIVIDER_1);

    ADC12_A_setupSamplingTimer(ADC12_A_BASE,
    ADC12_A_CYCLEHOLD_96_CYCLES,
    ADC12_A_CYCLEHOLD_4_CYCLES,
    ADC12_A_MULTIPLESAMPLESDISABLE);

    /* Configure Memory Buffer */
    ADC12_A_configureMemoryParam config_param = {0};
    config_param.memoryBufferControlIndex = ADC12_A_MEMORY_0;
    config_param.inputSourceSelect = ADC12_A_INPUT_A4;
    config_param.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    config_param.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    config_param.endOfSequence = ADC12_A_ENDOFSEQUENCE;

    ADC12_A_configureMemory(ADC12_A_BASE, &config_param);

    ADC12_A_setResolution(ADC12_A_BASE, ADC12_A_RESOLUTION_12BIT);

    ADC12_A_enable(ADC12_A_BASE);

    Thanks.

  • Hi Zhengwei,

    This is correct:

    Then set ADC12 clock source to ADC12_A_CLOCKSOURCE_SMCLK and sampleHoldSignalSourceSelect to ADC12_A_SAMPLEHOLDSOURCE_1?

    maybe you can debug your code via some breakpoint.

    And another method , you can enable TA CC1 interrupt, then run ADC sampling code in this interrupt route.

    Thanks!

    Best Regards

    Johnson

  • Hi Johnson,

    My above code not enable TA CC1 interrupt? If not, how should enable? or can't in CONTINUOUS_MODE? 

    Thanks.

  • Hi Wei Huang,

    You can refer to this example code to enable CC1 interrupt:

    https://dev.ti.com/tirex/explore/node?node=AFkOtmwplfDAIL4v7fFedQ__IOGqZri__LATEST

    Thanks!

    Best Regard

**Attention** This is a public forum