Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed the week of November 23.

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.

CCS/TM4C123GH6PM: 5 PWMs control with keyboard

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

Hello all,

I'm new on MCU programming so please bear with me :) My original idea was to control 5 servo motors via keyboard.

So, firstly I have checked if I'm able to set up all available PWM outputs on TM4C123G launchpad and surprisingly I was :) I've made code that all 16 PWM would work "simultaneously" with this code:

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_gpio.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h"

int main(void)
{
    //System clock set up
    SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

    //Enable peripherals
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //Enable PWM modules
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

    //Unlock PortF PIN_1
    HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
    HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;

    //Configure PWM pins
    GPIOPinConfigure(GPIO_PB6_M0PWM0);
    GPIOPinConfigure(GPIO_PB7_M0PWM1);
    GPIOPinConfigure(GPIO_PB4_M0PWM2);
    GPIOPinConfigure(GPIO_PB5_M0PWM3);
    GPIOPinConfigure(GPIO_PE4_M0PWM4);
    GPIOPinConfigure(GPIO_PE5_M0PWM5);
    GPIOPinConfigure(GPIO_PC4_M0PWM6);
    GPIOPinConfigure(GPIO_PC5_M0PWM7);

    GPIOPinConfigure(GPIO_PD0_M1PWM0);
    GPIOPinConfigure(GPIO_PD1_M1PWM1);
    GPIOPinConfigure(GPIO_PA6_M1PWM2);
    GPIOPinConfigure(GPIO_PA7_M1PWM3);
    GPIOPinConfigure(GPIO_PF0_M1PWM4);
    GPIOPinConfigure(GPIO_PF1_M1PWM5);
    GPIOPinConfigure(GPIO_PF2_M1PWM6);
    GPIOPinConfigure(GPIO_PF3_M1PWM7);

    //Set pins type
    GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
    GPIOPinTypePWM(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

    //Configure PWM generators
    PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
    PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN);
    PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
    PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);
    PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
    PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN);
    PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
    PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);

    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, 4095);
    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, 4095);
    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, 4095);
    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, 4095);
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 4095);
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 4095);
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, 4095);
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, 4095);

    //Enable PWM generators
    PWMGenEnable(PWM1_BASE, PWM_GEN_0);
    PWMGenEnable(PWM1_BASE, PWM_GEN_1);
    PWMGenEnable(PWM1_BASE, PWM_GEN_2);
    PWMGenEnable(PWM1_BASE, PWM_GEN_3);
    PWMGenEnable(PWM0_BASE, PWM_GEN_0);
    PWMGenEnable(PWM0_BASE, PWM_GEN_1);
    PWMGenEnable(PWM0_BASE, PWM_GEN_2);
    PWMGenEnable(PWM0_BASE, PWM_GEN_3);

    //Set PWM outptus state
    PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT | PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT | PWM_OUT_6_BIT | PWM_OUT_7_BIT, true);
    PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT | PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT | PWM_OUT_6_BIT | PWM_OUT_7_BIT, true);

    while (1)
    {
        //Rotation clockwise
        uint32_t speed = 100;
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_3, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_6, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_7, speed);
        SysCtlDelay(SysCtlClockGet() * 2);

        //Rotation counter-clockwise
        speed = 2100;
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_3, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, speed);
        PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_6, speed);
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_7, speed);
        SysCtlDelay(SysCtlClockGet() * 2);
    }
}

Then, I tried to set up UART communication with my PC via Tera Term terminal and control 5 servo motors with keyboard buttons 0,1,2,3,4 for one counter-clockwise rotation and 5,6,7,8,9 for clockwise rotation and "s" for stopping with code below, but unfortunately only 0,1,2 and 5,6,7 seems working (motor is rotating depending on push of button) for pins PD0, PD1 and PA6. Maybe someone could help solve this mystery, why other 4 buttons (3,4 & 8,9) is not starting my servo motor?

#include<stdint.h>
#include<stdbool.h>
#include"inc/hw_memmap.h"
#include"inc/hw_types.h"
#include"inc/hw_gpio.h"
#include"driverlib/gpio.h"
#include"driverlib/pin_map.h"
#include"driverlib/pwm.h"
#include"driverlib/sysctl.h"
#include "driverlib/uart.h"

