PWM control in BLE SDK

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

cross mob
LiCh_2157216
Level 1
Level 1

We use pwm_transitionToSubstituteValues() to control PWM, but it failed even the return value is true.

Is there any other PWM function?

The sample code we use is proximity_plus() in SDK 1.0.1

add the code in bleprox_mod_Create

gpio_configurePin(1,12,GPIO_OUTPUT_ENABLE, 0); // P28

// Configure ACLK as the reference clock of the PWM

aclk_configure(256000, ACLK1, ACLK_FREQ_24_MHZ);

ass the following function in the callback function bleprox_mod_appFineTimerCb()

pwm_start(PWM2,PMU_CLK,toggle_val,init_value);

Regards.

Licter

0 Likes
1 Solution

Did you disable output on the GPIO when you reset the PWM (and you can insert an internal pull-down/pull-up)? Do you have anything connected to the GPIO? If yes, then can you try disconnecting it and then see if the PWM goes low when you reset it?

        case 6:
           // Disable channel.
           pwm_setReset(PWM0, 1);
           gpio_configurePin(26/16, 26%16, GPIO_OUTPUT_DISABLE | GPIO_PULL_DOWN, 0);
           break;

View solution in original post

0 Likes
22 Replies
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog
Im checking with the development team to see if we can provide any sample application code which will assist with the understanding of utilizing the BCM20732S PWM capability within an application.

At this point, I am only aware of the Marcos, Enumerations and Functions defined within DocAPIIndex.html (Components->Peripheral Drivers->PWM)
0 Likes
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog
I have conformed with the team that calling pwm_start() every time the fine timer expires is not optimal; once you call start, it will start toggling the GPIO (P28 in this case).

I am checking to see if we can recommend a more efficient means of calling the same function.
0 Likes
LiCh_2157216
Level 1
Level 1
More detail sample code or document of API is helpful for us.

We tested the API for PWM and GPIO control, but we cant let it work well.

Only workable is the the initial setting in BLE_PROFILE_GPIO_CFG bleprox_mod_gpio_cfg ={ }

As we set the initial status is high for gpio, we cant find the way to pull it to low in application level.

😞
0 Likes
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog
Take a look at the RAM based automation_io client application thats provided with the SDK. 

I spoke with a developer and he was pretty sure that this application should provide working PWM code.
0 Likes
Anonymous
Not applicable
Is there any way I can observe what is going on in automation_io.c? I was playing around with hellosensor.c and it was pretty intuitive to see the different things I could do(press the button to have a count, write a number to have the LED flash a certain number times). Are there things I can check to see automation_io in action as well?
0 Likes
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog
SW1 (white button) on the Tag board interfaces to the BCM20732 via Pin 19 (VDDO/Digital-in).

If you were able to map this to a buzzer/LED also on the board (Digital-out), it seems that this demonstrate that the application was able to receive notification or indication when corresponding signal is changed.

Nothing has been created for this yet, but its an idea.
0 Likes
LiCh_2157216
Level 1
Level 1
We can use ble_pwn_init+ble_pwm_set and it can pull high for the PWM.

For the disable, we cant use ble_pwn_off to turn off the PWM.

Is there any sample code for the control?

The function description is limited and we didnt find the clear definition in the API.
0 Likes
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog
Heres a simple example that the firmware team provided:

void app_create(void)

{

       // PWM sample. Use P26

       UINT16 init_value = 0x000;

       UINT16 toggle_val = 0x100;

       aclk_configure(256000, ACLK1, ACLK_FREQ_24_MHZ);

       gpio_configurePin(26/16,26%16,GPIO_OUTPUT_ENABLE, 0);

       pwm_start(PWM0,PMU_CLK,toggle_val,init_value);

}

void app_timeout(UINT32 arg)

