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.

PWM and Dual Channel ADC sampling using MSP430fr5969

I need to use three I/O pins of my MPS430fr5969 to create four PWMs and then simultaneously, i need my adc to sample two signals. My PWM code is the following :

#include <msp430.h>

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

// Configure GPIO
P1DIR |= BIT2 | BIT3 | BIT4 | BIT5 ; // P1.0 and P1.1 output
P1SEL0 |= BIT2 |BIT3 | BIT4 | BIT5 ;
// P1.0 and P1.1 options select

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

CSCTL0_H = CSKEY >> 8; // Unlock CS registers
CSCTL1 = DCOFSEL_6; // Set DCO = 8MHz
CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;// Set ACLK=VLO SMCLK=DCO
CSCTL3 = DIVA__8 | DIVS__8 | DIVM__8; // Set all dividers
CSCTL0_H = 0; // Lock CS registers

// Configure Timer0_A
TA1CCR0 = 20000-1; // PWM Period
TA1CCTL1 = OUTMOD_7; // CCR2 reset/set
TA1CCR1 = 100; // CCR1 PWM duty cycle
TA1CCTL2 = OUTMOD_7; // CCR2 reset/set
TA1CCR2 = 100;

TB0CCR0 = 4000-1;
TB0CCTL1 = OUTMOD_7; // CCR1 reset/set
TB0CCR1= 100;
TB0CCTL2 = OUTMOD_7; // CCR1 reset/set
TB0CCR2 = 4000; // CCR2 PWM duty cycle

TA1CTL = TASSEL__SMCLK | MC__UP | TACLR; // SMCLK, up mode, clear TAR
// CCR1 PWM duty cycle
// CCR2 PWM duty cycle
TB0CTL = TBSSEL__SMCLK | MC__UP | TBCLR; // SMCLK, up mode, clear TBR


__bis_SR_register(LPM0_bits); // Enter LPM0
__no_operation(); // For debugger
}

Now, that I have already used three pins 1.2,1.3,1.4,1.5 for creating PWM , is it possible to add the firmware for dual channel ADC sampling ?...Will the ADC timers affect my PWM ( Do I need to configure the DMA since, I also need to push the digital output using UART)...

How exactly are the i/o pins connected to ADC...How to select the I/O pins for both the signal sampling so that my PWM is affected?...adc

  • Hello Krishna,

     I would recommend to use other ADC pins, multiplexing the functionality of these pins will affect your PWM outputs. For example, you could use pins P4.1 thru P4.3 for your ADC's. We have some code examples in our MSPWare on how to use the ADC's. Let me know if you need help migrating the code to use these pins.

    Krishna Balaji said:
    Will the ADC timers affect my PWM ( Do I need to configure the DMA since, I also need to push the digital output using UART)...

    I think it will depend on how often you will need to change your duty cycle on your PWM's, I could see a need of using DMA if that is the case.

    Hopefully this helps.

      Regards,

       David

  • Hello David,

    Thanks for the reply.

    My PWM's time periods are 4ms and 16ms respectively and time duration of my high level of PWM is 100 mircoseconds. Does that require a DMA since I need to do dual channel ADC sampling as well as PWM?.

    I need to do both PWM and dual channel ADC sampling using the same MSP430 because the ADC sampling has to synchronized with the PWM outputs ( since all the timers of MSP430 work using a single internal DCO, I believe this will happen..Let me know your thoughts on this..)

    Yes. It would be great if you can help me with the code since I am not clear how exactly to combine the PWM and dual channel ADC codes .

    I can use the pins 4.1 to 4.3 for my ADC but I have doubts on how exactly the ADC is triggered for the inputs at those pins ( Will it be automatic if the respective timers of those pins are used by the ADC's)..

    To give you a context, the PWM's are for an analog front end that comes before the ADC. The analog front end is an integrator circuit that adds four samples and gets reset to zero and I need the ADC to sample exactly the last addition (sum of three samples). I need another channel of ADC to sample the original input ( without the integrator) so that I can check if my front end works properly. Please let me know if such a synchronization is possible between the ADC and PWM.

    I look forward to your reply.

    Regards,

    Krishna

**Attention** This is a public forum