lawrence_jeff 3 Posted August 3, 2013 PWM is much easier on the new Launchpad using the PWM peripherals, here is a working example using the 3 onboard LEDs. #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" int main(void) { unsigned long ulPeriod; //Set the clock SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //Configure PWM Clock to match system SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // Enable the peripherals used by this program. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //The Tiva Launchpad has two modules (0 and 1). Module 1 covers the LED pins ulPeriod = SysCtlClockGet() / 200; //PWM frequency 200HZ //Configure PF1,PF2,PF3 Pins as PWM GPIOPinConfigure(GPIO_PF1_M1PWM5); GPIOPinConfigure(GPIO_PF2_M1PWM6); GPIOPinConfigure(GPIO_PF3_M1PWM7); GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); //Configure PWM Options //PWM_GEN_2 Covers M1PWM4 and M1PWM5 //PWM_GEN_3 Covers M1PWM6 and M1PWM7 See page 207 4/11/13 DriverLib doc PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); //Set the Period (expressed in clock ticks) PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ulPeriod); PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ulPeriod); //Set PWM duty-50% (Period /2) PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,ulPeriod/2); PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6,ulPeriod/2); PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7,ulPeriod/2); // Enable the PWM generator PWMGenEnable(PWM1_BASE, PWM_GEN_2); PWMGenEnable(PWM1_BASE, PWM_GEN_3); // Turn on the Output pins PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT |PWM_OUT_6_BIT|PWM_OUT_7_BIT, true); //Do nothing while(1) { } } 4 igor, tingo, bluehash and 1 other reacted to this Quote Share this post Link to post Share on other sites
peppeg85 0 Posted September 27, 2013 hi, i'm studying the pwm on a lm4f120hq, when I build the main.c i've the following error: #20 identifier "GPIO_PF1_M1PWM5" is undefined it is about the lines: //Configure PF1,PF2,PF3 Pins as PWMGPIOPinConfigure(GPIO_PF1_M1PWM5);GPIOPinConfigure(GPIO_PF2_M1PWM6);GPIOPinConfigure(GPIO_PF3_M1PWM7); how can I solve this problem? THANKS!!! Quote Share this post Link to post Share on other sites
peppeg85 0 Posted September 27, 2013 searching in the internet i found the following site: http://codeandlife.com/2012/10/30/stellaris-launchpad-pwm-tutorial/ is better to use the timers as pwm modules due the absence of a dedicated pwm module?? Quote Share this post Link to post Share on other sites
lawrence_jeff 3 Posted September 28, 2013 searching in the internet i found the following site: http://codeandlife.com/2012/10/30/stellaris-launchpad-pwm-tutorial/ is better to use the timers as pwm modules due the absence of a dedicated pwm module?? If you are using a stellaris launchpad that is your only option. My code example was for a tiva launchpad which has the pwm module. Quote Share this post Link to post Share on other sites
peppeg85 0 Posted September 30, 2013 ok, thanks! Quote Share this post Link to post Share on other sites
RAKSH 1 Posted October 11, 2013 Unfortunately ,I'm not getting any PWM output on the Led's ,I copy pasted the same code . Quote Share this post Link to post Share on other sites
superbrew 0 Posted October 29, 2013 Unfortunately ,I'm not getting any PWM output on the Led's , I copy pasted the same code . This code worked for me. Are you getting any errors or warnings? Quote Share this post Link to post Share on other sites
RAKSH 1 Posted October 29, 2013 No I tried it again ,I am not getting any errors and warnings .What am i expected to observe in the LED'sI just see a whitish light without any fading .I tried matching the dutycycle and changing the period according to my needs to achieve fading ,but to no avail . Quote Share this post Link to post Share on other sites
thequila 0 Posted November 6, 2013 Solving undefined identifiers error: #define GPIO_PB6_M0PWM0 0x00011804 #define GPIO_PB7_M0PWM1 0x00011C04 #define GPIO_PB4_M0PWM2 0x00011004 #define GPIO_PB5_M0PWM3 0x00011404 #define GPIO_PE4_M0PWM4 0x00041004 #define GPIO_PE5_M0PWM5 0x00041404 #define GPIO_PF1_M1PWM5 0x00050405 #define GPIO_PF2_M1PWM6 0x00050805 #define GPIO_PF3_M1PWM7 0x00050C05 Quote Share this post Link to post Share on other sites
bluehash 1,578 Posted November 6, 2013 Solving undefined identifiers error: #define GPIO_PB6_M0PWM0 0x00011804 #define GPIO_PB7_M0PWM1 0x00011C04 #define GPIO_PB4_M0PWM2 0x00011004 #define GPIO_PB5_M0PWM3 0x00011404 #define GPIO_PE4_M0PWM4 0x00041004 #define GPIO_PE5_M0PWM5 0x00041404 #define GPIO_PF1_M1PWM5 0x00050405 #define GPIO_PF2_M1PWM6 0x00050805 #define GPIO_PF3_M1PWM7 0x00050C05 Did you include the gpio.h file and driverlib? Quote Share this post Link to post Share on other sites
thequila 0 Posted November 6, 2013 Yes. gpio.h uses pin_map.h, which has no declaration of these pins for StellarisPad (at least in energia). I took those #defines directly from TivaWare C Series 1.1 pin_map.h. It seems to work for Tiva pads. Quote Share this post Link to post Share on other sites
Bernard 7 Posted December 24, 2013 Hi, I tried porting it to Energia TIVA board : #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 "inc/tm4c123gh6pm.h" //added void setup() { unsigned long ulPeriod; //Set the clock SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //Configure PWM Clock to match system SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // Enable the peripherals used by this program. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //The Tiva Launchpad has two modules (0 and 1). Module 1 covers the LED pins ulPeriod = SysCtlClockGet() / 200; //PWM frequency 200HZ //Configure PF1,PF2,PF3 Pins as PWM GPIOPinConfigure(GPIO_PF1_M1PWM5); GPIOPinConfigure(GPIO_PF2_M1PWM6); GPIOPinConfigure(GPIO_PF3_M1PWM7); GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); //Configure PWM Options //PWM_GEN_2 Covers M1PWM4 and M1PWM5 //PWM_GEN_3 Covers M1PWM6 and M1PWM7 See page 207 4/11/13 DriverLib doc PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); //Set the Period (expressed in clock ticks) PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ulPeriod); PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ulPeriod); //Set PWM duty-50% (Period /2) PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,ulPeriod/2); PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6,ulPeriod/2); PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7,ulPeriod/2); // Enable the PWM generator PWMGenEnable(PWM1_BASE, PWM_GEN_2); PWMGenEnable(PWM1_BASE, PWM_GEN_3); // Turn on the Output pins PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT |PWM_OUT_6_BIT|PWM_OUT_7_BIT, true); } void loop() { } I get errors: pwmtiva.ino:28:22: error: 'GPIO_PF1_M1PWM5' was not declared in this scope apwmtiva.ino:29:22: error: 'GPIO_PF2_M1PWM6' was not declared in this scope apwmtiva.ino:30:22: error: 'GPIO_PF3_M1PWM7' was not declared in this scope I don't understand because GPIO_PF1_M1PWM5, GPIO_PF1_M1PWM6, GPIO_PF1_M1PWM7 are defined in driverlib/pin_map.h. Thanks for help. Salutations. Bernard Quote Share this post Link to post Share on other sites
Bernard 7 Posted December 24, 2013 Hi again, Just put #define PART_TM4C123GH6PM before #includes. It compiles and load but no pwm effect .... Quote Share this post Link to post Share on other sites
gonya707 2 Posted December 25, 2013 Hi @@brownfox I think you have to include PART_TM4C123GH6PM here, in the project properties, under predefined symbols: In your case use PART_TM4C123GH6PM instead of the LM4F120. Happy Christmas Quote Share this post Link to post Share on other sites
Bernard 7 Posted December 25, 2013 hi, Thanks gonya707 but I don't use CCS. Just trying to port your example to Energia. happy Christmas Bernard. Quote Share this post Link to post Share on other sites