//MAIN FUNCTION
int main(void)
{
    unsigned char button;
    volatile uint32_t speed; //VARIABLE FOR PWM_WIDTH SET AS % FROM 0 TO 100

    //CLOCK SETTINGS - SET SYSTEM CLOCK TO 40MHz
    SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    //SET PWM CLOCK AS SYSTEM CLOCK DIVIDED BY 64
    SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

    //ENABLE PERIHPERALS
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //Enable PWM
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

    //CONFIGURE PINS
    GPIOPinConfigure(GPIO_PD0_M1PWM0);
    GPIOPinConfigure(GPIO_PD1_M1PWM1);
    GPIOPinConfigure(GPIO_PA6_M1PWM2);
    GPIOPinConfigure(GPIO_PA7_M1PWM3);
    GPIOPinConfigure(GPIO_PF1_M1PWM5);

    //SET PINS TYPE FOR PWM
    GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);

    //CONFIGURE PWM GENERATOR
    PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
    PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN);
    PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);

    //SET PWM GENERATORS WITH MODE OF OPERATION AS COUNTING
    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, 4095);
    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, 4095);
    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, 4095);

    //Enable PWM generators
    PWMGenEnable(PWM1_BASE, PWM_GEN_0);
    PWMGenEnable(PWM1_BASE, PWM_GEN_1);
    PWMGenEnable(PWM1_BASE, PWM_GEN_2);

    //Set PWM outputs state
    PWMOutputState(PWM1_BASE, PWM_OUT_0 | PWM_OUT_1 | PWM_OUT_2 | PWM_OUT_3 | PWM_OUT_4 | PWM_OUT_5 | PWM_OUT_6 | PWM_OUT_7, true);


    //Set up UART communication
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);

    //CONFIGURE UART, BAUD RATE 9600, DATA BITS 8, STOP BIT 1, PARITY NONE
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    while (1)
    {
        speed = 100;

        if (UARTCharsAvail(UART0_BASE))
        {
            button = UARTCharGet(UART0_BASE);
        }
        else
        {
            button = 100;
        }

        if (button == '0')
        {
            speed = 100; //ROTATION COUNTER-CLOCKWISE
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, speed); //SET THE PULSE WIDTH
        }

        if (button == '1')
        {
            speed = 100; //ROTATION COUNTER-CLOCKWISE
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, speed); //SET THE PULSE WIDTH
        }

        if (button == '2')
        {
            speed = 100; //ROTATION COUNTER-CLOCKWISE
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, speed); //SET THE PULSE WIDTH
        }

        if (button == '3')
        {
            speed = 100; //ROTATION COUNTER-CLOCKWISE
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_3, speed); //SET THE PULSE WIDTH
        }

        if (button == '4')
        {
            speed = 100; //ROTATION COUNTER-CLOCKWISE
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, speed); //SET THE PULSE WIDTH
        }

        if (button == '5')
        {
            speed = 2100; //ROTATION CLOCKWISE
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, speed); //SET THE PULSE WIDTH
        }

        if (button == '6')
        {
            speed = 2100; //ROTATION CLOCKWISE
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, speed); //SET THE PULSE WIDTH
        }

        if (button == '7')
        {
            speed = 2100; //ROTATION CLOCKWISE
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, speed); //SET THE PULSE WIDTH
        }

        if (button == '8')
        {
            speed = 2100; //ROTATION CLOCKWISE
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_3, speed); //SET THE PULSE WIDTH
        }

        if (button == '9')
        {
            speed = 2100; //ROTATION CLOCKWISE
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, speed); //SET THE PULSE WIDTH
        }

        if (button == 's')
        {
            speed = 0; //NO ROTATION
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, speed);
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, speed);
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, speed);
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_3, speed);
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, speed);
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, speed);
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, speed);
            PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, speed);
        }

        SysCtlDelay(SysCtlClockGet() / 90);
    }
}

  • Greetings,

    Nicely presented - "Good Job in that regard!"    However - might your review of your LPad's schematic been too brief - and/or insufficient in its data capture?

    Stasys Civilis said:
    unfortunately only 0,1,2 and 5,6,7 seems working

    Indeed the LPad's schematic avoids (proper) emphasis - but those "eagle eyed" may note the (unwanted) "PD0 - PB6 & PD1 - PB7" hardwired - GPIO to GPIO - connections!    Have you not chosen "all of those 4 pins for PWM Outputs?"

    Your decision to enable "16 PWM Outputs" set the stage for "Output to Output" contention - nicely enabled by the LPad's (unwanted) R9 & R10 "Plague-istors!"   Those two may be "stood up" (tombstoned) - well signalling their "horror" has been rectified!

    Your listing of the various keypad buttons would be improved if presented in one, "Common & well marked spot" - forcing an exacting search upon helpers to relate each button to MCU pin  does not work toward your interest...

  • Welcome to the forum. Let me set your expectations. We are more than happy to help answer technical questions about the TI microcontrollers, but in general we do not debug your code for you. I would like to help you. Can you tell us what you have done so far to isolate the issue? Have you verified with breakpoints that you get to each of the states? Have you verified with a logic analyzer or a scope if the pins are toggling or not? 

    You configured PF1 for M1PWM5, buttons 4 and 9, you use PWM_OUT_4. It should be PWM_OUT_5. I am not sure why PA7 (M1PWM3) is not working. Check that one with a scope if you have not already and let me know what you see.

  • Thank you for your answer and time for reviewing my problem, even though your writing manner difficult to follow, specially for non English native person :) nevertheless, after more experimental tries I've found 5 PWM pins, which corresponds to my keyboard via UART as initially I was intended to do (code below, please don't take my programming style into account, I will try to improve it in near future)

    Also, I tried to make a bit of reasearch about R9 & R10 resistors and I've found your post (https://e2e.ti.com/support/microcontrollers/other/f/908/t/260147), where you recommend to solder out those 2 resistors. Could it be, that those 2 resistors cause these problems (blocking some pins functionality) i.e. from code above - PA7 pin, doesn't control servo motor, even though it's configured as PWM. 

     

    #include<stdint.h>
    #include<stdbool.h>
    #include"inc/hw_memmap.h"
    #include"inc/hw_types.h"
    #include"inc/hw_gpio.h"
    #include"driverlib/gpio.h"
    #include"driverlib/pin_map.h"
    #include"driverlib/pwm.h"
    #include"driverlib/sysctl.h"
    #include "driverlib/uart.h"
    
    //MAIN FUNCTION
    int main(void)
    {
        unsigned char button;
        volatile uint32_t speed; //VARIABLE FOR PWM_WIDTH SET AS % FROM 0 TO 100
    
        //CLOCK SETTINGS - SET SYSTEM CLOCK TO 40MHz
        SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
        //SET PWM CLOCK AS SYSTEM CLOCK DIVIDED BY 64
        SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
    
        //ENABLE PERIHPERALS
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
        //Enable PWM
        SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
    
        //CONFIGURE PINS
        GPIOPinConfigure(GPIO_PA6_M1PWM2);
        GPIOPinConfigure(GPIO_PD0_M1PWM0);
        GPIOPinConfigure(GPIO_PD1_M1PWM1);
        GPIOPinConfigure(GPIO_PF2_M1PWM6);
        GPIOPinConfigure(GPIO_PF3_M1PWM7);
    
        //SET PINS TYPE FOR PWM
        GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6);
        GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
        GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
    
        //CONFIGURE PWM GENERATOR
        PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
        PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN);
        PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
        PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);
    
        //SET PWM GENERATORS WITH MODE OF OPERATION AS COUNTING
        PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, 4095);
        PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, 4095);
        PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, 4095);
        PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, 4095);
    
        //Enable PWM generators
        PWMGenEnable(PWM1_BASE, PWM_GEN_0);
        PWMGenEnable(PWM1_BASE, PWM_GEN_1);
        PWMGenEnable(PWM1_BASE, PWM_GEN_2);
        PWMGenEnable(PWM1_BASE, PWM_GEN_3);
    
        //Set PWM outputs state
        PWMOutputState(PWM1_BASE, PWM_OUT_0 | PWM_OUT_1 | PWM_OUT_2 | PWM_OUT_3 | PWM_OUT_4 | PWM_OUT_5 | PWM_OUT_6 | PWM_OUT_7, true);
    
    
        //Set up UART communication
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
    
        //CONFIGURE UART, BAUD RATE 9600, DATA BITS 8, STOP BIT 1, PARITY NONE
        UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    
        while (1)
        {
            speed = 100;
    
            if (UARTCharsAvail(UART0_BASE))
            {
                button = UARTCharGet(UART0_BASE);
            }
            else
            {
                button = 100;
            }
    
            if (button == '0')
            {
                speed = 100; //ROTATION COUNTER-CLOCKWISE
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, speed); //SET THE PULSE WIDTH
            }
    
            if (button == '1')
            {
                speed = 100; //ROTATION COUNTER-CLOCKWISE
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, speed); //SET THE PULSE WIDTH
            }
    
            if (button == '2')
            {
                speed = 100; //ROTATION COUNTER-CLOCKWISE
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, speed); //SET THE PULSE WIDTH
            }
    
            if (button == '3')
            {
                speed = 100; //ROTATION COUNTER-CLOCKWISE
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, speed); //SET THE PULSE WIDTH
            }
    
            if (button == '4')
            {
                speed = 100; //ROTATION COUNTER-CLOCKWISE
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, speed); //SET THE PULSE WIDTH
            }
    
            if (button == '5')
            {
                speed = 2100; //ROTATION CLOCKWISE
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, speed); //SET THE PULSE WIDTH
            }
    
            if (button == '6')
            {
                speed = 2100; //ROTATION CLOCKWISE
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, speed); //SET THE PULSE WIDTH
            }
    
            if (button == '7')
            {
                speed = 2100; //ROTATION CLOCKWISE
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, speed); //SET THE PULSE WIDTH
            }
    
            if (button == '8')
            {
                speed = 2100; //ROTATION CLOCKWISE
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, speed); //SET THE PULSE WIDTH
            }
    
            if (button == '9')
            {
                speed = 2100; //ROTATION CLOCKWISE
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, speed); //SET THE PULSE WIDTH
            }
    
    //        if (button != '1' | button != '2' | button != '3' | button != '4' | button != '5' | button != '6' | button != '7' | button != '8' | button != '9')
    
            if (button == 's')
            {
                speed = 0; //NO ROTATION
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, speed);
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, speed);
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, speed);
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_3, speed);
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, speed);
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, speed);
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, speed);
                PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, speed);
            }
    
            SysCtlDelay(SysCtlClockGet() / 90);
        }
    }
    
    

  • Bob Crosby said:

    Welcome to the forum. Let me set your expectations. We are more than happy to help answer technical questions about the TI microcontrollers, but in general we do not debug your code for you. I would like to help you. Can you tell us what you have done so far to isolate the issue? Have you verified with breakpoints that you get to each of the states? Have you verified with a logic analyzer or a scope if the pins are toggling or not? 

    You configured PF1 for M1PWM5, buttons 4 and 9, you use PWM_OUT_4. It should be PWM_OUT_5. I am not sure why PA7 (M1PWM3) is not working. Check that one with a scope if you have not already and let me know what you see.

    Thank you for your time and answer.  I understand, that you won't debug my code and I'm not seeking it, but I guess in most cases "problem" occurs from code side not hardware (but this is only my inexperienced programmer's thought).

    Can you tell us what you have done so far to isolate the issue?

    As I mention in man previous replay for "cb1_mobile" I've managed to write a code, which fulfills my initial intention. However, I'am still don't understand some thing on which I will have to make some deeper research by myself. Basically what I did, was that I've checked PWM pins one by one and I've found 5 "working" pins (I left them in code in "cb1_mobile" replay). But I'm still confused why other pins didn't "worked", and sadly I can't find any obvious reason for that ;/

    Have you verified with breakpoints that you get to each of the states?

    I've tried to go step by step in debbuger, but didn't find anything unsual (at least for me)

    Have you verified with a logic analyzer or a scope if the pins are toggling or not? 

    I don't have neither of this equipment, so, no, I didn't. But with my code from my initial post, where I set all 16 PWM, all 16 PWM pins where "working".

    You configured PF1 for M1PWM5, buttons 4 and 9, you use PWM_OUT_4. It should be PWM_OUT_5.

    Thank for notice, I've change it, but still nothing has changed.

  • Continued, follow-on Greetings,

    Further review finds (as you noted) Pins:

    • PD0 - Button 0
    • PD1 - Button 1
    • PA6 - Button 2

    to work.

    In addition - had you noted that those same Pins serve:

    • PD0 - Button 5
    • PD1 - Button 6
    • PA6 - Button 7

    as well - & continue to work.

    Your "Buttons 4 & 9" fail as they service "PF0" - which you have not enabled!   (You enabled PF1 - only)

    Your "Buttons 3 & 8" serviced by "PA7" appear properly configured - that's really the (sole) mystery...

    In such cases it proves wise to:

    • check & determine if that pin is (really) connected to your device
    • check & determine if some other connection(s) exist to that pin
    • temporarily configure that pin to GPIO Output & test to see if it can be driven high

    Your most recent post noted, "PA7 pin, doesn't control servo motor, even though it's configured as PWM. "    But that's NOT true!   Your newest code reveals:

    //CONFIGURE PINS
    GPIOPinConfigure(GPIO_PA6_M1PWM2);    // PA7 has been abandoned!
    GPIOPinConfigure(GPIO_PD0_M1PWM0);
    GPIOPinConfigure(GPIO_PD1_M1PWM1);
    GPIOPinConfigure(GPIO_PF2_M1PWM6);    //  PF0 is equally abandoned!
    GPIOPinConfigure(GPIO_PF3_M1PWM7);
    //SET PINS TYPE FOR PWM
    GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6);     // PA7 has been abandoned!
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 |     //  PF0 is equally abandoned!

    Thus (any) buttons calling to PF0 or PA7 must fail...

    While the dual (unwanted) cross-connects appear to "Not yet have impacted your effort" - they "remain armed & poised" to do so.   Tomb-stoning both prevents issues while (boldly) confirming that your board has been "fixed."

  • The root cause of your issue is in your call of PWMOutputState(). In the first code you correctly used the parameters PWM_OUT_x_BIT.  In the next two codes you incorrectly used PWM_OUT_x. Using the wrong defines resulted in the value 0xC7 instead of 0xFF being written to the PWM_ENABLE register. That prevented pins F1 and A7 from working correctly.

  • Thank you! Now everything is fixed and works as I expected. Thanks to Bob Crosby and cb1_mobile for your time and efforts, problem solved :)

  • Greetings,

    Should it not be noted that there is - yet another - "root cause" for issue's appearance?

    cb1_mobile said:

    //CONFIGURE PINS
    GPIOPinConfigure(GPIO_PA6_M1PWM2);    // PA7 has been abandoned!
    GPIOPinConfigure(GPIO_PD0_M1PWM0);
    GPIOPinConfigure(GPIO_PD1_M1PWM1);
    GPIOPinConfigure(GPIO_PF2_M1PWM6);    //  PF0 is equally abandoned!
    GPIOPinConfigure(GPIO_PF3_M1PWM7);
    //SET PINS TYPE FOR PWM
    GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6);     // PA7 has been abandoned!
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 |     //  PF0 is equally abandoned!

    Thus (any) buttons calling to PF0 or PA7 must fail...

    Now (one) of the "proposed" root causes noted, "PWMOutputState()" receiving incorrect parameters.   Yet - even if - and especially if - correct parameters were employed - Code Failure would continue!    (as neither PA7 & PF0 had been "GPIOPinConfigured() AND GPIOPinTyped()!    Root cause (clearly) flowed along two paths - (Not just one!)

  • cb1_mobile said:

    Greetings,

    Should it not be noted that there is - yet another - "root cause" for issue's appearance?

    cb1_mobile

    //CONFIGURE PINS
    GPIOPinConfigure(GPIO_PA6_M1PWM2);    // PA7 has been abandoned!
    GPIOPinConfigure(GPIO_PD0_M1PWM0);
    GPIOPinConfigure(GPIO_PD1_M1PWM1);
    GPIOPinConfigure(GPIO_PF2_M1PWM6);    //  PF0 is equally abandoned!
    GPIOPinConfigure(GPIO_PF3_M1PWM7);
    //SET PINS TYPE FOR PWM
    GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6);     // PA7 has been abandoned!
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 |     //  PF0 is equally abandoned!

    Thus (any) buttons calling to PF0 or PA7 must fail...

    Now (one) of the "proposed" root causes noted, "PWMOutputState()" receiving incorrect parameters.   Yet - even if - and especially if - correct parameters were employed - Code Failure would continue!    (as neither PA7 & PF0 had been "GPIOPinConfigured() AND GPIOPinTyped()!    Root cause (clearly) flowed along two paths - (Not just one!)

    Sorry, I was unspecific and not clear in this part, which could made all this confusion about pin PA7 & PF0 "i.e. from code ABOVE - PA7 pin, doesn't control servo motor, even though it's configured as PWM." I wanted to say, that in my initial code I've configured these pin as PWM, but for unknown (now it's clear why) reason they didn't "worked", so on later replay "...nevertheless, after more experimental tries I've found 5 PWM pins, which corresponds to my keyboard via UART as initially I was intended to do (code BELOW, please... "  I found other 2 pins which was working with my new code, so I abandoned those PA7 & PF0 pins. Again, sorry for this and in future I will try to be more precise what I'm chaning and etc.