This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PWM

I`ve been trying to vary the brightness of the LED using PWM.....but the LED remains bright throughout...whts wrong??

/*
 * main.c
 */
#include<stdint.h>
#include<stdbool.h>
#include"inc/hw_memmap.h"
#include"inc/hw_gpio.h"
#include"inc/hw_types.h"
#include"driverlib/gpio.h"
#include"driverlib/sysctl.h"
#include"driverlib/pin_map.h"
#include"driverlib/pwm.h"

void main()
{

    int i;
    i =0;
    SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
    SysCtlClockSet(SYSCTL_PWMDIV_64);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

    GPIOPinConfigure(GPIO_PF1_M1PWM5);
    GPIOPinTypePWM(GPIO_PORTF_BASE,GPIO_PIN_1);

    PWMGenConfigure(PWM1_BASE,PWM_GEN_2,PWM_GEN_MODE_DOWN|PWM_GEN_MODE_NO_SYNC);
    PWMGenPeriodSet(PWM1_BASE,PWM_GEN_2,5000);

    PWMPulseWidthSet(PWM1_BASE,PWM_OUT_5,20);

    PWMGenEnable(PWM1_BASE,PWM_GEN_2);
    PWMOutputState(PWM1_BASE,PWM_OUT_5_BIT,true);

    while(1)
    {
        SysCtlDelay(800000000);
        PWMPulseWidthSet(PWM1_BASE,PWM_OUT_5,i);

        i = i+200;
        if(i == 5000);
        {
            i =0;
        }
    }
}

  • shreyas bhujbal said:
    SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

    For starters - you cannot "use the PLL" AND "SYSDIV_1."   The MCU cannot accommodate the so high speed you've set.

    Have you inserted a break point at the entry to your while loop?   What's the condition of the Led then?

    Always - in cases such as this - it proves "wise" to first force your pin (PF1 here) into GPIO Out mode - and toggle - and observe.   Only then should you "repurpose" that pin.

  • alright i did what you told me to....but I kept the led connected to PF1.......I even kept the duty cycle to 0.....but its just stays switched on ......whats wrong??
  • shreyas bhujbal said:
    ... i  (I) did what you told me to

    If that's true - did the Led light output change when you switched to GPIO Out mode?

    And - what was the (requested) result when you "broke" @ the entry to the while loop?

    Your writing does not effectively convey either fact - and both are important - don't you agree?

  • Hello Shreyas,

    First things first. Diagnostics: Use the LED pin in GPIO mode and switch it ON and OFF. This will help check if the LED pin and LED itself are fine. Then we can investigate the PWM software.

    Regards
    Amit