Skip navigation
Home > All Places > WICED Studio Wi-Fi/Combo > WICED Studio Wi-Fi/Combo Forums > Blog > 2017 > November > 30

Introduction

 

This blog discusses about the usage of PWM module of CYW943907AEVAL1F in WICED SDK 6.0. The CYW43907 provides up to six independent PWM channels. The PWM pins for CYW943907AEVAL1F EVK are as shown in the table below.

 

Enum ID

Header

Conn

Function

WICED Peripheral

Alias

WICED_GPIO_6J12:4PWM, GPIOWICED_PWM_1
WICED_GPIO_7J12:3PWM, GPIOWICED_PWM_2
WICED_GPIO_12J10:6PWM, GPIOWICED_PWM_3
WICED_GPIO_11J10:7PWM, GPIOWICED_PWM_4
WICED_GPIO_17J6:1PWM, GPIOWICED_PWM_5
WICED_GPIO_3J10:4PWM, GPIOWICED_PWM_6

 

The PWM pins can be re-assigned to different I/Os using the pin mux functionality in "platform_pwm_peripherals" at

<WICED SDK>/43xxx_Wi-Fi/platforms/CYW943907AEVAL1F/platform.c.

 

In order to re-assign a PWM, just change the first argument in the entry for that row to the desired pin name. For example, to re-assign WICED_PWM_1 to PIN_GPIO_0, just change PIN_GPIO_10 to PIN_GPIO_0.

 

const platform_pwm_t platform_pwm_peripherals[] =

{

   [WICED_PWM_1]  = {PIN_GPIO_10,  PIN_FUNCTION_PWM0, },   /* or PIN_GPIO_0, PIN_GPIO_8,  PIN_GPIO_12, PIN_GPIO_14, PIN_GPIO_16, PIN_PWM_0   */

...

};

 

PWM Features

 

The following features apply to the PWM channels:

  • Each channel is a square wave generator with a programmable duty cycle.
  • Each channel generates its duty cycle by dividing down the input clock.
  • Both the high and low duration of the duty cycle can be divided down independently by a 16-bit divider register.
  • Each channel can work independently or update simultaneously.
  • Pairs of PWM outputs can be inverted for devices that need a differential output.
  • Continuous or single pulses can be generated.
  • The input clock can either be a high-speed clock from a PLL channel or a lower speed clock at the crystal frequency.

 

Different APIs in WICED for PWM

 

PWM APIs used in WICED are given below.

 

wiced_result_t wiced_pwm_init ( wiced_pwm_t pwm, uint32_t frequency, float duty_cycle )

 

This API initializes a PWM pin. Prepares a Pulse-Width Modulation pin for use. Does not start the PWM output.

 

     Parameters
[in]pwm: The PWM interface which should be initialized
[in]frequency: Output signal frequency in Hertz
[in]duty_cycle: Duty cycle of signal as a floating-point percentage (0.0 to 100.0)

 

     Returns
     WICED_SUCCESS : on success.
     WICED_ERROR : if an error occurred with any step

 

wiced_result_t wiced_pwm_start ( wiced_pwm_t pwm )

 

This API starts Pulse-Width Modulation signal output on a PWM pin

 

     Parameters
[in]pwm: The PWM interface which should be started

 

     Returns
     WICED_SUCCESS : on success.
     WICED_ERROR : if an error occurred with any step

 

wiced_result_t wiced_pwm_stop ( wiced_pwm_t pwm )

 

This API stops output on a PWM pin.

 

     Parameters
[in]pwm: The PWM interface which should be stopped

 

     Returns
     WICED_SUCCESS : on success.
     WICED_ERROR : if an error occurred with any step

APIs are explained in <WICED SDK>/43xxx_Wi-Fi/doc/API.html at Components > Platform functions > PWM and also at <WICED SDK>/43xxx_Wi-Fi/include/wiced_platform.h in WICED SDK6.0.

 

Testing the Application

 

  1. Download the PWM application attached with this blog post extract and add the downloaded folder "pwm" to "snip" folder in <WICED SDK>/43xxx_Wi-Fi/apps/.
  2. Create a make target for the application. Example: snip.pwm-CYW943907AEVAL1F download run.
  3. Connect CYW943907AEVAL1F EVK to PC and run the make target by double clicking on it.
  4. After the application is compiled and downloaded, it will start running. You can see the messages in serial terminal like "putty" or "Tera Term".

output.JPG

 

You can change the frequency of PWM by using the API wiced_pwm_init ( wiced_pwm_t pwm, uint32_t frequency, float duty_cycle ). The figure below shows the screen capture of PWM with 1MHz frequency.

T0001.BMP

 

Once the application starts running, whenever the button USER_1 is pressed, interrupt service routine (button1_isr()) is called. Application is written in such a way that the duty cycle get reduced by 5% every time USER_1 button is pressed hence the brightness of LED_1 reduces.

Filter Blog

By date:
By tag: