Blink LED using PWM

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I am a Japanese student.

I want to let to blink 3 colors LED using PWM control.

Please tell me!

I can't speak English very wall.

Sorry.

0 Likes
1 Solution
Anonymous
Not applicable

Hello, here is an example of what you can do.


Include Library

#include "pwm.h"
#include "gpiodriver.h"


Define Macros

#define LED_RED    26  /* PWM 0 */
#define LED_BLUE   27  /* PWM 1 */
#define LED_GREEN  28  /* PWM 2 */

#define GPIO_PORT(x)  (x/16)
#define GPIO_PIN(x)   (x%16)

#define ENABLE_LED_RED    PWM0_OUTPUT_ENABLE_P26
#define ENABLE_LED_BLUE   PWM1_OUTPUT_ENABLE_P27
#define ENABLE_LED_GREEN  PWM2_OUTPUT_ENABLE_P28

#define DISABLE_LED_GPIO     GPIO_INPUT_ENABLE | GPIO_PULL_DOWN
#define LED_RED_CHANNEL      (PWM0)
#define LED_BLUE_CHANNEL     (PWM1)
#define LED_GREEN_CHANNEL    (PWM2)

     Note: depending on which chip you are using, the GPIO Pins might change


Enable LED

     // enable
     gpio_configurePin(GPIO_PORT(LED_RED), GPIO_PIN(LED_RED), ENABLE_LED_RED, 0); 
     pwm_start( LED_RED_CHANNEL, LHL_CLK, 0x000 , 0);

     // pwm_start( id, clk, toggleCount, initCount);
     // Output Voltage  | Toggle Count (Found these values by trial & error)
     // --------------------------------------------
     // ~ (4/4) V_MAX  |    0x000
     // ~ (3/4) V_MAX  |    0x100
     // ~ (2/4) V_MAX  |    0x210
     // ~ (1/4) V_MAX  |    0x315

     Note: depending on the hardware configuration, the V_MAX may change


Disable LED

// disable
     gpio_configurePin(GPIO_PORT(LED_RED), GPIO_PIN(LED_RED), DISABLE_LED_GPIO, 0);
     pwm_disableChannel( 1 << LED_RED_CHANNEL );

pastedImage_4.jpg

References

BCM2073XS GPIO Basics

How to turn on LED

Different Frequencies for PWM

James

View solution in original post

4 Replies
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog

You might want to take a look at this thread: Re: How to turn on LED


vsesto figured out how to make this work.

Unfortunately, we do not make this easy for the beginner.

0 Likes
Anonymous
Not applicable

Thank you!

And where should I see to get information of process writing a program on WICED-Smart-SDK?

0 Likes
Anonymous
Not applicable

I think below blog would help your understanding.

WICED Smart User's Guide

<WICED-Smart-SDK>/Apps/pwm_tones sample application controls buzzer on the EVB through PWM.

Anonymous
Not applicable

Hello, here is an example of what you can do.


Include Library

#include "pwm.h"
#include "gpiodriver.h"


Define Macros

#define LED_RED    26  /* PWM 0 */
#define LED_BLUE   27  /* PWM 1 */
#define LED_GREEN  28  /* PWM 2 */

#define GPIO_PORT(x)  (x/16)
#define GPIO_PIN(x)   (x%16)

#define ENABLE_LED_RED    PWM0_OUTPUT_ENABLE_P26
#define ENABLE_LED_BLUE   PWM1_OUTPUT_ENABLE_P27
#define ENABLE_LED_GREEN  PWM2_OUTPUT_ENABLE_P28

#define DISABLE_LED_GPIO     GPIO_INPUT_ENABLE | GPIO_PULL_DOWN
#define LED_RED_CHANNEL      (PWM0)
#define LED_BLUE_CHANNEL     (PWM1)
#define LED_GREEN_CHANNEL    (PWM2)

     Note: depending on which chip you are using, the GPIO Pins might change


Enable LED

     // enable
     gpio_configurePin(GPIO_PORT(LED_RED), GPIO_PIN(LED_RED), ENABLE_LED_RED, 0); 
     pwm_start( LED_RED_CHANNEL, LHL_CLK, 0x000 , 0);

     // pwm_start( id, clk, toggleCount, initCount);
     // Output Voltage  | Toggle Count (Found these values by trial & error)
     // --------------------------------------------
     // ~ (4/4) V_MAX  |    0x000
     // ~ (3/4) V_MAX  |    0x100
     // ~ (2/4) V_MAX  |    0x210
     // ~ (1/4) V_MAX  |    0x315

     Note: depending on the hardware configuration, the V_MAX may change


Disable LED

// disable
     gpio_configurePin(GPIO_PORT(LED_RED), GPIO_PIN(LED_RED), DISABLE_LED_GPIO, 0);
     pwm_disableChannel( 1 << LED_RED_CHANNEL );

pastedImage_4.jpg

References

BCM2073XS GPIO Basics

How to turn on LED

Different Frequencies for PWM

James