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: How Can I use D1 pin instead of D0 pin for PWM output.

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

Hi,

The workshop for TM4C123GH6PM shows PWM control on D0 pin and code working fine. Could you please let me know what modification I need to do in code in order to get D1 (or generalized) as PWM output pin. 

Best regards,

Nasim

  • You need to change the pin configuration functions to GPIO_PIN_1 and GPIO_PD1_M1PWM1

    	ROM_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);
    	ROM_GPIOPinConfigure(GPIO_PD1_M1PWM1);
    

    You need to change the PWM configurations to use PWM_GEN_1 and PWM_OUT_1

     

    	PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN);
    	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, ui32Load);
    
    	ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, ui8Adjust * ui32Load / 1000);
    	ROM_PWMOutputState(PWM1_BASE, PWM_OUT_1_BIT, true);
    	ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_1);
    

    And remember to change PWM_OUT_0 to PWM_OUT_1 twice within the while loop at the end of the main function.

  • Bob,

    Thanks a lot for your support. I tried accordingly. It builds, debugs, runs but motor does not move. 

    Best regards, 

    Nasim

  • Hello,

    Nasim Khan said:
    It builds, debugs, runs but motor does not move. 

    Pardon - further facts ARE required:

    • was PWM Output observed on your desired pin?    Ideally - that should be confirmed via a 'Scope Capture.'
    • unless your motor (btw - the operation of a 'motor' is 'brand-new' information) is extremely small & low voltage - it cannot be 'directly driven' by the MCU's PWM Output - alone!     MCU outputs are intelligent - yet not intended to provide the current demanded by 'most all' motors.
    • a listing (ideally spec) of your motor along w/a schematic detailing the connections between MCU and that motor - will greatly aid your 'helpers.'   (almost surely will be required!)

    It is 'normal/customary' that a Transistor Power Stage be inserted between the MCU and the Motor.    The Power Stage should be able to 'well match' the motor's current AND voltage requirements - both (FAR Beyond) the MCU's output capability...

    Depending upon the motor's current & voltage demands - if you attempted a 'direct connection' - the MCU may have been damaged.    You are advised to 'Halt all (further) attempts at motor drive' - until you have provided the customary Power Stage as described...

  • Nasim,

    I am sorry, I gave you incorrect information. There are four PWM generators on each module. Each generator controls two PWM signals. Pin PD1 is on module PWM1_BASE, generator PWM_GEN_0, output PWM_OUT_1_BIT. I told you to use  PWM_GEN_1, which is incorrect. The code should look like this:

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/debug.h"
    #include "driverlib/pwm.h"
    #include "driverlib/pin_map.h"
    #include "inc/hw_gpio.h"
    #include "driverlib/rom.h"
    
    
    #define PWM_FREQUENCY 55
    
    int main(void)
    {
    	volatile uint32_t ui32Load;
    	volatile uint32_t ui32PWMClock;
    	volatile uint8_t ui8Adjust;
    	ui8Adjust = 83;
    
    	ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
    	ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
    
    	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
    	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
    	ROM_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);
    	ROM_GPIOPinConfigure(GPIO_PD1_M1PWM1);
    
    	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
    	HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
    	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;
    	ROM_GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_DIR_MODE_IN);
    	ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    
    	ui32PWMClock = SysCtlClockGet() / 64;
    	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
    	PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
    	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ui32Load);
    
    	ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, ui8Adjust * ui32Load / 1000);
    	ROM_PWMOutputState(PWM1_BASE, PWM_OUT_1_BIT, true);
    	ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_0);
    
    	while(1)
    	{
    
    		if(ROM_GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00)
    		{
    			ui8Adjust--;
    			if (ui8Adjust < 56)
    			{
    				ui8Adjust = 56;
    			}
    			ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, ui8Adjust * ui32Load / 1000);
    		}
    
    		if(ROM_GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00)
    		{
    			ui8Adjust++;
    			if (ui8Adjust > 111)
    			{
    				ui8Adjust = 111;
    			}
    			ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, ui8Adjust * ui32Load / 1000);
    		}
    
    		ROM_SysCtlDelay(100000);
    	}
    
    }
    

  • Hi,

    I meant it is the same servo motor ((HextroniK,  HXT900) I connected to D0 (orange/ signal cable). When I connected signal cable to D1 it did not work.

    Best regards,

    Nasim

  • Greetings,

    Do note vendor Bob's updated post - w/so many (potential) PWM pins available - it proves easy to scramble them.   (multi-eyed staff proves great at 'preventing such confusion.')

    In light of your 'motor detail' it is suspected that such a small servo motor, 'Is accepting of CMOS Signal Levels.'     (it is likely that any current buffering is implemented w/in the small servo motor)    Do note that such motors are the 'Exception' - and most always you must deploy a proper 'Power Stage' when mating an MCU to a (more powerful) motor...

  • Thanks a lot Bob,

    yes, this code is working to control servo position from D1 pin.

    Best regards,

    Nasim