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 using P1.2 or P1.3 on MSP430fr5969

Intellectual 290 points

Replies: 15

Views: 3793

I would like to generate a PWM on P1.2 or P1.3 or P1.4 since these pins can be connected to a wire ...There is software example for P1.0 and P1.1 which are LEDs which is the following...

#include <msp430.h>

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

// Configure GPIO
P1DIR |= BIT0 | BIT1; // P1.0 and P1.1 output
P1SEL0 |= BIT0 | BIT1; // 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
TA0CCR0 = 1000-1; // PWM Period
TA0CCTL1 = OUTMOD_7; // CCR1 reset/set
TA0CCR1 = 750; // CCR1 PWM duty cycle
TA0CCTL2 = OUTMOD_7; // CCR2 reset/set
TA0CCR2 = 250; // CCR2 PWM duty cycle
TA0CTL = TASSEL__SMCLK | MC__UP | TACLR; // SMCLK, up mode, clear TAR

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

when i try change P1DIR |= BIT0 | BIT1; // P1.0 and P1.1 output
                                P1SEL0 |= BIT0 | BIT1;

 to 

P1DIR |= BIT0 | BIT2; // P1.0 and P1.2output
P1SEL0 |= BIT0 | BIT2; 

i dont get any output for p1.2?...please tell me how to scale the same program for p1.2 and other p1.x pins...

15 Replies

  • Krishna, why do you like your own question? :)

    If you want to change the PWM to another pin you first have to check the datasheet for the device's pinout. P1.0 has TA0.1 as special function. P1.1 has TA0.2 - these are the internal connections to the timer module.

    Now look at P1.2 - it has TA1.1, so you have to change your code for using TA1 instead of TA0.
    P1.3 is TA1.2 and P1.4 is connected to TB0.1, again another timer module for the last one.

    Dennis


  • Setting a bit in P1SEL disables that pin's GPIO function, and connects the pin to some other hardware instead. That other connection is usually hardcoded; to see what you actually get, you have to look into the datasheet of your chip.

    The MSP430FR5969 datasheet (section 6.11) says that the P1.0 and P1.1 pins are connected to TA0.1 and TA0.2, which are the CCR1 and CCR2 functions of timer A0.

    Pin P1.2 is connected to TA1.1, which means that to get a PWM signal out of this pin, you must use a different timer (A1), and that timer's capture/compare register CCR1.

  • In reply to Dennis Eichmann:

    Thank you very much Dennis...
  • In reply to Clemens Ladisch:

    Thank you very much Clemens..
  • In reply to Dennis Eichmann:

    I have a beginner question that may be stupid but,

    If I wanted to use two PWM channels, to control two different motor controllers could I:

    -Use analogwrite() on pin P1.2 since it is hardware PWM.

    -Use the above code for a general I/o pin

    Additionally, how can use pin P1.1 or P1.0 if they are power pins?

    Sorry if these are ridiculous questions. I am very new to this. 

    Thanks,

    Nolan

  • In reply to Nolan Conway:

    Hi Nolan!

    I don't know the analogwrite()-function, but PWM is a digital signal, so anything analog is wrong here. The above code does not use a "general" I/O pin - the used pins aren't chosen intentionally because these ones can internally be linked to the timer module of the processor. Look at the datasheet - they have TA0.x or TA1.x as pin functions.

    To use two different PWM signals you should use pins that share TA0.1 and TA0.2 for example.

    And power pins have never a "Px.x" port function. They are power pins, nothing else. The names for them are DVcc and DVss or AVcc and AVss.

    Dennis


  • In reply to Dennis Eichmann:

    Dennis Eichmann
    but PWM is a digital signal, so anything analog is wrong here

    Sorry Dennis but not true. PWM can be used as DAC to control an analogue motor driver.

  • In reply to Leo Bosch:

    Ah, OK, yes - did not think about that. But the PWM becomes analogue due to the low pass filter following the PWM. The PWM itself is on/off with variable duty cycle and this is digital.

    Dennis


  • In reply to Dennis Eichmann:

    So going back to my original statement, analogwrite() was the recommended method to generate pwm signals in energia. 

    If i need to run two motors off a pwm signal, could i simply use one motor on pin P1.2 (the hardware PWM), and then i would need the code from the original post in order to use the second motor controller?

    Is there an easier way that I am missing? Will this be to memory intensive if i am running other operations such as serial communication and logic for the motor control?

    Thanks,

    Nolan

  • In reply to Nolan Conway:

    Nolan,

    then use analogwrite() for that - I have never worked with Energia, so I don't know those functions. If it controls the PWM signal, then it just might change the CCR value of the timer module. Is there a low pass filter on your board?

    Using the hardware PWM generates almost no code (at least without using Energia) since everything is done in hardware. Without Energia you would use TA0.0 as frequency and TA0.1 and TA0.2 for control of the duty cycle of your two PWM signals. How this is configured in Energia...I don't know. But the method will be the same. Then connect your two driver stages to the pins that have TA0.1 and TA0.2 as special functions. That's it.

    Dennis


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.