Hii all,
I was digging out the PWM capabilities of TM4C123G,and found very confusing to configure the PWM resoultion or maybe i am going wrong somewhere,
Well let me take a simple code example which can control the Speed of a Toy DC motor.i wrote the code as follows.
I am configuring PF1 as PWM pin and PE3 as ADC for POT.
------------------------------------------------------------------------CODE STARTS HERE----------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_gpio.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/adc.h"
int main(void)
{
uint32_t result[0];
SysCtlClockSet(SYSCTL_SYSDIV_5| SYSCTL_USE_OSC |SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);//Divide the sys clock for PWM module
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
// ADCHardwareOversampleConfigure(ADC0_BASE, 64);
SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3);
ADCSequenceDisable(ADC0_BASE, 3);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //The Tiva Launchpad has two modules (0 and 1). Module 1 covers the LED pins
GPIOPinConfigure(GPIO_PF1_M1PWM5);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);//set PF1 as PWM
PWMGenConfigure(PWM1_BASE, PWM_GEN_2,PWM_GEN_MODE_DOWN|PWM_GEN_MODE_DBG_RUN);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, 4095);
PWMGenEnable(PWM1_BASE, PWM_GEN_2);
PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT , true);
while(1)
{
ADCIntClear(ADC0_BASE,3);
ADCProcessorTrigger(ADC0_BASE,3);
while(!ADCIntStatus(ADC0_BASE,3,false))
{
}
ADCSequenceDataGet(ADC0_BASE,3,result);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,result[0]);
}
-------------------------------------------------------------------------------------------------------------END HERE-----------------------------------------------------------------------------------------------------------------------------------------------------------------
I have connected an oscilloscope and a multi-meter on the PF1 pin to see the out put result..10k POT is connected between 0V and 3.3v.Also added the ''result' value to watch window which varies perfectly from 0-4095 as expected.Now when i go for 4095 value through my pot the Scope shows 100% duty cycle and voltage also around 3.1v,and when i slowly slowly decrease the pot value towards 0,same i see in scope as the duty cycle reducing and led also glows accordingly.
when my pot is at level 6 or 7,below that led starts blinking ,which i think is the property of pwm and voltage also stops reducing ,it goes from some 0.7v to 1.17v(up and down) continuosly.
If i now connect the same PWM with a DC motor,i am able to control the speed when its above that pot level(6 or 7), till 4095.
below that motor rotates with the blink of LED.
Do i need to set the PWM resolution,and
If i want my Pwm to be controlled from the very begining level 0,what is the PWM resolution i need to set up and how to calculate it?
Thank You