////Init (PF0) SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
//Set clock directly from crystal SysCtlPWMClockSet(SYSCTL_PWMDIV_16);
// Set GPIO F0 as PWM pin. GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
// Compute the PWM period based on the system clock.ulPWMPeriod = SysCtlClockGet() / 1000;
//Configure PWM PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, ulPWMPeriod );
//Set Pulse Width PWMPulseWidthSet(PWM_BASE, PWM_OUT_0, (unsigned long)(ulPWMPeriod * 50));
//Enable Output signal PWMOutputState(PWM_BASE, PWM_OUT_0_BIT, true);
// Enable the PWM generator. PWMGenEnable(PWM_BASE, PWM_GEN_0);
What is missing? I'm not seeing any activity on the PF0 PWM signal at all?
PF0 defaults into "special function" mode on certain Stellaris MCUs - this may be the cause of your issue. Earlier (your I2C post) Stellaris Mitch requested that you identify your chosen MCU - without that knowledge we are forced to "guess."
Assuming that your MCU is among those which specially treats - or locks PF0 - you must first unlock PF0 and then place it into PWM mode. (assuming that is an allowed use of PF0)
There is a sticky, guideline post atop this forum which outlines forum procedures which will benefit your future posts. (and those who choose to respond...)
Thanks for any help you can offer. The processor is the lm3s9d96. Would I be better off using a different pin?
Stephen Griffiths Would I be better off using a different pin?
Absolutement - mon ami! KISS always best - you have much to read/learn/master - suggest that you initially study your design goals - then focus on individual goal achievement. (dealing with "special pins" - at this time - is unnecessary/unwanted distraction - your idea of choosing a, "less restricted/suspect pin" makes perfect sense...)
Be sure to read/review
a) MCU datasheet
b) numerous Stellaris code examples which relate to your project's needs
c) StellarisWare Driver Library "User Guide" details PWM functions and provides brief, code examples. (beware - peeve of mine/others - while SW-DRL User Guide's code examples are tested - they most always "avoid" the very necessary, "Pre-set-ups/configs" - without which the example code may, "fail to perform!" Frustration could be reduced/perhaps prevented by "boiler-plate reminder," "Note: Insure that any/all pins/ports referenced by this code example have been properly/fully configured." (and especially have their clocks, "SysCtlEnabled()"...)
Confess to very quick scan of your code - basically looks good. Change to different pin - continue w/modified code Configs/Set-Ups (due to new pin - possibly new port) and try/report. You're almost there...
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); SysCtlDelay(1000); GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_3, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); GPIODirModeSet(GPIO_PORTJ_BASE, GPIO_PIN_3, GPIO_DIR_MODE_OUT); GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_3, m_PowerState);
////Init MLP PWM Brightness Control (PF0) SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); SysCtlDelay(1000);
Got it. This is the initialization that finally worked. Thanks for everyone who helped out on this.
GPIOPinConfigure(GPIO_PF0_PWM0); GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0); PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); SysCtlDelay(10);
// Compute the PWM period based on the system clock. m_PWMPeriod = SysCtlClockGet() / m_PWMFrequency; unsigned long width = (unsigned long)(m_PWMPeriod * 50* 0.01);
printf("MLP PWM: period=%d, freq=%d, dutycycle=%d width=%d\n", m_PWMPeriod, m_PWMFrequency, m_DutyCyclePercent, width);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, m_PWMPeriod); SysCtlDelay(10);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, width); SysCtlDelay(10);
PWMGenEnable(PWM0_BASE, PWM_GEN_0); SysCtlDelay(10);
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true); SysCtlDelay(10);
Stephen Griffiths initialization that worked. Thanks for everyone (1)
Ahh... Success has many fathers... failure few. (where is that pistol? one way to escape dreary basement...)