TM4C123GH6PM | DC Motor speed control through Potentiometer using TM4C Launch Pad | TM4C Launch Pad

DC Motor speed control through Potentiometer using TM4C Launch Pad

Program

#include<stdint.h>

#include<stdbool.h>
#include"inc/hw_memmap.h"
#include"driverlib/sysctl.h"
#include"driverlib/adc.h"
#include"driverlib/gpio.h"
#include"driverlib/pwm.h"
#include"driverlib/pin_map.h"
uint32_t ui32ADC0Value[1]; // TO STORE THE VALUE IN VARIABLE ui32ADC0Value FOR EVERY SAMPLING
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|
SYSCTL_XTAL_16MHZ); // SET SYSTEM CLOCK AT 40MHZ
SysCtlPWMClockSet(SYSCTL_PWMDIV_64); //SET PWM CLOCK AT SYSTEM CLOCK DIVIDED BY 64
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //ENABLE PWM1 MODULE
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //ENABLE ADC0 MODULE
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //ENABLE GPIO FOR ADC0 MODULE
GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3); //CONFIGURE PE3 AS AN0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //ENABLE GPIO FOR PWM1 MODULE
GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0); //CONFIGURE PD0 AS PWM OUTPUT
GPIOPinConfigure(GPIO_PD0_M1PWM0);//SET PD0 AS M1PWM0
PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
//SET PWM GENERATOR WITH MODEOF OPERATION AS COUNTING
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0,4095);
//SET THE PERIOD OF PWM GENERATOR
PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true); //ENABLE BIT0 OUTPUT
PWMGenEnable(PWM1_BASE, PWM_GEN_0); //ENABLE PWM GENERATOR
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
// ADC0 MODULE, TRIGGER IS PROCESSOR EVENT, SEQUENCER 0 IS CONFIGURED
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);
// ADC0 MODULE, SEQUENCER 0 , FOR 1 SAMPLING, INPUT IS FROM CHANNEL 0 PE3
ADCSequenceEnable(ADC0_BASE, 1); // ENABLE THE SEQUENCE 1 FOR ADC0
while(1)
{
ADCIntClear(ADC0_BASE, 1); // CLEAR INTERRUPT FLAG FOR ADC0, SEQUENCER 1
ADCProcessorTrigger(ADC0_BASE, 1); // TRIGGER IS GIVEN FOR ADC0 MODULE, SEQUENCER1
// STORE THE CONVERTED VALUE FOR ALL DIFFERENT SAMPLING IN ARRAY ui32ADC0Value
ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, ui32ADC0Value[0]);
// SET THE PULSE WIDTH
}
}


Procedure

1. Create a new folder on desktop location.

2. Open cc studio on desktop.

3. Browse the workspace location

    Click on browseàdesktopàselect created folderàok button.

4. CCstudio wizard is opened

     Click on projectànew ccs projectàtarget [select Tiva c series].

5. Select microcontroller “Tiva TM4C123GH6PM”, click on connection and select “Stellaris in-circuit debug interface”.                                     

6. Name the project in project name bar and click on finish button.

7. Click on restore button on left side and then enter the programà save button.

8. Now unfold the project and right click on project and select properties.

9. Select include optionsàaddàbrowseàmy computeràlocal disc càtià
    Tivaware_c_series_2.1.2.111
àok. Now directory path is added to project then click on ok
    button.

10. Select projectà Right click on project à add files à select local disc cà  select tià Tivaware_c_series_2.1.2.111 àselect driverlib à ccs à debug àdriverlib.lib à open button.

11. Select copy files and click ok button. Now driver library file is added to the project.                                                                                                                                     

12. To build the project click on Build button.

13. CIRCUIT CONNECTION: 10k potentiometer is taken, the middle pin is connected to PE3 in TM4C launch pad, first pin is connected to the 3.3V and the last pin is connected to the GND in TM4C. Connect L293D motor driver module’s  CI-A (control input pin) to PD0 pin in TM4C. Connect 7805 IC to the motor module. Now connect the GND of motor module to GND of TM4C. Connect 9V MOTOR to L293D motor module at M1.connect 9V battery to motor module.7805 IC converts 9V to 5V and supplies voltage to TM4C launch pad.

14.  Connect TM4C launch pad to pc using USB cable.

15. Before debugging set the launch pad in debug mode by pushing wake up pin and click on debug button in ccstudio.

16.  Select the potentiometer variable name UI32ADC0 in the program àRight Click on itàselect add watch expression àclick ok buttonàunfold the UI32ADC0 value on expression.

17.  To add the break point select line 32(double click) àRight click on itàbreak point properties àactionàclick on Remain HaltàRefresh all windowsàok.

18. Click on Resume button and vary the potentiometer.


Circuit Connection


TM4C123GH6PM Overall Documentation in video description

Video 👇









Comments