PWM Application for CYW943907AEVAL1F
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
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_6 | J12:4 | PWM, GPIO | WICED_PWM_1 |
WICED_GPIO_7 | J12:3 | PWM, GPIO | WICED_PWM_2 |
WICED_GPIO_12 | J10:6 | PWM, GPIO | WICED_PWM_3 |
WICED_GPIO_11 | J10:7 | PWM, GPIO | WICED_PWM_4 |
WICED_GPIO_17 | J6:1 | PWM, GPIO | WICED_PWM_5 |
WICED_GPIO_3 | J10:4 | PWM, GPIO | WICED_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
- 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/.
- Create a make target for the application. Example: snip.pwm-CYW943907AEVAL1F download run.
- Connect CYW943907AEVAL1F EVK to PC and run the make target by double clicking on it.
- After the application is compiled and downloaded, it will start running. You can see the messages in serial terminal like "putty" or "Tera Term".
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.
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.
- Tags:
- cyw943907aeval1f
- pwm
- Subscribe to RSS Feed
- Mark Article as New
- Mark Article as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Hi,
the documentation says:
[in] | duty_cycle | : Duty cycle of signal as a floating-point percentage (0.0 to 100.0) |
but within your code (pwm.zip) duty cycle is limited to 99: duty_cycle=99; /*Can't have 100 duty cycle*/
That's my obeservation, too, wiced_pwm_init() does not support 0 and 100 😞
#Holger
P.S.: Also the description ("Application is written in such a way that the duty cycle get reduced by 5% every time USER_1 button is pressed") is 'wrong', as the Duty Cycle gets increased (duty_cycle+=5.0;). Because the LED is low-active, the relation between duty cycle and brightness is inverted 🙂