{

    static int iiii = 0;

    switch(iiii)

    {

    case 0:

       // Change period

       pwm_transitionToSubstituteValues(PWM0, 0x400, 0x00);

       break;

    case 1:

       // Invert

       pwm_setInversion(PWM0, 1);

       break;

    case 2:

       // Disable inversion

       pwm_setInversion(PWM0, 0);

       break;

    case 3:

       // Change frequency

       pwm_transitionToSubstituteValues(PWM0, 0x50, 0x00);

       break;

    case 4:

       // Nothing

       break;

    case 5:

       pwm_startWithAlternateValues(PWM0, PMU_CLK,0x800, 0x100, 0);

       break;

    case 6:

       // Disable channel.

       pwm_setReset(PWM0, 1);

       break;

    case 7:

       pwm_transitionToSubstituteValues(PWM0, 0x100, 0x00);

       break;

    }

    iiii = (iiii + 1) & 7;

}
0 Likes
LiCh_2157216
Level 1
Level 1
The following are 3 ways we tested to disable the PWM function include the suggestion, but we still cant let PWM work well.

Is there any description for each function?

1.
0 Likes
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog
I will ask someone from the firmware team to respond.  Most are out for the holidays, so it may be next week before someone is able to respond.
0 Likes

Is there any update about the PWM function?

0 Likes

The post from the 24th with the three methods used to disable the PWM function, including function descriptions seems to have gotten cut off.

Can you repost the names of the three functions you would like more information on?

0 Likes

function “pwm_setReset(DWORD mask, BOOLEAN resetEnable);” to disable pwm, it does not work.

It only stops pwm signal but not pull the level to low.

I use this function with below methods but all are failed.

==============================

#define AIO_PWM1       26

#define AIO_PWM_BASE   26

       pwm_ setReset (1 << (AIO_PWM1- AIO_PWM_BASE), 1);

   //pwm_ setReset ((AIO_PWM1- AIO_PWM_BASE), 1);

    //pwm_ setReset (AIO_PWM1, 1);

==============================

But, if I use this function “pwm_disableChannel(DWORD mask);”, it merely sometimes pull the PWM GPIO down failed.

====================

    pwm_disableChannel(1 << (gpio - AIO_PWM_BASE));

====================

If we also set the PWM GPIO to be a BUZZER one, we could use the function “bleprofile_BUZBeep(bleprofile_p_cfg->buz_on_ms);” to control the pin.

But this pin will become low automatically after  the time “buz_on_ms”.

0 Likes

Did you disable output on the GPIO when you reset the PWM (and you can insert an internal pull-down/pull-up)? Do you have anything connected to the GPIO? If yes, then can you try disconnecting it and then see if the PWM goes low when you reset it?

        case 6:
           // Disable channel.
           pwm_setReset(PWM0, 1);
           gpio_configurePin(26/16, 26%16, GPIO_OUTPUT_DISABLE | GPIO_PULL_DOWN, 0);
           break;

0 Likes

Any luck getting this to work Licter?

0 Likes

Thanks a lot.

We tested it and it works well.

Licter

0 Likes

Thanks for the feedback.  We are thinking about adding a PWM section to the existing Hardware Interfaces Guide.

0 Likes
Anonymous
Not applicable

Hi,

i think, it'll be nice if you are adding a PWM section into Hardware Interfaces Guide.

Because i'm a little bit confused about it.

Thanks

0 Likes

The best way to get familiar with the PWM function is to play with the PWM_Tones sample application within SDK 2.0.1

*

* PWM Tones Sample

*

* This application provides the sample code that uses the

* on-chip PWM and the buzzer on the TAG board to cycle

* through different tones when the button connected to P0

* is pressed. It also uses two other channels to generate

* random width pulses. Tones are generated with a 50% duty

* cycle and the other two channels have some randomness.

*

* Features demonstrated

*  - Use of the PWM driver interface

*  - Use of the on-chip HW random number generator.

*

* To demonstrate the app, work through the following steps.

* 1. Plug the WICED eval board into your computer

* 2. Build and download the application (to the WICED board)

* 3. Once the application is running, push SW1 and every

*  time the button is pressed, the tone generated by the buzzer

*  will cycle through a set of frequencies.

* 4. Attach an oscilloscope to P26 and P27 to see random width

*  signals.

*/

0 Likes
Anonymous
Not applicable

do you have tips for me, if i'll change the PWM duty cycle?

Example: PWM0 should run in 13% Duty Cycle; PWM1 => 90% Duty Cycle; PWM2 => 28% duty cycle. All PWMs should run with 1kHz.

0 Likes

This thread does an excellent job of explaining how to change the frequency of the PWM: Re: Different Frequencies for PWM

0 Likes
Anonymous
Not applicable

thanks. i'll try it.

0 Likes