controller =TM4C123gh6pm
IDE=KEIL
In my project I need 2 PWM signals.For that I configured PWM0 and PWM1 like given below
void PWM_Config() //This fn will cofigure PWM
{
SysCtlPWMClockSet (SYSCTL_PWMDIV_1); /* Set the PWM clock to the system clock.*/
SysCtlPeripheralEnable (SYSCTL_PERIPH_PWM1);/* The PWM peripheral must be enabled for use.*/
SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOD);
GPIOPinConfigure (GPIO_PD0_M1PWM0);
GPIOPinTypePWM (GPIO_PORTD_BASE, GPIO_PIN_0);
PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
// PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
}
void PWM1_Config()//This fn will cofigure PWM1
{
// SysCtlPWMClockSet (SYSCTL_PWMDIV_1); /* Set the PWM clock to the system clock.*/
SysCtlPeripheralDisable (SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable (SYSCTL_PERIPH_PWM0);/* The PWM peripheral must be enabled for use.*/
SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure (GPIO_PB6_M0PWM0);
GPIOPinTypePWM (GPIO_PORTB_BASE, GPIO_PIN_6);
PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
// PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
}
void PWM_On (float duty) //this function will turn on PWM module with duty cycle based on the function argument duty
{
PWMGenPeriodSet (PWM1_BASE, PWM_GEN_0, PWMFreqency);/* 120000=1KHz 120=1MHz 12=10MHz */
duty=duty/100;
PWMPulseWidthSet (PWM1_BASE, PWM_OUT_0,PWMGenPeriodGet(PWM1_BASE, PWM_OUT_0) * duty);
PWMOutputState (PWM1_BASE, PWM_OUT_1_BIT | PWM_OUT_0_BIT, true);
PWMGenEnable (PWM1_BASE, PWM_GEN_0);/* Enable the PWM generator block.*/
}
void PWM1_On (float duty1)//this function will turn on PWM1 module with duty cycle based on the function argument duty1
{
pulse=no_of_pulse;
PWMGenPeriodSet (PWM0_BASE, PWM_GEN_0, PWMFreqency);/* 120000=1KHz 120=1MHz 12=10MHz */
duty1=duty1/100;
PWMPulseWidthSet (PWM0_BASE, PWM_OUT_0,PWMGenPeriodGet(PWM0_BASE, PWM_OUT_0) * duty1);
PWMOutputState (PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_0_BIT, true);
PWMGenEnable (PWM0_BASE, PWM_GEN_0);/* Enable the PWM generator block.*/
}
code given below is the main programme
main()
{
PWM_Config(); //PWM configuration
PWM1_Config(); //PWM1 configuration
PWM_On(50);
PWM1_On(99);
}
In the above programme PWM module0 is turn on with a pulse width of 99% and PWM module 1 is with 50%. But I am getting same voltage across PB6(PWM1) and PD0(PWM0). But if a use 1 PWM module at a time (ie only configure and turn on eighter PWM module 0 or PWM module 1) then I will get exact voltage across the pins(PB6/PD0) based on the duty cycle..Problem will occur when they configure and turn on together.
PWM module 0 and PWM module 1 are under same generator(generator 0)
When I tried to use another PWM module(ie. another generator) compiler is showing warning Bz macro for only PWM0 and PWM1 is defined(in sysctl.h).
#define SYSCTL_PERIPH_PWM0 0xf0004000 // PWM 0
#define SYSCTL_PERIPH_PWM1 0xf0004001 // PWM 1
I cant use other PWM modules bz it is not defined like above in sysctl.h
So please help me with this problem.