- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to get the PWM working on the output pin to drive an external LED. However, in using the temp_control sample application ( although a different board ) , I cannot get it to work . Any ideas what I am doing wrong. I want to use the WIFI IOT board for this application ( and not the other boards ) . Does it support external PWM to drive an LED ( for example? )
thanks
Rob
Solved! Go to Solution.
- Labels:
-
Wifi+Bluetooth
- Tags:
- teaser
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I assume you're using Avnet BCM94343W IoT Starter Kit as mwf_mmfae guessed earlier in this post.
By comparing their platform file and HW User Guide (Avnet website), I think you're doing wrong modifications.
1. It looks like you modified definition of the first two PWM peripherals:
WICED_PWM_1 : WICED_GPIO_11 => WICED_GPIO_17
WICED_PWM_2 : WICED_GPIO_12 => WICED_GPIO_25
I doubt that these are valid since MCU only supports limited alternatives on each pin.
Forgive me if you did examined the SPEC carefully. I didn't, sorry.
2. Assume stock platform definition, compare with HW User Guide p.12 to find if there is pin-out.
You can see that only WICED_PWM_1/2/3/4/5, WICED_GPIO_11/12/2/3/4 accordingly, are available on connectors : D15,D14,A0/1/2.
I guess PWM should work on these 5 pins.
This should work in your case:
wiced_pwm_init(WICED_PWM_1/2/3/4/5, 36000, duty_cycle);
On my platform (non-Avnet BCM94343W) PWM works on the according pin of MCU Port Pin A1/2/3.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've studied this topic several weeks ago.
On my SPIL-N08-based platforms PWM does work.
Here's how I tested:
Step 1: Check your platform definition
/* PWM peripherals. Used by WICED/platform/MCU/wiced_platform_common.c */
const platform_pwm_t platform_pwm_peripherals[] =
{
[WICED_PWM_1] = {TIM4, 1, RCC_APB1Periph_TIM4, GPIO_AF_TIM4, &platform_gpio_pins[WICED_GPIO_24]},
[WICED_PWM_2] = {TIM4, 2, RCC_APB1Periph_TIM4, GPIO_AF_TIM4, &platform_gpio_pins[WICED_GPIO_25]},
[WICED_PWM_3] = {TIM2, 2, RCC_APB1Periph_TIM2, GPIO_AF_TIM2, &platform_gpio_pins[WICED_GPIO_2] }, /* or TIM5/Ch2 */
[WICED_PWM_4] = {TIM2, 3, RCC_APB1Periph_TIM2, GPIO_AF_TIM2, &platform_gpio_pins[WICED_GPIO_3] }, /* or TIM5/Ch3, TIM9/Ch1 */
[WICED_PWM_5] = {TIM2, 4, RCC_APB1Periph_TIM2, GPIO_AF_TIM2, &platform_gpio_pins[WICED_GPIO_4] }, /* or TIM5/Ch4, TIM9/Ch2 */
[WICED_PWM_6] = {TIM2, 1, RCC_APB1Periph_TIM2, GPIO_AF_TIM2, &platform_gpio_pins[WICED_GPIO_6] }, /* or TIM2_CH1_ETR, TIM8/Ch1N */
[WICED_PWM_7] = {TIM3, 1, RCC_APB1Periph_TIM3, GPIO_AF_TIM3, &platform_gpio_pins[WICED_GPIO_7] }, /* or TIM1_BKIN, TIM8_BKIN, TIM13/Ch1*/
[WICED_PWM_8] = {TIM3, 2, RCC_APB1Periph_TIM3, GPIO_AF_TIM3, &platform_gpio_pins[WICED_GPIO_8] }, /* or TIM8/Ch1N, TIM14/Ch1 */
[WICED_PWM_9] = {TIM5, 2, RCC_APB1Periph_TIM5, GPIO_AF_TIM5, &platform_gpio_pins[WICED_GPIO_2] }, /* or TIM2/Ch2 */
};
Contact hardware vendor if you find problem locating the GPIO pins.
Step 2: Try the code below
/*
* Usage:
* WICED_PWM_1 => wiced_pwm_number = 1
* WICED_PWM_2 => wiced_pwm_number = 2
*/
void test_pwm(int wiced_pwm_number)
{
wiced_result_t result;
float duty_cycle = 50.0f;
if (wiced_pwm_number < 1 || wiced_pwm_number > WICED_PWM_MAX)
{
WPRINT_APP_ERROR(("wiced_pwm_number = %d, should be 1 ~ %d\n", wiced_pwm_number, WICED_PWM_MAX));
return;
}
wiced_pwm_number -= 1;
while (1)
{
WPRINT_APP_INFO(("WICED_PWM_%d : %.1f\n", wiced_pwm_number+1, duty_cycle));
result = wiced_pwm_init(wiced_pwm_number, 2000, duty_cycle);
if (result != WICED_SUCCESS)
{
WPRINT_APP_INFO(("wiced_gpio_init(WICED_PWM_%d, 2000, %.1f) = %d\n", wiced_pwm_number+1, duty_cycle, result));
return;
}
result = wiced_pwm_start(wiced_pwm_number);
if (result != WICED_SUCCESS)
{
WPRINT_APP_INFO(("wiced_pwm_start(WICED_PWM_%d) = %d\n", wiced_pwm_number+1, result));
return;
}
wiced_rtos_delay_milliseconds(1000);
duty_cycle += 10.0f;
if (duty_cycle > 100.0f)
{
duty_cycle = 0.0f;
}
}
}
You should be able to measure varying voltage on the selected pin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You may want to post this to the Avnet forum as well. Note that you will need their updated platform files for that specific board. They also have alot of documentation available for the board here on the cloudconnectkits site: Avnet BCM4343W IoT Starter Kit | Avnet CloudConnectKits
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I could not find these definitions in wiced_platform_common.c file. I added the but after the first init the application stopped and did not continue.
I am suspecting that the PWM definitions are not correct for that board. I will see what I can hunt down.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Got on PIN that at least did not hang the program ( GPIO 17 ) but no voltage output from ground to GPIO 17 ( or current ) . to detect the duty cycle , will it need more external resistors ( pull up or pull down )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I modified my code to add in the above . It will happily pulse a internal LED in the right scheme but will not pulse PWM . I must be missing something obvious. I have an IR diode grounded and GPIO_17 connected to other side of diode. ( polarity fully tested on hardware ) and IR pulses measured on a Arduino unit.
Confused.
//+=============================================================================
// Sends an IR mark for the specified number of microseconds.
// The mark output is modulated at the PWM frequency.
//
static void space (unsigned int time)
{
#define CPU_CLOCK_HZ ( 96200000 )
#define CPU_CYCLES_PER_MICROSECOND ( CPU_CLOCK_HZ / 1000000 )
wiced_result_t result = WICED_SUCCESS;
const wiced_pwm_number= WICED_PWM_1;
uint32_t current_time;
uint32_t duration;
uint32_t elapsed_time = 0;
//TIMER_ENABLE_PWM; // Enable pin 3 PWM output
// if (time > 0) custom_delay_usec(time);
// Custom turn off the LED for exactly the SPACE time
// no duty cycle since its off
// test with Samsung Protocol at 38Khz frequency. Hard code to 26 usec pulse
// LED off ,
WPRINT_APP_INFO(("SPACE \n"));
wiced_gpio_output_low( WICED_LED2 );
result = wiced_pwm_stop(wiced_pwm_number);
// cycle thru the time
current_time = host_platform_get_cycle_count( );
duration = ( time * CPU_CYCLES_PER_MICROSECOND );
WPRINT_APP_INFO(("Space . %d\n", wiced_pwm_number ));
WPRINT_APP_INFO(("duration %d \n", duration ));
while ( elapsed_time < duration )
{
elapsed_time = host_platform_get_cycle_count( ) - current_time;
}
}
static void mark2( int high_level )
{
#define CPU_CLOCK_HZ ( 96200000 )
#define CPU_CYCLES_PER_MICROSECOND ( CPU_CLOCK_HZ / 1000000 )
uint32_t current_time;
uint32_t duration;
uint32_t elapsed_time = 0;
// use working PWM ( GPIO_17 )
int wiced_pwm_number= WICED_PWM_1;
wiced_result_t result = WICED_SUCCESS;
// set LED and PWM to high
wiced_gpio_output_high( WICED_LED2 );
result = wiced_pwm_start(wiced_pwm_number);
if ( result != WICED_SUCCESS )
{
WPRINT_APP_INFO(("FAIL MARK2" ));
}
// cycle thru the time
current_time = host_platform_get_cycle_count( );
duration = ( high_level * CPU_CYCLES_PER_MICROSECOND );
WPRINT_APP_INFO(("MARK3 . %d\n", wiced_pwm_number ));
WPRINT_APP_INFO(("duration %d \n", duration ));
while ( elapsed_time < duration )
{
elapsed_time = host_platform_get_cycle_count( ) - current_time;
}
// set LED and PWM to Low
result = wiced_pwm_stop(wiced_pwm_number);
wiced_gpio_output_low( WICED_LED2 );
}
static void sendSamung_Manually ( )
{
#define SAMSUNG_BITS 32
#define SAMSUNG_HDR_MARK 5000
#define SAMSUNG_HDR_SPACE 5000
#define SAMSUNG_BIT_MARK 560
#define SAMSUNG_ONE_SPACE 1600
#define SAMSUNG_ZERO_SPACE 560
#define SAMSUNG_RPT_SPACE 2250
wiced_result_t result;
int wiced_pwm_number = WICED_PWM_1;
float duty_cycle = 100.0f;
// wiced_pwm_number -= 1;
result = wiced_pwm_init(wiced_pwm_number, 36000, duty_cycle);
if (result != WICED_SUCCESS)
{
WPRINT_APP_INFO(("wiced_gpio_init(WICED_PWM_%d, 2000, %.1f) = %d\n", wiced_pwm_number+1, duty_cycle, result));
WPRINT_APP_INFO(("Fail First\n"));
return;
}
// initiate and start the PWM pin
WPRINT_APP_INFO(("WICED_PWM_%d : %.1f\n", wiced_pwm_number, duty_cycle));
result = wiced_pwm_start(wiced_pwm_number);
if (result != WICED_SUCCESS)
{
WPRINT_APP_INFO(("Fail Second, wiced_pwm_start(WICED_PWM_%d) = %d\n", wiced_pwm_number+1, result));
return;
}
else
{
WPRINT_APP_INFO(("Start Pass \n"));
}
if (result != WICED_SUCCESS)
{
WPRINT_APP_INFO(("Fail\n"));
return;
}
WPRINT_APP_INFO(("Start Marking\n"));
mark2( SAMSUNG_HDR_MARK);
space ( SAMSUNG_HDR_SPACE);
// 4 ,5
mark2 ( SAMSUNG_BIT_MARK);
space ( SAMSUNG_ONE_SPACE);
... PWM defintions
GPIO_17 is mapped to PWM_out on the BCM94343W
const platform_pwm_t platform_pwm_peripherals[] =
{
[WICED_PWM_1] = {TIM4, 1, RCC_APB1Periph_TIM4, GPIO_AF_TIM4, &platform_gpio_pins[WICED_GPIO_17]},
[WICED_PWM_2] = {TIM4, 2, RCC_APB1Periph_TIM4, GPIO_AF_TIM4, &platform_gpio_pins[WICED_GPIO_25]},
[WICED_PWM_3] = {TIM2, 2, RCC_APB1Periph_TIM2, GPIO_AF_TIM2, &platform_gpio_pins[WICED_GPIO_2] }, /* or TIM5/Ch2 */
[WICED_PWM_4] = {TIM2, 3, RCC_APB1Periph_TIM2, GPIO_AF_TIM2, &platform_gpio_pins[WICED_GPIO_3] }, /* or TIM5/Ch3, TIM9/Ch1 */
[WICED_PWM_5] = {TIM2, 4, RCC_APB1Periph_TIM2, GPIO_AF_TIM2, &platform_gpio_pins[WICED_GPIO_4] }, /* or TIM5/Ch4, TIM9/Ch2 */
[WICED_PWM_6] = {TIM2, 1, RCC_APB1Periph_TIM2, GPIO_AF_TIM2, &platform_gpio_pins[WICED_GPIO_6] }, /* or TIM2_CH1_ETR, TIM8/Ch1N */
[WICED_PWM_7] = {TIM3, 1, RCC_APB1Periph_TIM3, GPIO_AF_TIM3, &platform_gpio_pins[WICED_GPIO_7] }, /* or TIM1_BKIN, TIM8_BKIN, TIM13/Ch1*/
[WICED_PWM_8] = {TIM3, 2, RCC_APB1Periph_TIM3, GPIO_AF_TIM3, &platform_gpio_pins[WICED_GPIO_8] }, /* or TIM8/Ch1N, TIM14/Ch1 */
[WICED_PWM_9] = {TIM5, 2, RCC_APB1Periph_TIM5, GPIO_AF_TIM5, &platform_gpio_pins[WICED_GPIO_2] }, /* or TIM2/Ch2 */
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I assume you're using Avnet BCM94343W IoT Starter Kit as mwf_mmfae guessed earlier in this post.
By comparing their platform file and HW User Guide (Avnet website), I think you're doing wrong modifications.
1. It looks like you modified definition of the first two PWM peripherals:
WICED_PWM_1 : WICED_GPIO_11 => WICED_GPIO_17
WICED_PWM_2 : WICED_GPIO_12 => WICED_GPIO_25
I doubt that these are valid since MCU only supports limited alternatives on each pin.
Forgive me if you did examined the SPEC carefully. I didn't, sorry.
2. Assume stock platform definition, compare with HW User Guide p.12 to find if there is pin-out.
You can see that only WICED_PWM_1/2/3/4/5, WICED_GPIO_11/12/2/3/4 accordingly, are available on connectors : D15,D14,A0/1/2.
I guess PWM should work on these 5 pins.
This should work in your case:
wiced_pwm_init(WICED_PWM_1/2/3/4/5, 36000, duty_cycle);
On my platform (non-Avnet BCM94343W) PWM works on the according pin of MCU Port Pin A1/2/3.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks so much. Completely misread the hardware spec.. its getting there.. moved on two turning the PCM pin off completely off and on.